1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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>
35 #include "lpfc_disc.h"
37 #include "lpfc_sli4.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 /* AlpaArray for assignment of scsid for scan-down and bind_method */
46 static uint8_t lpfcAlpaArray
[] = {
47 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
48 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
49 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
50 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
51 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
52 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
53 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
54 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
55 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
56 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
57 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
58 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
59 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
62 static void lpfc_disc_timeout_handler(struct lpfc_vport
*);
63 static void lpfc_disc_flush_list(struct lpfc_vport
*vport
);
66 lpfc_terminate_rport_io(struct fc_rport
*rport
)
68 struct lpfc_rport_data
*rdata
;
69 struct lpfc_nodelist
* ndlp
;
70 struct lpfc_hba
*phba
;
72 rdata
= rport
->dd_data
;
75 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
76 if (rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)
77 printk(KERN_ERR
"Cannot find remote node"
78 " to terminate I/O Data x%x\n",
85 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
86 "rport terminate: sid:x%x did:x%x flg:x%x",
87 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
89 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
90 lpfc_sli_abort_iocb(ndlp
->vport
,
91 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
92 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
97 * This function will be called when dev_loss_tmo fire.
100 lpfc_dev_loss_tmo_callbk(struct fc_rport
*rport
)
102 struct lpfc_rport_data
*rdata
;
103 struct lpfc_nodelist
* ndlp
;
104 struct lpfc_vport
*vport
;
105 struct lpfc_hba
*phba
;
106 struct lpfc_work_evt
*evtp
;
110 rdata
= rport
->dd_data
;
112 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
118 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
119 "rport devlosscb: sid:x%x did:x%x flg:x%x",
120 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
122 /* Don't defer this if we are in the process of deleting the vport
123 * or unloading the driver. The unload will cleanup the node
124 * appropriately we just need to cleanup the ndlp rport info here.
126 if (vport
->load_flag
& FC_UNLOADING
) {
127 put_node
= rdata
->pnode
!= NULL
;
128 put_rport
= ndlp
->rport
!= NULL
;
134 put_device(&rport
->dev
);
138 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)
141 evtp
= &ndlp
->dev_loss_evt
;
143 if (!list_empty(&evtp
->evt_listp
))
146 spin_lock_irq(&phba
->hbalock
);
147 /* We need to hold the node by incrementing the reference
148 * count until this queued work is done
150 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
151 if (evtp
->evt_arg1
) {
152 evtp
->evt
= LPFC_EVT_DEV_LOSS
;
153 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
154 lpfc_worker_wake_up(phba
);
156 spin_unlock_irq(&phba
->hbalock
);
162 * This function is called from the worker thread when dev_loss_tmo
166 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist
*ndlp
)
168 struct lpfc_rport_data
*rdata
;
169 struct fc_rport
*rport
;
170 struct lpfc_vport
*vport
;
171 struct lpfc_hba
*phba
;
182 rdata
= rport
->dd_data
;
183 name
= (uint8_t *) &ndlp
->nlp_portname
;
187 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
188 "rport devlosstmo:did:x%x type:x%x id:x%x",
189 ndlp
->nlp_DID
, ndlp
->nlp_type
, rport
->scsi_target_id
);
191 /* Don't defer this if we are in the process of deleting the vport
192 * or unloading the driver. The unload will cleanup the node
193 * appropriately we just need to cleanup the ndlp rport info here.
195 if (vport
->load_flag
& FC_UNLOADING
) {
196 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
197 /* flush the target */
198 lpfc_sli_abort_iocb(vport
,
199 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
200 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
202 put_node
= rdata
->pnode
!= NULL
;
203 put_rport
= ndlp
->rport
!= NULL
;
209 put_device(&rport
->dev
);
213 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
214 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
215 "0284 Devloss timeout Ignored on "
216 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
218 *name
, *(name
+1), *(name
+2), *(name
+3),
219 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
224 if (ndlp
->nlp_type
& NLP_FABRIC
) {
225 /* We will clean up these Nodes in linkup */
226 put_node
= rdata
->pnode
!= NULL
;
227 put_rport
= ndlp
->rport
!= NULL
;
233 put_device(&rport
->dev
);
237 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
239 /* flush the target */
240 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
241 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
245 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
246 "0203 Devloss timeout on "
247 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
248 "NPort x%06x Data: x%x x%x x%x\n",
249 *name
, *(name
+1), *(name
+2), *(name
+3),
250 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
251 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
252 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
254 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
255 "0204 Devloss timeout on "
256 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
257 "NPort x%06x Data: x%x x%x x%x\n",
258 *name
, *(name
+1), *(name
+2), *(name
+3),
259 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
260 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
261 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
264 put_node
= rdata
->pnode
!= NULL
;
265 put_rport
= ndlp
->rport
!= NULL
;
271 put_device(&rport
->dev
);
273 if (!(vport
->load_flag
& FC_UNLOADING
) &&
274 !(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
275 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
276 (ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
))
277 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
281 * lpfc_alloc_fast_evt - Allocates data structure for posting event
282 * @phba: Pointer to hba context object.
284 * This function is called from the functions which need to post
285 * events from interrupt context. This function allocates data
286 * structure required for posting event. It also keeps track of
287 * number of events pending and prevent event storm when there are
290 struct lpfc_fast_path_event
*
291 lpfc_alloc_fast_evt(struct lpfc_hba
*phba
) {
292 struct lpfc_fast_path_event
*ret
;
294 /* If there are lot of fast event do not exhaust memory due to this */
295 if (atomic_read(&phba
->fast_event_count
) > LPFC_MAX_EVT_COUNT
)
298 ret
= kzalloc(sizeof(struct lpfc_fast_path_event
),
301 atomic_inc(&phba
->fast_event_count
);
302 INIT_LIST_HEAD(&ret
->work_evt
.evt_listp
);
303 ret
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
308 * lpfc_free_fast_evt - Frees event data structure
309 * @phba: Pointer to hba context object.
310 * @evt: Event object which need to be freed.
312 * This function frees the data structure required for posting
316 lpfc_free_fast_evt(struct lpfc_hba
*phba
,
317 struct lpfc_fast_path_event
*evt
) {
319 atomic_dec(&phba
->fast_event_count
);
324 * lpfc_send_fastpath_evt - Posts events generated from fast path
325 * @phba: Pointer to hba context object.
326 * @evtp: Event data structure.
328 * This function is called from worker thread, when the interrupt
329 * context need to post an event. This function posts the event
330 * to fc transport netlink interface.
333 lpfc_send_fastpath_evt(struct lpfc_hba
*phba
,
334 struct lpfc_work_evt
*evtp
)
336 unsigned long evt_category
, evt_sub_category
;
337 struct lpfc_fast_path_event
*fast_evt_data
;
339 uint32_t evt_data_size
;
340 struct Scsi_Host
*shost
;
342 fast_evt_data
= container_of(evtp
, struct lpfc_fast_path_event
,
345 evt_category
= (unsigned long) fast_evt_data
->un
.fabric_evt
.event_type
;
346 evt_sub_category
= (unsigned long) fast_evt_data
->un
.
347 fabric_evt
.subcategory
;
348 shost
= lpfc_shost_from_vport(fast_evt_data
->vport
);
349 if (evt_category
== FC_REG_FABRIC_EVENT
) {
350 if (evt_sub_category
== LPFC_EVENT_FCPRDCHKERR
) {
351 evt_data
= (char *) &fast_evt_data
->un
.read_check_error
;
352 evt_data_size
= sizeof(fast_evt_data
->un
.
354 } else if ((evt_sub_category
== LPFC_EVENT_FABRIC_BUSY
) ||
355 (evt_sub_category
== LPFC_EVENT_PORT_BUSY
)) {
356 evt_data
= (char *) &fast_evt_data
->un
.fabric_evt
;
357 evt_data_size
= sizeof(fast_evt_data
->un
.fabric_evt
);
359 lpfc_free_fast_evt(phba
, fast_evt_data
);
362 } else if (evt_category
== FC_REG_SCSI_EVENT
) {
363 switch (evt_sub_category
) {
364 case LPFC_EVENT_QFULL
:
365 case LPFC_EVENT_DEVBSY
:
366 evt_data
= (char *) &fast_evt_data
->un
.scsi_evt
;
367 evt_data_size
= sizeof(fast_evt_data
->un
.scsi_evt
);
369 case LPFC_EVENT_CHECK_COND
:
370 evt_data
= (char *) &fast_evt_data
->un
.check_cond_evt
;
371 evt_data_size
= sizeof(fast_evt_data
->un
.
374 case LPFC_EVENT_VARQUEDEPTH
:
375 evt_data
= (char *) &fast_evt_data
->un
.queue_depth_evt
;
376 evt_data_size
= sizeof(fast_evt_data
->un
.
380 lpfc_free_fast_evt(phba
, fast_evt_data
);
384 lpfc_free_fast_evt(phba
, fast_evt_data
);
388 fc_host_post_vendor_event(shost
,
389 fc_get_event_number(),
394 lpfc_free_fast_evt(phba
, fast_evt_data
);
399 lpfc_work_list_done(struct lpfc_hba
*phba
)
401 struct lpfc_work_evt
*evtp
= NULL
;
402 struct lpfc_nodelist
*ndlp
;
405 spin_lock_irq(&phba
->hbalock
);
406 while (!list_empty(&phba
->work_list
)) {
407 list_remove_head((&phba
->work_list
), evtp
, typeof(*evtp
),
409 spin_unlock_irq(&phba
->hbalock
);
412 case LPFC_EVT_ELS_RETRY
:
413 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
414 lpfc_els_retry_delay_handler(ndlp
);
415 free_evt
= 0; /* evt is part of ndlp */
416 /* decrement the node reference count held
417 * for this queued work
421 case LPFC_EVT_DEV_LOSS
:
422 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
423 lpfc_dev_loss_tmo_handler(ndlp
);
425 /* decrement the node reference count held for
430 case LPFC_EVT_ONLINE
:
431 if (phba
->link_state
< LPFC_LINK_DOWN
)
432 *(int *) (evtp
->evt_arg1
) = lpfc_online(phba
);
434 *(int *) (evtp
->evt_arg1
) = 0;
435 complete((struct completion
*)(evtp
->evt_arg2
));
437 case LPFC_EVT_OFFLINE_PREP
:
438 if (phba
->link_state
>= LPFC_LINK_DOWN
)
439 lpfc_offline_prep(phba
);
440 *(int *)(evtp
->evt_arg1
) = 0;
441 complete((struct completion
*)(evtp
->evt_arg2
));
443 case LPFC_EVT_OFFLINE
:
445 lpfc_sli_brdrestart(phba
);
446 *(int *)(evtp
->evt_arg1
) =
447 lpfc_sli_brdready(phba
, HS_FFRDY
| HS_MBRDY
);
448 lpfc_unblock_mgmt_io(phba
);
449 complete((struct completion
*)(evtp
->evt_arg2
));
451 case LPFC_EVT_WARM_START
:
453 lpfc_reset_barrier(phba
);
454 lpfc_sli_brdreset(phba
);
455 lpfc_hba_down_post(phba
);
456 *(int *)(evtp
->evt_arg1
) =
457 lpfc_sli_brdready(phba
, HS_MBRDY
);
458 lpfc_unblock_mgmt_io(phba
);
459 complete((struct completion
*)(evtp
->evt_arg2
));
463 *(int *)(evtp
->evt_arg1
)
464 = (phba
->pport
->stopped
)
465 ? 0 : lpfc_sli_brdkill(phba
);
466 lpfc_unblock_mgmt_io(phba
);
467 complete((struct completion
*)(evtp
->evt_arg2
));
469 case LPFC_EVT_FASTPATH_MGMT_EVT
:
470 lpfc_send_fastpath_evt(phba
, evtp
);
476 spin_lock_irq(&phba
->hbalock
);
478 spin_unlock_irq(&phba
->hbalock
);
483 lpfc_work_done(struct lpfc_hba
*phba
)
485 struct lpfc_sli_ring
*pring
;
486 uint32_t ha_copy
, status
, control
, work_port_events
;
487 struct lpfc_vport
**vports
;
488 struct lpfc_vport
*vport
;
491 spin_lock_irq(&phba
->hbalock
);
492 ha_copy
= phba
->work_ha
;
494 spin_unlock_irq(&phba
->hbalock
);
496 /* First, try to post the next mailbox command to SLI4 device */
497 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
)
498 lpfc_sli4_post_async_mbox(phba
);
500 if (ha_copy
& HA_ERATT
)
501 /* Handle the error attention event */
502 lpfc_handle_eratt(phba
);
504 if (ha_copy
& HA_MBATT
)
505 lpfc_sli_handle_mb_event(phba
);
507 if (ha_copy
& HA_LATT
)
508 lpfc_handle_latt(phba
);
510 /* Process SLI4 events */
511 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
) {
512 if (phba
->hba_flag
& FCP_XRI_ABORT_EVENT
)
513 lpfc_sli4_fcp_xri_abort_event_proc(phba
);
514 if (phba
->hba_flag
& ELS_XRI_ABORT_EVENT
)
515 lpfc_sli4_els_xri_abort_event_proc(phba
);
516 if (phba
->hba_flag
& ASYNC_EVENT
)
517 lpfc_sli4_async_event_proc(phba
);
518 if (phba
->hba_flag
& HBA_POST_RECEIVE_BUFFER
) {
519 spin_lock_irq(&phba
->hbalock
);
520 phba
->hba_flag
&= ~HBA_POST_RECEIVE_BUFFER
;
521 spin_unlock_irq(&phba
->hbalock
);
522 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
524 if (phba
->hba_flag
& HBA_RECEIVE_BUFFER
)
525 lpfc_sli4_handle_received_buffer(phba
);
528 vports
= lpfc_create_vport_work_array(phba
);
530 for (i
= 0; i
<= phba
->max_vports
; i
++) {
532 * We could have no vports in array if unloading, so if
533 * this happens then just use the pport
535 if (vports
[i
] == NULL
&& i
== 0)
541 spin_lock_irq(&vport
->work_port_lock
);
542 work_port_events
= vport
->work_port_events
;
543 vport
->work_port_events
&= ~work_port_events
;
544 spin_unlock_irq(&vport
->work_port_lock
);
545 if (work_port_events
& WORKER_DISC_TMO
)
546 lpfc_disc_timeout_handler(vport
);
547 if (work_port_events
& WORKER_ELS_TMO
)
548 lpfc_els_timeout_handler(vport
);
549 if (work_port_events
& WORKER_HB_TMO
)
550 lpfc_hb_timeout_handler(phba
);
551 if (work_port_events
& WORKER_MBOX_TMO
)
552 lpfc_mbox_timeout_handler(phba
);
553 if (work_port_events
& WORKER_FABRIC_BLOCK_TMO
)
554 lpfc_unblock_fabric_iocbs(phba
);
555 if (work_port_events
& WORKER_FDMI_TMO
)
556 lpfc_fdmi_timeout_handler(vport
);
557 if (work_port_events
& WORKER_RAMP_DOWN_QUEUE
)
558 lpfc_ramp_down_queue_handler(phba
);
559 if (work_port_events
& WORKER_RAMP_UP_QUEUE
)
560 lpfc_ramp_up_queue_handler(phba
);
562 lpfc_destroy_vport_work_array(phba
, vports
);
564 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
565 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
566 status
>>= (4*LPFC_ELS_RING
);
567 if ((status
& HA_RXMASK
)
568 || (pring
->flag
& LPFC_DEFERRED_RING_EVENT
)) {
569 if (pring
->flag
& LPFC_STOP_IOCB_EVENT
) {
570 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
571 /* Set the lpfc data pending flag */
572 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
574 pring
->flag
&= ~LPFC_DEFERRED_RING_EVENT
;
575 lpfc_sli_handle_slow_ring_event(phba
, pring
,
580 * Turn on Ring interrupts
582 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
583 spin_lock_irq(&phba
->hbalock
);
584 control
= readl(phba
->HCregaddr
);
585 if (!(control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
))) {
586 lpfc_debugfs_slow_ring_trc(phba
,
587 "WRK Enable ring: cntl:x%x hacopy:x%x",
588 control
, ha_copy
, 0);
590 control
|= (HC_R0INT_ENA
<< LPFC_ELS_RING
);
591 writel(control
, phba
->HCregaddr
);
592 readl(phba
->HCregaddr
); /* flush */
594 lpfc_debugfs_slow_ring_trc(phba
,
595 "WRK Ring ok: cntl:x%x hacopy:x%x",
596 control
, ha_copy
, 0);
598 spin_unlock_irq(&phba
->hbalock
);
601 lpfc_work_list_done(phba
);
605 lpfc_do_work(void *p
)
607 struct lpfc_hba
*phba
= p
;
610 set_user_nice(current
, -20);
611 phba
->data_flags
= 0;
613 while (!kthread_should_stop()) {
614 /* wait and check worker queue activities */
615 rc
= wait_event_interruptible(phba
->work_waitq
,
616 (test_and_clear_bit(LPFC_DATA_READY
,
618 || kthread_should_stop()));
619 /* Signal wakeup shall terminate the worker thread */
621 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
622 "0433 Wakeup on signal: rc=x%x\n", rc
);
626 /* Attend pending lpfc data processing */
627 lpfc_work_done(phba
);
629 phba
->worker_thread
= NULL
;
630 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
631 "0432 Worker thread stopped.\n");
636 * This is only called to handle FC worker events. Since this a rare
637 * occurance, we allocate a struct lpfc_work_evt structure here instead of
638 * embedding it in the IOCB.
641 lpfc_workq_post_event(struct lpfc_hba
*phba
, void *arg1
, void *arg2
,
644 struct lpfc_work_evt
*evtp
;
648 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
649 * be queued to worker thread for processing
651 evtp
= kmalloc(sizeof(struct lpfc_work_evt
), GFP_ATOMIC
);
655 evtp
->evt_arg1
= arg1
;
656 evtp
->evt_arg2
= arg2
;
659 spin_lock_irqsave(&phba
->hbalock
, flags
);
660 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
661 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
663 lpfc_worker_wake_up(phba
);
669 lpfc_cleanup_rpis(struct lpfc_vport
*vport
, int remove
)
671 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
672 struct lpfc_hba
*phba
= vport
->phba
;
673 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
676 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
677 if (!NLP_CHK_NODE_ACT(ndlp
))
679 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
681 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) ||
682 ((vport
->port_type
== LPFC_NPIV_PORT
) &&
683 (ndlp
->nlp_DID
== NameServer_DID
)))
684 lpfc_unreg_rpi(vport
, ndlp
);
686 /* Leave Fabric nodes alone on link down */
687 if (!remove
&& ndlp
->nlp_type
& NLP_FABRIC
)
689 rc
= lpfc_disc_state_machine(vport
, ndlp
, NULL
,
692 : NLP_EVT_DEVICE_RECOVERY
);
694 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) {
695 lpfc_mbx_unreg_vpi(vport
);
696 spin_lock_irq(shost
->host_lock
);
697 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
698 spin_unlock_irq(shost
->host_lock
);
703 lpfc_port_link_failure(struct lpfc_vport
*vport
)
705 /* Cleanup any outstanding RSCN activity */
706 lpfc_els_flush_rscn(vport
);
708 /* Cleanup any outstanding ELS commands */
709 lpfc_els_flush_cmd(vport
);
711 lpfc_cleanup_rpis(vport
, 0);
713 /* Turn off discovery timer if its running */
714 lpfc_can_disctmo(vport
);
718 lpfc_linkdown_port(struct lpfc_vport
*vport
)
720 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
722 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKDOWN
, 0);
724 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
725 "Link Down: state:x%x rtry:x%x flg:x%x",
726 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
728 lpfc_port_link_failure(vport
);
733 lpfc_linkdown(struct lpfc_hba
*phba
)
735 struct lpfc_vport
*vport
= phba
->pport
;
736 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
737 struct lpfc_vport
**vports
;
741 if (phba
->link_state
== LPFC_LINK_DOWN
)
743 spin_lock_irq(&phba
->hbalock
);
744 if (phba
->link_state
> LPFC_LINK_DOWN
) {
745 phba
->link_state
= LPFC_LINK_DOWN
;
746 phba
->pport
->fc_flag
&= ~FC_LBIT
;
748 spin_unlock_irq(&phba
->hbalock
);
749 vports
= lpfc_create_vport_work_array(phba
);
751 for(i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
752 /* Issue a LINK DOWN event to all nodes */
753 lpfc_linkdown_port(vports
[i
]);
755 lpfc_destroy_vport_work_array(phba
, vports
);
756 /* Clean up any firmware default rpi's */
757 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
759 lpfc_unreg_did(phba
, 0xffff, 0xffffffff, mb
);
761 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
762 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
763 == MBX_NOT_FINISHED
) {
764 mempool_free(mb
, phba
->mbox_mem_pool
);
768 /* Setup myDID for link up if we are in pt2pt mode */
769 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
770 phba
->pport
->fc_myDID
= 0;
771 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
773 lpfc_config_link(phba
, mb
);
774 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
776 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
777 == MBX_NOT_FINISHED
) {
778 mempool_free(mb
, phba
->mbox_mem_pool
);
781 spin_lock_irq(shost
->host_lock
);
782 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
783 spin_unlock_irq(shost
->host_lock
);
790 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
792 struct lpfc_nodelist
*ndlp
;
794 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
795 if (!NLP_CHK_NODE_ACT(ndlp
))
797 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
799 if (ndlp
->nlp_type
& NLP_FABRIC
) {
800 /* On Linkup its safe to clean up the ndlp
801 * from Fabric connections.
803 if (ndlp
->nlp_DID
!= Fabric_DID
)
804 lpfc_unreg_rpi(vport
, ndlp
);
805 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
806 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
807 /* Fail outstanding IO now since device is
810 lpfc_unreg_rpi(vport
, ndlp
);
816 lpfc_linkup_port(struct lpfc_vport
*vport
)
818 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
819 struct lpfc_hba
*phba
= vport
->phba
;
821 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
824 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
825 "Link Up: top:x%x speed:x%x flg:x%x",
826 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
828 /* If NPIV is not enabled, only bring the physical port up */
829 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
830 (vport
!= phba
->pport
))
833 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKUP
, 0);
835 spin_lock_irq(shost
->host_lock
);
836 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
837 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
838 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
839 vport
->fc_ns_retry
= 0;
840 spin_unlock_irq(shost
->host_lock
);
842 if (vport
->fc_flag
& FC_LBIT
)
843 lpfc_linkup_cleanup_nodes(vport
);
848 lpfc_linkup(struct lpfc_hba
*phba
)
850 struct lpfc_vport
**vports
;
853 phba
->link_state
= LPFC_LINK_UP
;
855 /* Unblock fabric iocbs if they are blocked */
856 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
857 del_timer_sync(&phba
->fabric_block_timer
);
859 vports
= lpfc_create_vport_work_array(phba
);
861 for(i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++)
862 lpfc_linkup_port(vports
[i
]);
863 lpfc_destroy_vport_work_array(phba
, vports
);
864 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
865 lpfc_issue_clear_la(phba
, phba
->pport
);
871 * This routine handles processing a CLEAR_LA mailbox
872 * command upon completion. It is setup in the LPFC_MBOXQ
873 * as the completion routine when the command is
874 * handed off to the SLI layer.
877 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
879 struct lpfc_vport
*vport
= pmb
->vport
;
880 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
881 struct lpfc_sli
*psli
= &phba
->sli
;
882 MAILBOX_t
*mb
= &pmb
->mb
;
885 /* Since we don't do discovery right now, turn these off here */
886 psli
->ring
[psli
->extra_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
887 psli
->ring
[psli
->fcp_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
888 psli
->ring
[psli
->next_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
890 /* Check for error */
891 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
892 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
893 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
894 "0320 CLEAR_LA mbxStatus error x%x hba "
896 mb
->mbxStatus
, vport
->port_state
);
897 phba
->link_state
= LPFC_HBA_ERROR
;
901 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
902 phba
->link_state
= LPFC_HBA_READY
;
904 spin_lock_irq(&phba
->hbalock
);
905 psli
->sli_flag
|= LPFC_PROCESS_LA
;
906 control
= readl(phba
->HCregaddr
);
907 control
|= HC_LAINT_ENA
;
908 writel(control
, phba
->HCregaddr
);
909 readl(phba
->HCregaddr
); /* flush */
910 spin_unlock_irq(&phba
->hbalock
);
911 mempool_free(pmb
, phba
->mbox_mem_pool
);
915 /* Device Discovery completes */
916 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
917 "0225 Device Discovery completes\n");
918 mempool_free(pmb
, phba
->mbox_mem_pool
);
920 spin_lock_irq(shost
->host_lock
);
921 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
922 spin_unlock_irq(shost
->host_lock
);
924 lpfc_can_disctmo(vport
);
926 /* turn on Link Attention interrupts */
928 spin_lock_irq(&phba
->hbalock
);
929 psli
->sli_flag
|= LPFC_PROCESS_LA
;
930 control
= readl(phba
->HCregaddr
);
931 control
|= HC_LAINT_ENA
;
932 writel(control
, phba
->HCregaddr
);
933 readl(phba
->HCregaddr
); /* flush */
934 spin_unlock_irq(&phba
->hbalock
);
941 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
943 struct lpfc_vport
*vport
= pmb
->vport
;
945 if (pmb
->mb
.mbxStatus
)
948 mempool_free(pmb
, phba
->mbox_mem_pool
);
950 if (phba
->fc_topology
== TOPOLOGY_LOOP
&&
951 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
952 !(vport
->fc_flag
& FC_LBIT
)) {
953 /* Need to wait for FAN - use discovery timer
954 * for timeout. port_state is identically
955 * LPFC_LOCAL_CFG_LINK while waiting for FAN
957 lpfc_set_disctmo(vport
);
961 /* Start discovery by sending a FLOGI. port_state is identically
962 * LPFC_FLOGI while waiting for FLOGI cmpl
964 if (vport
->port_state
!= LPFC_FLOGI
) {
965 lpfc_initial_flogi(vport
);
970 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
971 "0306 CONFIG_LINK mbxStatus error x%x "
973 pmb
->mb
.mbxStatus
, vport
->port_state
);
974 mempool_free(pmb
, phba
->mbox_mem_pool
);
978 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
979 "0200 CONFIG_LINK bad hba state x%x\n",
982 lpfc_issue_clear_la(phba
, vport
);
987 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
989 MAILBOX_t
*mb
= &pmb
->mb
;
990 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
991 struct lpfc_vport
*vport
= pmb
->vport
;
994 /* Check for error */
996 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
997 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
998 "0319 READ_SPARAM mbxStatus error x%x "
1000 mb
->mbxStatus
, vport
->port_state
);
1001 lpfc_linkdown(phba
);
1005 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
1006 sizeof (struct serv_parm
));
1007 if (phba
->cfg_soft_wwnn
)
1008 u64_to_wwn(phba
->cfg_soft_wwnn
,
1009 vport
->fc_sparam
.nodeName
.u
.wwn
);
1010 if (phba
->cfg_soft_wwpn
)
1011 u64_to_wwn(phba
->cfg_soft_wwpn
,
1012 vport
->fc_sparam
.portName
.u
.wwn
);
1013 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
1014 sizeof(vport
->fc_nodename
));
1015 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
1016 sizeof(vport
->fc_portname
));
1017 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
1018 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
1019 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
1022 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1024 mempool_free(pmb
, phba
->mbox_mem_pool
);
1028 pmb
->context1
= NULL
;
1029 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1031 lpfc_issue_clear_la(phba
, vport
);
1032 mempool_free(pmb
, phba
->mbox_mem_pool
);
1037 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, READ_LA_VAR
*la
)
1039 struct lpfc_vport
*vport
= phba
->pport
;
1040 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
;
1042 struct lpfc_dmabuf
*mp
;
1045 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1046 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1048 spin_lock_irq(&phba
->hbalock
);
1049 switch (la
->UlnkSpeed
) {
1051 phba
->fc_linkspeed
= LA_1GHZ_LINK
;
1054 phba
->fc_linkspeed
= LA_2GHZ_LINK
;
1057 phba
->fc_linkspeed
= LA_4GHZ_LINK
;
1060 phba
->fc_linkspeed
= LA_8GHZ_LINK
;
1063 phba
->fc_linkspeed
= LA_UNKNW_LINK
;
1067 phba
->fc_topology
= la
->topology
;
1068 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
1070 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1071 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
1073 if (phba
->cfg_enable_npiv
)
1074 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1075 "1309 Link Up Event npiv not supported in loop "
1077 /* Get Loop Map information */
1079 vport
->fc_flag
|= FC_LBIT
;
1081 vport
->fc_myDID
= la
->granted_AL_PA
;
1082 i
= la
->un
.lilpBde64
.tus
.f
.bdeSize
;
1085 phba
->alpa_map
[0] = 0;
1087 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
1098 numalpa
= phba
->alpa_map
[0];
1100 while (j
< numalpa
) {
1101 memset(un
.pamap
, 0, 16);
1102 for (k
= 1; j
< numalpa
; k
++) {
1104 phba
->alpa_map
[j
+ 1];
1109 /* Link Up Event ALPA map */
1110 lpfc_printf_log(phba
,
1113 "1304 Link Up Event "
1114 "ALPA map Data: x%x "
1116 un
.pa
.wd1
, un
.pa
.wd2
,
1117 un
.pa
.wd3
, un
.pa
.wd4
);
1122 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
1123 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1124 (phba
->sli_rev
== 3))
1125 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
1127 vport
->fc_myDID
= phba
->fc_pref_DID
;
1128 vport
->fc_flag
|= FC_LBIT
;
1130 spin_unlock_irq(&phba
->hbalock
);
1134 lpfc_read_sparam(phba
, sparam_mbox
, 0);
1135 sparam_mbox
->vport
= vport
;
1136 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
1137 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
1138 if (rc
== MBX_NOT_FINISHED
) {
1139 mp
= (struct lpfc_dmabuf
*) sparam_mbox
->context1
;
1140 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1142 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
1144 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
1150 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
1151 lpfc_config_link(phba
, cfglink_mbox
);
1152 cfglink_mbox
->vport
= vport
;
1153 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
1154 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
1155 if (rc
!= MBX_NOT_FINISHED
)
1157 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
1160 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1161 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1162 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
1163 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
1164 lpfc_issue_clear_la(phba
, vport
);
1169 lpfc_enable_la(struct lpfc_hba
*phba
)
1172 struct lpfc_sli
*psli
= &phba
->sli
;
1173 spin_lock_irq(&phba
->hbalock
);
1174 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1175 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
1176 control
= readl(phba
->HCregaddr
);
1177 control
|= HC_LAINT_ENA
;
1178 writel(control
, phba
->HCregaddr
);
1179 readl(phba
->HCregaddr
); /* flush */
1181 spin_unlock_irq(&phba
->hbalock
);
1185 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
1187 lpfc_linkdown(phba
);
1188 lpfc_enable_la(phba
);
1189 /* turn on Link Attention interrupts - no CLEAR_LA needed */
1194 * This routine handles processing a READ_LA mailbox
1195 * command upon completion. It is setup in the LPFC_MBOXQ
1196 * as the completion routine when the command is
1197 * handed off to the SLI layer.
1200 lpfc_mbx_cmpl_read_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1202 struct lpfc_vport
*vport
= pmb
->vport
;
1203 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1205 MAILBOX_t
*mb
= &pmb
->mb
;
1206 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1208 /* Unblock ELS traffic */
1209 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1210 /* Check for error */
1211 if (mb
->mbxStatus
) {
1212 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1213 "1307 READ_LA mbox error x%x state x%x\n",
1214 mb
->mbxStatus
, vport
->port_state
);
1215 lpfc_mbx_issue_link_down(phba
);
1216 phba
->link_state
= LPFC_HBA_ERROR
;
1217 goto lpfc_mbx_cmpl_read_la_free_mbuf
;
1220 la
= (READ_LA_VAR
*) & pmb
->mb
.un
.varReadLA
;
1222 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
1224 spin_lock_irq(shost
->host_lock
);
1226 vport
->fc_flag
|= FC_BYPASSED_MODE
;
1228 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
1229 spin_unlock_irq(shost
->host_lock
);
1231 if (((phba
->fc_eventTag
+ 1) < la
->eventTag
) ||
1232 (phba
->fc_eventTag
== la
->eventTag
)) {
1233 phba
->fc_stat
.LinkMultiEvent
++;
1234 if (la
->attType
== AT_LINK_UP
)
1235 if (phba
->fc_eventTag
!= 0)
1236 lpfc_linkdown(phba
);
1239 phba
->fc_eventTag
= la
->eventTag
;
1241 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
1243 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
1245 if (la
->attType
== AT_LINK_UP
&& (!la
->mm
)) {
1246 phba
->fc_stat
.LinkUp
++;
1247 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
1248 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1249 "1306 Link Up Event in loop back mode "
1250 "x%x received Data: x%x x%x x%x x%x\n",
1251 la
->eventTag
, phba
->fc_eventTag
,
1252 la
->granted_AL_PA
, la
->UlnkSpeed
,
1255 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1256 "1303 Link Up Event x%x received "
1257 "Data: x%x x%x x%x x%x x%x x%x %d\n",
1258 la
->eventTag
, phba
->fc_eventTag
,
1259 la
->granted_AL_PA
, la
->UlnkSpeed
,
1262 phba
->wait_4_mlo_maint_flg
);
1264 lpfc_mbx_process_link_up(phba
, la
);
1265 } else if (la
->attType
== AT_LINK_DOWN
) {
1266 phba
->fc_stat
.LinkDown
++;
1267 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
1268 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1269 "1308 Link Down Event in loop back mode "
1271 "Data: x%x x%x x%x\n",
1272 la
->eventTag
, phba
->fc_eventTag
,
1273 phba
->pport
->port_state
, vport
->fc_flag
);
1276 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1277 "1305 Link Down Event x%x received "
1278 "Data: x%x x%x x%x x%x x%x\n",
1279 la
->eventTag
, phba
->fc_eventTag
,
1280 phba
->pport
->port_state
, vport
->fc_flag
,
1283 lpfc_mbx_issue_link_down(phba
);
1285 if (la
->mm
&& la
->attType
== AT_LINK_UP
) {
1286 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
1287 phba
->fc_stat
.LinkDown
++;
1288 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1289 "1312 Link Down Event x%x received "
1290 "Data: x%x x%x x%x\n",
1291 la
->eventTag
, phba
->fc_eventTag
,
1292 phba
->pport
->port_state
, vport
->fc_flag
);
1293 lpfc_mbx_issue_link_down(phba
);
1295 lpfc_enable_la(phba
);
1297 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1298 "1310 Menlo Maint Mode Link up Event x%x rcvd "
1299 "Data: x%x x%x x%x\n",
1300 la
->eventTag
, phba
->fc_eventTag
,
1301 phba
->pport
->port_state
, vport
->fc_flag
);
1303 * The cmnd that triggered this will be waiting for this
1306 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
1307 if (phba
->wait_4_mlo_maint_flg
) {
1308 phba
->wait_4_mlo_maint_flg
= 0;
1309 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
1315 lpfc_issue_clear_la(phba
, vport
);
1316 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1317 "1311 fa %d\n", la
->fa
);
1320 lpfc_mbx_cmpl_read_la_free_mbuf
:
1321 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1323 mempool_free(pmb
, phba
->mbox_mem_pool
);
1328 * This routine handles processing a REG_LOGIN mailbox
1329 * command upon completion. It is setup in the LPFC_MBOXQ
1330 * as the completion routine when the command is
1331 * handed off to the SLI layer.
1334 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1336 struct lpfc_vport
*vport
= pmb
->vport
;
1337 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1338 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1340 pmb
->context1
= NULL
;
1342 /* Good status, call state machine */
1343 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
1344 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1346 mempool_free(pmb
, phba
->mbox_mem_pool
);
1347 /* decrement the node reference count held for this callback
1356 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1358 MAILBOX_t
*mb
= &pmb
->mb
;
1359 struct lpfc_vport
*vport
= pmb
->vport
;
1360 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1362 switch (mb
->mbxStatus
) {
1366 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1367 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
1371 vport
->unreg_vpi_cmpl
= VPORT_OK
;
1372 mempool_free(pmb
, phba
->mbox_mem_pool
);
1374 * This shost reference might have been taken at the beginning of
1375 * lpfc_vport_delete()
1377 if (vport
->load_flag
& FC_UNLOADING
)
1378 scsi_host_put(shost
);
1382 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
1384 struct lpfc_hba
*phba
= vport
->phba
;
1388 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1392 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
1393 mbox
->vport
= vport
;
1394 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
1395 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1396 if (rc
== MBX_NOT_FINISHED
) {
1397 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1398 "1800 Could not issue unreg_vpi\n");
1399 mempool_free(mbox
, phba
->mbox_mem_pool
);
1400 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
1407 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1409 struct lpfc_vport
*vport
= pmb
->vport
;
1410 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1411 MAILBOX_t
*mb
= &pmb
->mb
;
1413 switch (mb
->mbxStatus
) {
1417 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1418 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
1420 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1421 spin_lock_irq(shost
->host_lock
);
1422 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
1423 spin_unlock_irq(shost
->host_lock
);
1424 vport
->fc_myDID
= 0;
1428 vport
->num_disc_nodes
= 0;
1429 /* go thru NPR list and issue ELS PLOGIs */
1430 if (vport
->fc_npr_cnt
)
1431 lpfc_els_disc_plogi(vport
);
1433 if (!vport
->num_disc_nodes
) {
1434 spin_lock_irq(shost
->host_lock
);
1435 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1436 spin_unlock_irq(shost
->host_lock
);
1437 lpfc_can_disctmo(vport
);
1439 vport
->port_state
= LPFC_VPORT_READY
;
1442 mempool_free(pmb
, phba
->mbox_mem_pool
);
1447 * This routine handles processing a Fabric REG_LOGIN mailbox
1448 * command upon completion. It is setup in the LPFC_MBOXQ
1449 * as the completion routine when the command is
1450 * handed off to the SLI layer.
1453 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1455 struct lpfc_vport
*vport
= pmb
->vport
;
1456 MAILBOX_t
*mb
= &pmb
->mb
;
1457 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1458 struct lpfc_nodelist
*ndlp
;
1459 struct lpfc_vport
**vports
;
1462 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1463 pmb
->context1
= NULL
;
1464 pmb
->context2
= NULL
;
1465 if (mb
->mbxStatus
) {
1466 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1468 mempool_free(pmb
, phba
->mbox_mem_pool
);
1470 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1471 /* FLOGI failed, use loop map to make discovery list */
1472 lpfc_disc_list_loopmap(vport
);
1474 /* Start discovery */
1475 lpfc_disc_start(vport
);
1476 /* Decrement the reference count to ndlp after the
1477 * reference to the ndlp are done.
1483 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1484 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1485 "0258 Register Fabric login error: 0x%x\n",
1487 /* Decrement the reference count to ndlp after the reference
1488 * to the ndlp are done.
1494 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1495 ndlp
->nlp_type
|= NLP_FABRIC
;
1496 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1498 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
1499 vports
= lpfc_create_vport_work_array(phba
);
1502 i
<= phba
->max_vpi
&& vports
[i
] != NULL
;
1504 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
1506 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1507 lpfc_vport_set_state(vports
[i
],
1511 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
1512 lpfc_initial_fdisc(vports
[i
]);
1514 lpfc_vport_set_state(vports
[i
],
1515 FC_VPORT_NO_FABRIC_SUPP
);
1516 lpfc_printf_vlog(vport
, KERN_ERR
,
1519 "Fabric support\n");
1522 lpfc_destroy_vport_work_array(phba
, vports
);
1523 lpfc_do_scr_ns_plogi(phba
, vport
);
1526 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1528 mempool_free(pmb
, phba
->mbox_mem_pool
);
1530 /* Drop the reference count from the mbox at the end after
1531 * all the current reference to the ndlp have been done.
1538 * This routine handles processing a NameServer REG_LOGIN mailbox
1539 * command upon completion. It is setup in the LPFC_MBOXQ
1540 * as the completion routine when the command is
1541 * handed off to the SLI layer.
1544 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1546 MAILBOX_t
*mb
= &pmb
->mb
;
1547 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1548 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1549 struct lpfc_vport
*vport
= pmb
->vport
;
1551 if (mb
->mbxStatus
) {
1553 /* decrement the node reference count held for this
1554 * callback function.
1557 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1559 mempool_free(pmb
, phba
->mbox_mem_pool
);
1561 /* If no other thread is using the ndlp, free it */
1562 lpfc_nlp_not_used(ndlp
);
1564 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1566 * RegLogin failed, use loop map to make discovery
1569 lpfc_disc_list_loopmap(vport
);
1571 /* Start discovery */
1572 lpfc_disc_start(vport
);
1575 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1576 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1577 "0260 Register NameServer error: 0x%x\n",
1582 pmb
->context1
= NULL
;
1584 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1585 ndlp
->nlp_type
|= NLP_FABRIC
;
1586 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1588 if (vport
->port_state
< LPFC_VPORT_READY
) {
1589 /* Link up discovery requires Fabric registration. */
1590 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, 0); /* Do this first! */
1591 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
1592 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
1593 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
1594 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
1596 /* Issue SCR just before NameServer GID_FT Query */
1597 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
1600 vport
->fc_ns_retry
= 0;
1601 /* Good status, issue CT Request to NameServer */
1602 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0)) {
1603 /* Cannot issue NameServer Query, so finish up discovery */
1607 /* decrement the node reference count held for this
1608 * callback function.
1611 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1613 mempool_free(pmb
, phba
->mbox_mem_pool
);
1619 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1621 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1622 struct fc_rport
*rport
;
1623 struct lpfc_rport_data
*rdata
;
1624 struct fc_rport_identifiers rport_ids
;
1625 struct lpfc_hba
*phba
= vport
->phba
;
1627 /* Remote port has reappeared. Re-register w/ FC transport */
1628 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
1629 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
1630 rport_ids
.port_id
= ndlp
->nlp_DID
;
1631 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
1634 * We leave our node pointer in rport->dd_data when we unregister a
1635 * FCP target port. But fc_remote_port_add zeros the space to which
1636 * rport->dd_data points. So, if we're reusing a previously
1637 * registered port, drop the reference that we took the last time we
1638 * registered the port.
1640 if (ndlp
->rport
&& ndlp
->rport
->dd_data
&&
1641 ((struct lpfc_rport_data
*) ndlp
->rport
->dd_data
)->pnode
== ndlp
)
1644 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
1645 "rport add: did:x%x flg:x%x type x%x",
1646 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
1648 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
1649 if (!rport
|| !get_device(&rport
->dev
)) {
1650 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
1651 "Warning: fc_remote_port_add failed\n");
1655 /* initialize static port data */
1656 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
1657 rport
->supported_classes
= ndlp
->nlp_class_sup
;
1658 rdata
= rport
->dd_data
;
1659 rdata
->pnode
= lpfc_nlp_get(ndlp
);
1661 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1662 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1663 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
1664 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1667 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
1668 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
1670 if ((rport
->scsi_target_id
!= -1) &&
1671 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
1672 ndlp
->nlp_sid
= rport
->scsi_target_id
;
1678 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
1680 struct fc_rport
*rport
= ndlp
->rport
;
1682 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
1683 "rport delete: did:x%x flg:x%x type x%x",
1684 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
1686 fc_remote_port_delete(rport
);
1692 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
1694 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1696 spin_lock_irq(shost
->host_lock
);
1698 case NLP_STE_UNUSED_NODE
:
1699 vport
->fc_unused_cnt
+= count
;
1701 case NLP_STE_PLOGI_ISSUE
:
1702 vport
->fc_plogi_cnt
+= count
;
1704 case NLP_STE_ADISC_ISSUE
:
1705 vport
->fc_adisc_cnt
+= count
;
1707 case NLP_STE_REG_LOGIN_ISSUE
:
1708 vport
->fc_reglogin_cnt
+= count
;
1710 case NLP_STE_PRLI_ISSUE
:
1711 vport
->fc_prli_cnt
+= count
;
1713 case NLP_STE_UNMAPPED_NODE
:
1714 vport
->fc_unmap_cnt
+= count
;
1716 case NLP_STE_MAPPED_NODE
:
1717 vport
->fc_map_cnt
+= count
;
1719 case NLP_STE_NPR_NODE
:
1720 vport
->fc_npr_cnt
+= count
;
1723 spin_unlock_irq(shost
->host_lock
);
1727 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1728 int old_state
, int new_state
)
1730 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1732 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
1733 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
1734 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
1735 ndlp
->nlp_type
|= NLP_FC_NODE
;
1737 if (new_state
== NLP_STE_MAPPED_NODE
)
1738 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
1739 if (new_state
== NLP_STE_NPR_NODE
)
1740 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
1742 /* Transport interface */
1743 if (ndlp
->rport
&& (old_state
== NLP_STE_MAPPED_NODE
||
1744 old_state
== NLP_STE_UNMAPPED_NODE
)) {
1745 vport
->phba
->nport_event_cnt
++;
1746 lpfc_unregister_remote_port(ndlp
);
1749 if (new_state
== NLP_STE_MAPPED_NODE
||
1750 new_state
== NLP_STE_UNMAPPED_NODE
) {
1751 vport
->phba
->nport_event_cnt
++;
1753 * Tell the fc transport about the port, if we haven't
1754 * already. If we have, and it's a scsi entity, be
1755 * sure to unblock any attached scsi devices
1757 lpfc_register_remote_port(vport
, ndlp
);
1759 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
1760 (vport
->stat_data_enabled
)) {
1762 * A new target is discovered, if there is no buffer for
1763 * statistical data collection allocate buffer.
1765 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
1766 sizeof(struct lpfc_scsicmd_bkt
),
1769 if (!ndlp
->lat_data
)
1770 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
1771 "0286 lpfc_nlp_state_cleanup failed to "
1772 "allocate statistical data buffer DID "
1773 "0x%x\n", ndlp
->nlp_DID
);
1776 * if we added to Mapped list, but the remote port
1777 * registration failed or assigned a target id outside
1778 * our presentable range - move the node to the
1781 if (new_state
== NLP_STE_MAPPED_NODE
&&
1783 ndlp
->rport
->scsi_target_id
== -1 ||
1784 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
1785 spin_lock_irq(shost
->host_lock
);
1786 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
1787 spin_unlock_irq(shost
->host_lock
);
1788 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1793 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
1795 static char *states
[] = {
1796 [NLP_STE_UNUSED_NODE
] = "UNUSED",
1797 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
1798 [NLP_STE_ADISC_ISSUE
] = "ADISC",
1799 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
1800 [NLP_STE_PRLI_ISSUE
] = "PRLI",
1801 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
1802 [NLP_STE_MAPPED_NODE
] = "MAPPED",
1803 [NLP_STE_NPR_NODE
] = "NPR",
1806 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
1807 strlcpy(buffer
, states
[state
], size
);
1809 snprintf(buffer
, size
, "unknown (%d)", state
);
1814 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1817 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1818 int old_state
= ndlp
->nlp_state
;
1819 char name1
[16], name2
[16];
1821 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1822 "0904 NPort state transition x%06x, %s -> %s\n",
1824 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
1825 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
1827 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
1828 "node statechg did:x%x old:%d ste:%d",
1829 ndlp
->nlp_DID
, old_state
, state
);
1831 if (old_state
== NLP_STE_NPR_NODE
&&
1832 state
!= NLP_STE_NPR_NODE
)
1833 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1834 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
1835 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
1836 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
1839 if (list_empty(&ndlp
->nlp_listp
)) {
1840 spin_lock_irq(shost
->host_lock
);
1841 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
1842 spin_unlock_irq(shost
->host_lock
);
1843 } else if (old_state
)
1844 lpfc_nlp_counters(vport
, old_state
, -1);
1846 ndlp
->nlp_state
= state
;
1847 lpfc_nlp_counters(vport
, state
, 1);
1848 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
1852 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1854 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1856 if (list_empty(&ndlp
->nlp_listp
)) {
1857 spin_lock_irq(shost
->host_lock
);
1858 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
1859 spin_unlock_irq(shost
->host_lock
);
1864 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1866 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1868 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1869 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
1870 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
1871 spin_lock_irq(shost
->host_lock
);
1872 list_del_init(&ndlp
->nlp_listp
);
1873 spin_unlock_irq(shost
->host_lock
);
1874 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
1875 NLP_STE_UNUSED_NODE
);
1879 lpfc_disable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1881 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1882 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
1883 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
1884 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
1885 NLP_STE_UNUSED_NODE
);
1888 * lpfc_initialize_node - Initialize all fields of node object
1889 * @vport: Pointer to Virtual Port object.
1890 * @ndlp: Pointer to FC node object.
1891 * @did: FC_ID of the node.
1893 * This function is always called when node object need to be initialized.
1894 * It initializes all the fields of the node object. Although the reference
1895 * to phba from @ndlp can be obtained indirectly through it's reference to
1896 * @vport, a direct reference to phba is taken here by @ndlp. This is due
1897 * to the life-span of the @ndlp might go beyond the existence of @vport as
1898 * the final release of ndlp is determined by its reference count. And, the
1899 * operation on @ndlp needs the reference to phba.
1902 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1905 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
1906 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
1907 init_timer(&ndlp
->nlp_delayfunc
);
1908 ndlp
->nlp_delayfunc
.function
= lpfc_els_retry_delay
;
1909 ndlp
->nlp_delayfunc
.data
= (unsigned long)ndlp
;
1910 ndlp
->nlp_DID
= did
;
1911 ndlp
->vport
= vport
;
1912 ndlp
->phba
= vport
->phba
;
1913 ndlp
->nlp_sid
= NLP_NO_SID
;
1914 kref_init(&ndlp
->kref
);
1915 NLP_INT_NODE_ACT(ndlp
);
1916 atomic_set(&ndlp
->cmd_pending
, 0);
1917 ndlp
->cmd_qdepth
= LPFC_MAX_TGT_QDEPTH
;
1920 struct lpfc_nodelist
*
1921 lpfc_enable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1924 struct lpfc_hba
*phba
= vport
->phba
;
1926 unsigned long flags
;
1931 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
1932 /* The ndlp should not be in memory free mode */
1933 if (NLP_CHK_FREE_REQ(ndlp
)) {
1934 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
1935 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
1936 "0277 lpfc_enable_node: ndlp:x%p "
1937 "usgmap:x%x refcnt:%d\n",
1938 (void *)ndlp
, ndlp
->nlp_usg_map
,
1939 atomic_read(&ndlp
->kref
.refcount
));
1942 /* The ndlp should not already be in active mode */
1943 if (NLP_CHK_NODE_ACT(ndlp
)) {
1944 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
1945 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
1946 "0278 lpfc_enable_node: ndlp:x%p "
1947 "usgmap:x%x refcnt:%d\n",
1948 (void *)ndlp
, ndlp
->nlp_usg_map
,
1949 atomic_read(&ndlp
->kref
.refcount
));
1953 /* Keep the original DID */
1954 did
= ndlp
->nlp_DID
;
1956 /* re-initialize ndlp except of ndlp linked list pointer */
1957 memset((((char *)ndlp
) + sizeof (struct list_head
)), 0,
1958 sizeof (struct lpfc_nodelist
) - sizeof (struct list_head
));
1959 lpfc_initialize_node(vport
, ndlp
, did
);
1961 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
1963 if (state
!= NLP_STE_UNUSED_NODE
)
1964 lpfc_nlp_set_state(vport
, ndlp
, state
);
1966 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
1967 "node enable: did:x%x",
1968 ndlp
->nlp_DID
, 0, 0);
1973 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1976 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
1977 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
1978 * the ndlp from the vport. The ndlp marked as UNUSED on the list
1979 * until ALL other outstanding threads have completed. We check
1980 * that the ndlp not already in the UNUSED state before we proceed.
1982 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
1984 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1990 * Start / ReStart rescue timer for Discovery / RSCN handling
1993 lpfc_set_disctmo(struct lpfc_vport
*vport
)
1995 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1996 struct lpfc_hba
*phba
= vport
->phba
;
1999 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
2000 /* For FAN, timeout should be greater than edtov */
2001 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
2003 /* Normal discovery timeout should be > than ELS/CT timeout
2004 * FC spec states we need 3 * ratov for CT requests
2006 tmo
= ((phba
->fc_ratov
* 3) + 3);
2010 if (!timer_pending(&vport
->fc_disctmo
)) {
2011 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2012 "set disc timer: tmo:x%x state:x%x flg:x%x",
2013 tmo
, vport
->port_state
, vport
->fc_flag
);
2016 mod_timer(&vport
->fc_disctmo
, jiffies
+ HZ
* tmo
);
2017 spin_lock_irq(shost
->host_lock
);
2018 vport
->fc_flag
|= FC_DISC_TMO
;
2019 spin_unlock_irq(shost
->host_lock
);
2021 /* Start Discovery Timer state <hba_state> */
2022 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2023 "0247 Start Discovery Timer state x%x "
2024 "Data: x%x x%lx x%x x%x\n",
2025 vport
->port_state
, tmo
,
2026 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
2027 vport
->fc_adisc_cnt
);
2033 * Cancel rescue timer for Discovery / RSCN handling
2036 lpfc_can_disctmo(struct lpfc_vport
*vport
)
2038 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2039 unsigned long iflags
;
2041 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2042 "can disc timer: state:x%x rtry:x%x flg:x%x",
2043 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
2045 /* Turn off discovery timer if its running */
2046 if (vport
->fc_flag
& FC_DISC_TMO
) {
2047 spin_lock_irqsave(shost
->host_lock
, iflags
);
2048 vport
->fc_flag
&= ~FC_DISC_TMO
;
2049 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
2050 del_timer_sync(&vport
->fc_disctmo
);
2051 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
2052 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
2053 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
2056 /* Cancel Discovery Timer state <hba_state> */
2057 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2058 "0248 Cancel Discovery Timer state x%x "
2059 "Data: x%x x%x x%x\n",
2060 vport
->port_state
, vport
->fc_flag
,
2061 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
2066 * Check specified ring for outstanding IOCB on the SLI queue
2067 * Return true if iocb matches the specified nport
2070 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
2071 struct lpfc_sli_ring
*pring
,
2072 struct lpfc_iocbq
*iocb
,
2073 struct lpfc_nodelist
*ndlp
)
2075 struct lpfc_sli
*psli
= &phba
->sli
;
2076 IOCB_t
*icmd
= &iocb
->iocb
;
2077 struct lpfc_vport
*vport
= ndlp
->vport
;
2079 if (iocb
->vport
!= vport
)
2082 if (pring
->ringno
== LPFC_ELS_RING
) {
2083 switch (icmd
->ulpCommand
) {
2084 case CMD_GEN_REQUEST64_CR
:
2085 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
)
2087 case CMD_ELS_REQUEST64_CR
:
2088 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
2090 case CMD_XMIT_ELS_RSP64_CX
:
2091 if (iocb
->context1
== (uint8_t *) ndlp
)
2094 } else if (pring
->ringno
== psli
->extra_ring
) {
2096 } else if (pring
->ringno
== psli
->fcp_ring
) {
2097 /* Skip match check if waiting to relogin to FCP target */
2098 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
2099 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2102 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
2105 } else if (pring
->ringno
== psli
->next_ring
) {
2112 * Free resources / clean up outstanding I/Os
2113 * associated with nlp_rpi in the LPFC_NODELIST entry.
2116 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
2118 LIST_HEAD(completions
);
2119 struct lpfc_sli
*psli
;
2120 struct lpfc_sli_ring
*pring
;
2121 struct lpfc_iocbq
*iocb
, *next_iocb
;
2124 lpfc_fabric_abort_nport(ndlp
);
2127 * Everything that matches on txcmplq will be returned
2128 * by firmware with a no rpi error.
2131 rpi
= ndlp
->nlp_rpi
;
2133 /* Now process each ring */
2134 for (i
= 0; i
< psli
->num_rings
; i
++) {
2135 pring
= &psli
->ring
[i
];
2137 spin_lock_irq(&phba
->hbalock
);
2138 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
,
2141 * Check to see if iocb matches the nport we are
2144 if ((lpfc_check_sli_ndlp(phba
, pring
, iocb
,
2146 /* It matches, so deque and call compl
2148 list_move_tail(&iocb
->list
,
2153 spin_unlock_irq(&phba
->hbalock
);
2157 /* Cancel all the IOCBs from the completions list */
2158 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
2165 * Free rpi associated with LPFC_NODELIST entry.
2166 * This routine is called from lpfc_freenode(), when we are removing
2167 * a LPFC_NODELIST entry. It is also called if the driver initiates a
2168 * LOGO that completes successfully, and we are waiting to PLOGI back
2169 * to the remote NPort. In addition, it is called after we receive
2170 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
2171 * we are waiting to PLOGI back to the remote NPort.
2174 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2176 struct lpfc_hba
*phba
= vport
->phba
;
2180 if (ndlp
->nlp_rpi
) {
2181 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2183 lpfc_unreg_login(phba
, vport
->vpi
, ndlp
->nlp_rpi
, mbox
);
2184 mbox
->vport
= vport
;
2185 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2186 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2187 if (rc
== MBX_NOT_FINISHED
)
2188 mempool_free(mbox
, phba
->mbox_mem_pool
);
2190 lpfc_no_rpi(phba
, ndlp
);
2198 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
2200 struct lpfc_hba
*phba
= vport
->phba
;
2204 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2206 lpfc_unreg_login(phba
, vport
->vpi
, 0xffff, mbox
);
2207 mbox
->vport
= vport
;
2208 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2209 mbox
->context1
= NULL
;
2210 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2211 if (rc
!= MBX_TIMEOUT
)
2212 mempool_free(mbox
, phba
->mbox_mem_pool
);
2214 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
2215 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
2216 "1836 Could not issue "
2217 "unreg_login(all_rpis) status %d\n", rc
);
2222 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
2224 struct lpfc_hba
*phba
= vport
->phba
;
2228 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2230 lpfc_unreg_did(phba
, vport
->vpi
, 0xffffffff, mbox
);
2231 mbox
->vport
= vport
;
2232 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2233 mbox
->context1
= NULL
;
2234 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2235 if (rc
!= MBX_TIMEOUT
)
2236 mempool_free(mbox
, phba
->mbox_mem_pool
);
2238 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
2239 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
2240 "1815 Could not issue "
2241 "unreg_did (default rpis) status %d\n",
2247 * Free resources associated with LPFC_NODELIST entry
2248 * so it can be freed.
2251 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2253 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2254 struct lpfc_hba
*phba
= vport
->phba
;
2255 LPFC_MBOXQ_t
*mb
, *nextmb
;
2256 struct lpfc_dmabuf
*mp
;
2258 /* Cleanup node for NPort <nlp_DID> */
2259 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2260 "0900 Cleanup node for NPort x%x "
2261 "Data: x%x x%x x%x\n",
2262 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
2263 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2264 if (NLP_CHK_FREE_REQ(ndlp
)) {
2265 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2266 "0280 lpfc_cleanup_node: ndlp:x%p "
2267 "usgmap:x%x refcnt:%d\n",
2268 (void *)ndlp
, ndlp
->nlp_usg_map
,
2269 atomic_read(&ndlp
->kref
.refcount
));
2270 lpfc_dequeue_node(vport
, ndlp
);
2272 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2273 "0281 lpfc_cleanup_node: ndlp:x%p "
2274 "usgmap:x%x refcnt:%d\n",
2275 (void *)ndlp
, ndlp
->nlp_usg_map
,
2276 atomic_read(&ndlp
->kref
.refcount
));
2277 lpfc_disable_node(vport
, ndlp
);
2280 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
2281 if ((mb
= phba
->sli
.mbox_active
)) {
2282 if ((mb
->mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
2283 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
2284 mb
->context2
= NULL
;
2285 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2289 spin_lock_irq(&phba
->hbalock
);
2290 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
2291 if ((mb
->mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
2292 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
2293 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
2295 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2298 list_del(&mb
->list
);
2299 mempool_free(mb
, phba
->mbox_mem_pool
);
2300 /* We shall not invoke the lpfc_nlp_put to decrement
2301 * the ndlp reference count as we are in the process
2302 * of lpfc_nlp_release.
2306 spin_unlock_irq(&phba
->hbalock
);
2308 lpfc_els_abort(phba
, ndlp
);
2310 spin_lock_irq(shost
->host_lock
);
2311 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2312 spin_unlock_irq(shost
->host_lock
);
2314 ndlp
->nlp_last_elscmd
= 0;
2315 del_timer_sync(&ndlp
->nlp_delayfunc
);
2317 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
2318 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
2320 lpfc_unreg_rpi(vport
, ndlp
);
2326 * Check to see if we can free the nlp back to the freelist.
2327 * If we are in the middle of using the nlp in the discovery state
2328 * machine, defer the free till we reach the end of the state machine.
2331 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2333 struct lpfc_hba
*phba
= vport
->phba
;
2334 struct lpfc_rport_data
*rdata
;
2338 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2339 if (ndlp
->nlp_flag
& NLP_DEFER_RM
&& !ndlp
->nlp_rpi
) {
2340 /* For this case we need to cleanup the default rpi
2341 * allocated by the firmware.
2343 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
))
2345 rc
= lpfc_reg_login(phba
, vport
->vpi
, ndlp
->nlp_DID
,
2346 (uint8_t *) &vport
->fc_sparam
, mbox
, 0);
2348 mempool_free(mbox
, phba
->mbox_mem_pool
);
2351 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
2352 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
2353 mbox
->vport
= vport
;
2354 mbox
->context2
= NULL
;
2355 rc
=lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2356 if (rc
== MBX_NOT_FINISHED
) {
2357 mempool_free(mbox
, phba
->mbox_mem_pool
);
2362 lpfc_cleanup_node(vport
, ndlp
);
2365 * We can get here with a non-NULL ndlp->rport because when we
2366 * unregister a rport we don't break the rport/node linkage. So if we
2367 * do, make sure we don't leaving any dangling pointers behind.
2370 rdata
= ndlp
->rport
->dd_data
;
2371 rdata
->pnode
= NULL
;
2377 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2380 D_ID mydid
, ndlpdid
, matchdid
;
2382 if (did
== Bcast_DID
)
2385 /* First check for Direct match */
2386 if (ndlp
->nlp_DID
== did
)
2389 /* Next check for area/domain identically equals 0 match */
2390 mydid
.un
.word
= vport
->fc_myDID
;
2391 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
2395 matchdid
.un
.word
= did
;
2396 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
2397 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
2398 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
2399 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
2400 if ((ndlpdid
.un
.b
.domain
== 0) &&
2401 (ndlpdid
.un
.b
.area
== 0)) {
2402 if (ndlpdid
.un
.b
.id
)
2408 matchdid
.un
.word
= ndlp
->nlp_DID
;
2409 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
2410 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
2411 if ((matchdid
.un
.b
.domain
== 0) &&
2412 (matchdid
.un
.b
.area
== 0)) {
2413 if (matchdid
.un
.b
.id
)
2421 /* Search for a nodelist entry */
2422 static struct lpfc_nodelist
*
2423 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
2425 struct lpfc_nodelist
*ndlp
;
2428 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2429 if (lpfc_matchdid(vport
, ndlp
, did
)) {
2430 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
2431 ((uint32_t) ndlp
->nlp_xri
<< 16) |
2432 ((uint32_t) ndlp
->nlp_type
<< 8) |
2433 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
2434 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2435 "0929 FIND node DID "
2436 "Data: x%p x%x x%x x%x\n",
2437 ndlp
, ndlp
->nlp_DID
,
2438 ndlp
->nlp_flag
, data1
);
2443 /* FIND node did <did> NOT FOUND */
2444 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2445 "0932 FIND node did x%x NOT FOUND.\n", did
);
2449 struct lpfc_nodelist
*
2450 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
2452 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2453 struct lpfc_nodelist
*ndlp
;
2455 spin_lock_irq(shost
->host_lock
);
2456 ndlp
= __lpfc_findnode_did(vport
, did
);
2457 spin_unlock_irq(shost
->host_lock
);
2461 struct lpfc_nodelist
*
2462 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
2464 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2465 struct lpfc_nodelist
*ndlp
;
2467 ndlp
= lpfc_findnode_did(vport
, did
);
2469 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
2470 lpfc_rscn_payload_check(vport
, did
) == 0)
2472 ndlp
= (struct lpfc_nodelist
*)
2473 mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
2476 lpfc_nlp_init(vport
, ndlp
, did
);
2477 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2478 spin_lock_irq(shost
->host_lock
);
2479 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2480 spin_unlock_irq(shost
->host_lock
);
2482 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2483 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
2486 spin_lock_irq(shost
->host_lock
);
2487 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2488 spin_unlock_irq(shost
->host_lock
);
2492 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
2493 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
2494 if (lpfc_rscn_payload_check(vport
, did
)) {
2495 /* If we've already recieved a PLOGI from this NPort
2496 * we don't need to try to discover it again.
2498 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
2501 /* Since this node is marked for discovery,
2502 * delay timeout is not needed.
2504 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2505 spin_lock_irq(shost
->host_lock
);
2506 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2507 spin_unlock_irq(shost
->host_lock
);
2511 /* If we've already recieved a PLOGI from this NPort,
2512 * or we are already in the process of discovery on it,
2513 * we don't need to try to discover it again.
2515 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
2516 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
2517 ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
2519 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2520 spin_lock_irq(shost
->host_lock
);
2521 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2522 spin_unlock_irq(shost
->host_lock
);
2527 /* Build a list of nodes to discover based on the loopmap */
2529 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
2531 struct lpfc_hba
*phba
= vport
->phba
;
2533 uint32_t alpa
, index
;
2535 if (!lpfc_is_link_up(phba
))
2538 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
2541 /* Check for loop map present or not */
2542 if (phba
->alpa_map
[0]) {
2543 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
2544 alpa
= phba
->alpa_map
[j
];
2545 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
2547 lpfc_setup_disc_node(vport
, alpa
);
2550 /* No alpamap, so try all alpa's */
2551 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
2552 /* If cfg_scan_down is set, start from highest
2553 * ALPA (0xef) to lowest (0x1).
2555 if (vport
->cfg_scan_down
)
2558 index
= FC_MAXLOOP
- j
- 1;
2559 alpa
= lpfcAlpaArray
[index
];
2560 if ((vport
->fc_myDID
& 0xff) == alpa
)
2562 lpfc_setup_disc_node(vport
, alpa
);
2569 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
2572 struct lpfc_sli
*psli
= &phba
->sli
;
2573 struct lpfc_sli_ring
*extra_ring
= &psli
->ring
[psli
->extra_ring
];
2574 struct lpfc_sli_ring
*fcp_ring
= &psli
->ring
[psli
->fcp_ring
];
2575 struct lpfc_sli_ring
*next_ring
= &psli
->ring
[psli
->next_ring
];
2579 * if it's not a physical port or if we already send
2580 * clear_la then don't send it.
2582 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
2583 (vport
->port_type
!= LPFC_PHYSICAL_PORT
) ||
2584 (phba
->sli_rev
== LPFC_SLI_REV4
))
2587 /* Link up discovery */
2588 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
2589 phba
->link_state
= LPFC_CLEAR_LA
;
2590 lpfc_clear_la(phba
, mbox
);
2591 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
2592 mbox
->vport
= vport
;
2593 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2594 if (rc
== MBX_NOT_FINISHED
) {
2595 mempool_free(mbox
, phba
->mbox_mem_pool
);
2596 lpfc_disc_flush_list(vport
);
2597 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2598 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2599 next_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2600 phba
->link_state
= LPFC_HBA_ERROR
;
2605 /* Reg_vpi to tell firmware to resume normal operations */
2607 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
2609 LPFC_MBOXQ_t
*regvpimbox
;
2611 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2613 lpfc_reg_vpi(vport
, regvpimbox
);
2614 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
2615 regvpimbox
->vport
= vport
;
2616 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
2617 == MBX_NOT_FINISHED
) {
2618 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
2623 /* Start Link up / RSCN discovery on NPR nodes */
2625 lpfc_disc_start(struct lpfc_vport
*vport
)
2627 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2628 struct lpfc_hba
*phba
= vport
->phba
;
2630 uint32_t clear_la_pending
;
2633 if (!lpfc_is_link_up(phba
))
2636 if (phba
->link_state
== LPFC_CLEAR_LA
)
2637 clear_la_pending
= 1;
2639 clear_la_pending
= 0;
2641 if (vport
->port_state
< LPFC_VPORT_READY
)
2642 vport
->port_state
= LPFC_DISC_AUTH
;
2644 lpfc_set_disctmo(vport
);
2646 if (vport
->fc_prevDID
== vport
->fc_myDID
)
2651 vport
->fc_prevDID
= vport
->fc_myDID
;
2652 vport
->num_disc_nodes
= 0;
2654 /* Start Discovery state <hba_state> */
2655 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2656 "0202 Start Discovery hba state x%x "
2657 "Data: x%x x%x x%x\n",
2658 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
2659 vport
->fc_adisc_cnt
);
2661 /* First do ADISCs - if any */
2662 num_sent
= lpfc_els_disc_adisc(vport
);
2668 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
2669 * continue discovery.
2671 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2672 !(vport
->fc_flag
& FC_PT2PT
) &&
2673 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
2674 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
2675 lpfc_issue_reg_vpi(phba
, vport
);
2680 * For SLI2, we need to set port_state to READY and continue
2683 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
2684 /* If we get here, there is nothing to ADISC */
2685 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
2686 lpfc_issue_clear_la(phba
, vport
);
2688 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
2689 vport
->num_disc_nodes
= 0;
2690 /* go thru NPR nodes and issue ELS PLOGIs */
2691 if (vport
->fc_npr_cnt
)
2692 lpfc_els_disc_plogi(vport
);
2694 if (!vport
->num_disc_nodes
) {
2695 spin_lock_irq(shost
->host_lock
);
2696 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2697 spin_unlock_irq(shost
->host_lock
);
2698 lpfc_can_disctmo(vport
);
2701 vport
->port_state
= LPFC_VPORT_READY
;
2703 /* Next do PLOGIs - if any */
2704 num_sent
= lpfc_els_disc_plogi(vport
);
2709 if (vport
->fc_flag
& FC_RSCN_MODE
) {
2710 /* Check to see if more RSCNs came in while we
2711 * were processing this one.
2713 if ((vport
->fc_rscn_id_cnt
== 0) &&
2714 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
2715 spin_lock_irq(shost
->host_lock
);
2716 vport
->fc_flag
&= ~FC_RSCN_MODE
;
2717 spin_unlock_irq(shost
->host_lock
);
2718 lpfc_can_disctmo(vport
);
2720 lpfc_els_handle_rscn(vport
);
2727 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2728 * ring the match the sppecified nodelist.
2731 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
2733 LIST_HEAD(completions
);
2734 struct lpfc_sli
*psli
;
2736 struct lpfc_iocbq
*iocb
, *next_iocb
;
2737 struct lpfc_sli_ring
*pring
;
2740 pring
= &psli
->ring
[LPFC_ELS_RING
];
2742 /* Error matching iocb on txq or txcmplq
2743 * First check the txq.
2745 spin_lock_irq(&phba
->hbalock
);
2746 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
2747 if (iocb
->context1
!= ndlp
) {
2751 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
2752 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
2754 list_move_tail(&iocb
->list
, &completions
);
2759 /* Next check the txcmplq */
2760 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
2761 if (iocb
->context1
!= ndlp
) {
2765 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
2766 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
2767 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
2770 spin_unlock_irq(&phba
->hbalock
);
2772 /* Cancel all the IOCBs from the completions list */
2773 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
2778 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
2780 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2781 struct lpfc_hba
*phba
= vport
->phba
;
2783 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
2784 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
2786 if (!NLP_CHK_NODE_ACT(ndlp
))
2788 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
2789 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
2790 lpfc_free_tx(phba
, ndlp
);
2797 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
2799 lpfc_els_flush_rscn(vport
);
2800 lpfc_els_flush_cmd(vport
);
2801 lpfc_disc_flush_list(vport
);
2804 /*****************************************************************************/
2806 * NAME: lpfc_disc_timeout
2808 * FUNCTION: Fibre Channel driver discovery timeout routine.
2810 * EXECUTION ENVIRONMENT: interrupt only
2818 /*****************************************************************************/
2820 lpfc_disc_timeout(unsigned long ptr
)
2822 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
2823 struct lpfc_hba
*phba
= vport
->phba
;
2824 uint32_t tmo_posted
;
2825 unsigned long flags
= 0;
2827 if (unlikely(!phba
))
2830 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
2831 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
2833 vport
->work_port_events
|= WORKER_DISC_TMO
;
2834 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
2837 lpfc_worker_wake_up(phba
);
2842 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
2844 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2845 struct lpfc_hba
*phba
= vport
->phba
;
2846 struct lpfc_sli
*psli
= &phba
->sli
;
2847 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2848 LPFC_MBOXQ_t
*initlinkmbox
;
2849 int rc
, clrlaerr
= 0;
2851 if (!(vport
->fc_flag
& FC_DISC_TMO
))
2854 spin_lock_irq(shost
->host_lock
);
2855 vport
->fc_flag
&= ~FC_DISC_TMO
;
2856 spin_unlock_irq(shost
->host_lock
);
2858 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2859 "disc timeout: state:x%x rtry:x%x flg:x%x",
2860 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
2862 switch (vport
->port_state
) {
2864 case LPFC_LOCAL_CFG_LINK
:
2865 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2869 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
2870 "0221 FAN timeout\n");
2871 /* Start discovery by sending FLOGI, clean up old rpis */
2872 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
2874 if (!NLP_CHK_NODE_ACT(ndlp
))
2876 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
2878 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2879 /* Clean up the ndlp on Fabric connections */
2880 lpfc_drop_node(vport
, ndlp
);
2882 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
2883 /* Fail outstanding IO now since device
2884 * is marked for PLOGI.
2886 lpfc_unreg_rpi(vport
, ndlp
);
2889 if (vport
->port_state
!= LPFC_FLOGI
) {
2890 lpfc_initial_flogi(vport
);
2897 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2898 /* Initial FLOGI timeout */
2899 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2900 "0222 Initial %s timeout\n",
2901 vport
->vpi
? "FDISC" : "FLOGI");
2903 /* Assume no Fabric and go on with discovery.
2904 * Check for outstanding ELS FLOGI to abort.
2907 /* FLOGI failed, so just use loop map to make discovery list */
2908 lpfc_disc_list_loopmap(vport
);
2910 /* Start discovery */
2911 lpfc_disc_start(vport
);
2914 case LPFC_FABRIC_CFG_LINK
:
2915 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2917 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2918 "0223 Timeout while waiting for "
2919 "NameServer login\n");
2920 /* Next look for NameServer ndlp */
2921 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
2922 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
2923 lpfc_els_abort(phba
, ndlp
);
2925 /* ReStart discovery */
2929 /* Check for wait for NameServer Rsp timeout */
2930 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2931 "0224 NameServer Query timeout "
2933 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
2935 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
2936 /* Try it one more time */
2937 vport
->fc_ns_retry
++;
2938 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
,
2939 vport
->fc_ns_retry
, 0);
2943 vport
->fc_ns_retry
= 0;
2947 * Discovery is over.
2948 * set port_state to PORT_READY if SLI2.
2949 * cmpl_reg_vpi will set port_state to READY for SLI3.
2951 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2952 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2953 lpfc_issue_reg_vpi(phba
, vport
);
2954 else { /* NPIV Not enabled */
2955 lpfc_issue_clear_la(phba
, vport
);
2956 vport
->port_state
= LPFC_VPORT_READY
;
2960 /* Setup and issue mailbox INITIALIZE LINK command */
2961 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2962 if (!initlinkmbox
) {
2963 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2964 "0206 Device Discovery "
2965 "completion error\n");
2966 phba
->link_state
= LPFC_HBA_ERROR
;
2970 lpfc_linkdown(phba
);
2971 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
2972 phba
->cfg_link_speed
);
2973 initlinkmbox
->mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
2974 initlinkmbox
->vport
= vport
;
2975 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2976 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
2977 lpfc_set_loopback_flag(phba
);
2978 if (rc
== MBX_NOT_FINISHED
)
2979 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
2983 case LPFC_DISC_AUTH
:
2984 /* Node Authentication timeout */
2985 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2986 "0227 Node Authentication timeout\n");
2987 lpfc_disc_flush_list(vport
);
2990 * set port_state to PORT_READY if SLI2.
2991 * cmpl_reg_vpi will set port_state to READY for SLI3.
2993 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
2994 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2995 lpfc_issue_reg_vpi(phba
, vport
);
2996 else { /* NPIV Not enabled */
2997 lpfc_issue_clear_la(phba
, vport
);
2998 vport
->port_state
= LPFC_VPORT_READY
;
3003 case LPFC_VPORT_READY
:
3004 if (vport
->fc_flag
& FC_RSCN_MODE
) {
3005 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3006 "0231 RSCN timeout Data: x%x "
3008 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
3010 /* Cleanup any outstanding ELS commands */
3011 lpfc_els_flush_cmd(vport
);
3013 lpfc_els_flush_rscn(vport
);
3014 lpfc_disc_flush_list(vport
);
3019 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3020 "0273 Unexpected discovery timeout, "
3021 "vport State x%x\n", vport
->port_state
);
3025 switch (phba
->link_state
) {
3027 /* CLEAR LA timeout */
3028 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3029 "0228 CLEAR LA timeout\n");
3034 lpfc_issue_clear_la(phba
, vport
);
3036 case LPFC_LINK_UNKNOWN
:
3037 case LPFC_WARM_START
:
3038 case LPFC_INIT_START
:
3039 case LPFC_INIT_MBX_CMDS
:
3040 case LPFC_LINK_DOWN
:
3041 case LPFC_HBA_ERROR
:
3042 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3043 "0230 Unexpected timeout, hba link "
3044 "state x%x\n", phba
->link_state
);
3048 case LPFC_HBA_READY
:
3053 lpfc_disc_flush_list(vport
);
3054 psli
->ring
[(psli
->extra_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
3055 psli
->ring
[(psli
->fcp_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
3056 psli
->ring
[(psli
->next_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
3057 vport
->port_state
= LPFC_VPORT_READY
;
3064 * This routine handles processing a NameServer REG_LOGIN mailbox
3065 * command upon completion. It is setup in the LPFC_MBOXQ
3066 * as the completion routine when the command is
3067 * handed off to the SLI layer.
3070 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3072 MAILBOX_t
*mb
= &pmb
->mb
;
3073 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3074 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3075 struct lpfc_vport
*vport
= pmb
->vport
;
3077 pmb
->context1
= NULL
;
3079 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3080 ndlp
->nlp_type
|= NLP_FABRIC
;
3081 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3084 * Start issuing Fabric-Device Management Interface (FDMI) command to
3085 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
3086 * fdmi-on=2 (supporting RPA/hostnmae)
3089 if (vport
->cfg_fdmi_on
== 1)
3090 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
);
3092 mod_timer(&vport
->fc_fdmitmo
, jiffies
+ HZ
* 60);
3094 /* decrement the node reference count held for this callback
3098 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3100 mempool_free(pmb
, phba
->mbox_mem_pool
);
3106 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
3108 uint16_t *rpi
= param
;
3110 return ndlp
->nlp_rpi
== *rpi
;
3114 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
3116 return memcmp(&ndlp
->nlp_portname
, param
,
3117 sizeof(ndlp
->nlp_portname
)) == 0;
3120 static struct lpfc_nodelist
*
3121 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
3123 struct lpfc_nodelist
*ndlp
;
3125 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3126 if (filter(ndlp
, param
))
3133 * This routine looks up the ndlp lists for the given RPI. If rpi found it
3134 * returns the node list element pointer else return NULL.
3136 struct lpfc_nodelist
*
3137 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
3139 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
3143 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
3144 * returns the node element list pointer else return NULL.
3146 struct lpfc_nodelist
*
3147 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
3149 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3150 struct lpfc_nodelist
*ndlp
;
3152 spin_lock_irq(shost
->host_lock
);
3153 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
3154 spin_unlock_irq(shost
->host_lock
);
3159 lpfc_nlp_init(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3162 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
3164 lpfc_initialize_node(vport
, ndlp
, did
);
3165 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
3167 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
3168 "node init: did:x%x",
3169 ndlp
->nlp_DID
, 0, 0);
3174 /* This routine releases all resources associated with a specifc NPort's ndlp
3175 * and mempool_free's the nodelist.
3178 lpfc_nlp_release(struct kref
*kref
)
3180 struct lpfc_hba
*phba
;
3181 unsigned long flags
;
3182 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
3185 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
3186 "node release: did:x%x flg:x%x type:x%x",
3187 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
3189 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
3190 "0279 lpfc_nlp_release: ndlp:x%p "
3191 "usgmap:x%x refcnt:%d\n",
3192 (void *)ndlp
, ndlp
->nlp_usg_map
,
3193 atomic_read(&ndlp
->kref
.refcount
));
3195 /* remove ndlp from action. */
3196 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
3198 /* clear the ndlp active flag for all release cases */
3200 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3201 NLP_CLR_NODE_ACT(ndlp
);
3202 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3204 /* free ndlp memory for final ndlp release */
3205 if (NLP_CHK_FREE_REQ(ndlp
)) {
3206 kfree(ndlp
->lat_data
);
3207 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
3211 /* This routine bumps the reference count for a ndlp structure to ensure
3212 * that one discovery thread won't free a ndlp while another discovery thread
3215 struct lpfc_nodelist
*
3216 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
3218 struct lpfc_hba
*phba
;
3219 unsigned long flags
;
3222 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
3223 "node get: did:x%x flg:x%x refcnt:x%x",
3224 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3225 atomic_read(&ndlp
->kref
.refcount
));
3226 /* The check of ndlp usage to prevent incrementing the
3227 * ndlp reference count that is in the process of being
3231 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3232 if (!NLP_CHK_NODE_ACT(ndlp
) || NLP_CHK_FREE_ACK(ndlp
)) {
3233 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3234 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
3235 "0276 lpfc_nlp_get: ndlp:x%p "
3236 "usgmap:x%x refcnt:%d\n",
3237 (void *)ndlp
, ndlp
->nlp_usg_map
,
3238 atomic_read(&ndlp
->kref
.refcount
));
3241 kref_get(&ndlp
->kref
);
3242 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3247 /* This routine decrements the reference count for a ndlp structure. If the
3248 * count goes to 0, this indicates the the associated nodelist should be
3249 * freed. Returning 1 indicates the ndlp resource has been released; on the
3250 * other hand, returning 0 indicates the ndlp resource has not been released
3254 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
3256 struct lpfc_hba
*phba
;
3257 unsigned long flags
;
3262 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
3263 "node put: did:x%x flg:x%x refcnt:x%x",
3264 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3265 atomic_read(&ndlp
->kref
.refcount
));
3267 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3268 /* Check the ndlp memory free acknowledge flag to avoid the
3269 * possible race condition that kref_put got invoked again
3270 * after previous one has done ndlp memory free.
3272 if (NLP_CHK_FREE_ACK(ndlp
)) {
3273 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3274 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
3275 "0274 lpfc_nlp_put: ndlp:x%p "
3276 "usgmap:x%x refcnt:%d\n",
3277 (void *)ndlp
, ndlp
->nlp_usg_map
,
3278 atomic_read(&ndlp
->kref
.refcount
));
3281 /* Check the ndlp inactivate log flag to avoid the possible
3282 * race condition that kref_put got invoked again after ndlp
3283 * is already in inactivating state.
3285 if (NLP_CHK_IACT_REQ(ndlp
)) {
3286 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3287 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
3288 "0275 lpfc_nlp_put: ndlp:x%p "
3289 "usgmap:x%x refcnt:%d\n",
3290 (void *)ndlp
, ndlp
->nlp_usg_map
,
3291 atomic_read(&ndlp
->kref
.refcount
));
3294 /* For last put, mark the ndlp usage flags to make sure no
3295 * other kref_get and kref_put on the same ndlp shall get
3296 * in between the process when the final kref_put has been
3297 * invoked on this ndlp.
3299 if (atomic_read(&ndlp
->kref
.refcount
) == 1) {
3300 /* Indicate ndlp is put to inactive state. */
3301 NLP_SET_IACT_REQ(ndlp
);
3302 /* Acknowledge ndlp memory free has been seen. */
3303 if (NLP_CHK_FREE_REQ(ndlp
))
3304 NLP_SET_FREE_ACK(ndlp
);
3306 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3307 /* Note, the kref_put returns 1 when decrementing a reference
3308 * count that was 1, it invokes the release callback function,
3309 * but it still left the reference count as 1 (not actually
3310 * performs the last decrementation). Otherwise, it actually
3311 * decrements the reference count and returns 0.
3313 return kref_put(&ndlp
->kref
, lpfc_nlp_release
);
3316 /* This routine free's the specified nodelist if it is not in use
3317 * by any other discovery thread. This routine returns 1 if the
3318 * ndlp has been freed. A return value of 0 indicates the ndlp is
3319 * not yet been released.
3322 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
3324 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
3325 "node not used: did:x%x flg:x%x refcnt:x%x",
3326 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3327 atomic_read(&ndlp
->kref
.refcount
));
3328 if (atomic_read(&ndlp
->kref
.refcount
) == 1)
3329 if (lpfc_nlp_put(ndlp
))