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>
34 #include "lpfc_disc.h"
36 #include "lpfc_scsi.h"
38 #include "lpfc_logmsg.h"
39 #include "lpfc_crtn.h"
40 #include "lpfc_vport.h"
41 #include "lpfc_debugfs.h"
43 /* AlpaArray for assignment of scsid for scan-down and bind_method */
44 static uint8_t lpfcAlpaArray
[] = {
45 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
46 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
47 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
48 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
49 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
50 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
51 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
52 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
53 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
54 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
55 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
56 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
57 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
60 static void lpfc_disc_timeout_handler(struct lpfc_vport
*);
61 static void lpfc_disc_flush_list(struct lpfc_vport
*vport
);
64 lpfc_terminate_rport_io(struct fc_rport
*rport
)
66 struct lpfc_rport_data
*rdata
;
67 struct lpfc_nodelist
* ndlp
;
68 struct lpfc_hba
*phba
;
70 rdata
= rport
->dd_data
;
73 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
74 if (rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)
75 printk(KERN_ERR
"Cannot find remote node"
76 " to terminate I/O Data x%x\n",
83 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
84 "rport terminate: sid:x%x did:x%x flg:x%x",
85 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
87 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
88 lpfc_sli_abort_iocb(ndlp
->vport
,
89 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
90 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
95 * This function will be called when dev_loss_tmo fire.
98 lpfc_dev_loss_tmo_callbk(struct fc_rport
*rport
)
100 struct lpfc_rport_data
*rdata
;
101 struct lpfc_nodelist
* ndlp
;
102 struct lpfc_vport
*vport
;
103 struct lpfc_hba
*phba
;
104 struct lpfc_work_evt
*evtp
;
108 rdata
= rport
->dd_data
;
110 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
116 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
117 "rport devlosscb: sid:x%x did:x%x flg:x%x",
118 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
120 /* Don't defer this if we are in the process of deleting the vport
121 * or unloading the driver. The unload will cleanup the node
122 * appropriately we just need to cleanup the ndlp rport info here.
124 if (vport
->load_flag
& FC_UNLOADING
) {
125 put_node
= rdata
->pnode
!= NULL
;
126 put_rport
= ndlp
->rport
!= NULL
;
132 put_device(&rport
->dev
);
136 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)
139 evtp
= &ndlp
->dev_loss_evt
;
141 if (!list_empty(&evtp
->evt_listp
))
144 spin_lock_irq(&phba
->hbalock
);
145 /* We need to hold the node by incrementing the reference
146 * count until this queued work is done
148 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
149 if (evtp
->evt_arg1
) {
150 evtp
->evt
= LPFC_EVT_DEV_LOSS
;
151 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
152 lpfc_worker_wake_up(phba
);
154 spin_unlock_irq(&phba
->hbalock
);
160 * This function is called from the worker thread when dev_loss_tmo
164 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist
*ndlp
)
166 struct lpfc_rport_data
*rdata
;
167 struct fc_rport
*rport
;
168 struct lpfc_vport
*vport
;
169 struct lpfc_hba
*phba
;
180 rdata
= rport
->dd_data
;
181 name
= (uint8_t *) &ndlp
->nlp_portname
;
185 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
186 "rport devlosstmo:did:x%x type:x%x id:x%x",
187 ndlp
->nlp_DID
, ndlp
->nlp_type
, rport
->scsi_target_id
);
189 /* Don't defer this if we are in the process of deleting the vport
190 * or unloading the driver. The unload will cleanup the node
191 * appropriately we just need to cleanup the ndlp rport info here.
193 if (vport
->load_flag
& FC_UNLOADING
) {
194 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
195 /* flush the target */
196 lpfc_sli_abort_iocb(vport
,
197 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
198 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
200 put_node
= rdata
->pnode
!= NULL
;
201 put_rport
= ndlp
->rport
!= NULL
;
207 put_device(&rport
->dev
);
211 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
212 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
213 "0284 Devloss timeout Ignored on "
214 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
216 *name
, *(name
+1), *(name
+2), *(name
+3),
217 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
222 if (ndlp
->nlp_type
& NLP_FABRIC
) {
223 /* We will clean up these Nodes in linkup */
224 put_node
= rdata
->pnode
!= NULL
;
225 put_rport
= ndlp
->rport
!= NULL
;
231 put_device(&rport
->dev
);
235 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
237 /* flush the target */
238 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
239 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
243 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
244 "0203 Devloss timeout on "
245 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
246 "NPort x%06x Data: x%x x%x x%x\n",
247 *name
, *(name
+1), *(name
+2), *(name
+3),
248 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
249 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
250 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
252 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
253 "0204 Devloss timeout on "
254 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
255 "NPort x%06x Data: x%x x%x x%x\n",
256 *name
, *(name
+1), *(name
+2), *(name
+3),
257 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
258 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
259 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
262 put_node
= rdata
->pnode
!= NULL
;
263 put_rport
= ndlp
->rport
!= NULL
;
269 put_device(&rport
->dev
);
271 if (!(vport
->load_flag
& FC_UNLOADING
) &&
272 !(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
273 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
274 (ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
))
275 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
279 * lpfc_alloc_fast_evt - Allocates data structure for posting event
280 * @phba: Pointer to hba context object.
282 * This function is called from the functions which need to post
283 * events from interrupt context. This function allocates data
284 * structure required for posting event. It also keeps track of
285 * number of events pending and prevent event storm when there are
288 struct lpfc_fast_path_event
*
289 lpfc_alloc_fast_evt(struct lpfc_hba
*phba
) {
290 struct lpfc_fast_path_event
*ret
;
292 /* If there are lot of fast event do not exhaust memory due to this */
293 if (atomic_read(&phba
->fast_event_count
) > LPFC_MAX_EVT_COUNT
)
296 ret
= kzalloc(sizeof(struct lpfc_fast_path_event
),
299 atomic_inc(&phba
->fast_event_count
);
300 INIT_LIST_HEAD(&ret
->work_evt
.evt_listp
);
301 ret
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
306 * lpfc_free_fast_evt - Frees event data structure
307 * @phba: Pointer to hba context object.
308 * @evt: Event object which need to be freed.
310 * This function frees the data structure required for posting
314 lpfc_free_fast_evt(struct lpfc_hba
*phba
,
315 struct lpfc_fast_path_event
*evt
) {
317 atomic_dec(&phba
->fast_event_count
);
322 * lpfc_send_fastpath_evt - Posts events generated from fast path
323 * @phba: Pointer to hba context object.
324 * @evtp: Event data structure.
326 * This function is called from worker thread, when the interrupt
327 * context need to post an event. This function posts the event
328 * to fc transport netlink interface.
331 lpfc_send_fastpath_evt(struct lpfc_hba
*phba
,
332 struct lpfc_work_evt
*evtp
)
334 unsigned long evt_category
, evt_sub_category
;
335 struct lpfc_fast_path_event
*fast_evt_data
;
337 uint32_t evt_data_size
;
338 struct Scsi_Host
*shost
;
340 fast_evt_data
= container_of(evtp
, struct lpfc_fast_path_event
,
343 evt_category
= (unsigned long) fast_evt_data
->un
.fabric_evt
.event_type
;
344 evt_sub_category
= (unsigned long) fast_evt_data
->un
.
345 fabric_evt
.subcategory
;
346 shost
= lpfc_shost_from_vport(fast_evt_data
->vport
);
347 if (evt_category
== FC_REG_FABRIC_EVENT
) {
348 if (evt_sub_category
== LPFC_EVENT_FCPRDCHKERR
) {
349 evt_data
= (char *) &fast_evt_data
->un
.read_check_error
;
350 evt_data_size
= sizeof(fast_evt_data
->un
.
352 } else if ((evt_sub_category
== LPFC_EVENT_FABRIC_BUSY
) ||
353 (evt_sub_category
== LPFC_EVENT_PORT_BUSY
)) {
354 evt_data
= (char *) &fast_evt_data
->un
.fabric_evt
;
355 evt_data_size
= sizeof(fast_evt_data
->un
.fabric_evt
);
357 lpfc_free_fast_evt(phba
, fast_evt_data
);
360 } else if (evt_category
== FC_REG_SCSI_EVENT
) {
361 switch (evt_sub_category
) {
362 case LPFC_EVENT_QFULL
:
363 case LPFC_EVENT_DEVBSY
:
364 evt_data
= (char *) &fast_evt_data
->un
.scsi_evt
;
365 evt_data_size
= sizeof(fast_evt_data
->un
.scsi_evt
);
367 case LPFC_EVENT_CHECK_COND
:
368 evt_data
= (char *) &fast_evt_data
->un
.check_cond_evt
;
369 evt_data_size
= sizeof(fast_evt_data
->un
.
372 case LPFC_EVENT_VARQUEDEPTH
:
373 evt_data
= (char *) &fast_evt_data
->un
.queue_depth_evt
;
374 evt_data_size
= sizeof(fast_evt_data
->un
.
378 lpfc_free_fast_evt(phba
, fast_evt_data
);
382 lpfc_free_fast_evt(phba
, fast_evt_data
);
386 fc_host_post_vendor_event(shost
,
387 fc_get_event_number(),
392 lpfc_free_fast_evt(phba
, fast_evt_data
);
397 lpfc_work_list_done(struct lpfc_hba
*phba
)
399 struct lpfc_work_evt
*evtp
= NULL
;
400 struct lpfc_nodelist
*ndlp
;
403 spin_lock_irq(&phba
->hbalock
);
404 while (!list_empty(&phba
->work_list
)) {
405 list_remove_head((&phba
->work_list
), evtp
, typeof(*evtp
),
407 spin_unlock_irq(&phba
->hbalock
);
410 case LPFC_EVT_ELS_RETRY
:
411 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
412 lpfc_els_retry_delay_handler(ndlp
);
413 free_evt
= 0; /* evt is part of ndlp */
414 /* decrement the node reference count held
415 * for this queued work
419 case LPFC_EVT_DEV_LOSS
:
420 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
421 lpfc_dev_loss_tmo_handler(ndlp
);
423 /* decrement the node reference count held for
428 case LPFC_EVT_ONLINE
:
429 if (phba
->link_state
< LPFC_LINK_DOWN
)
430 *(int *) (evtp
->evt_arg1
) = lpfc_online(phba
);
432 *(int *) (evtp
->evt_arg1
) = 0;
433 complete((struct completion
*)(evtp
->evt_arg2
));
435 case LPFC_EVT_OFFLINE_PREP
:
436 if (phba
->link_state
>= LPFC_LINK_DOWN
)
437 lpfc_offline_prep(phba
);
438 *(int *)(evtp
->evt_arg1
) = 0;
439 complete((struct completion
*)(evtp
->evt_arg2
));
441 case LPFC_EVT_OFFLINE
:
443 lpfc_sli_brdrestart(phba
);
444 *(int *)(evtp
->evt_arg1
) =
445 lpfc_sli_brdready(phba
, HS_FFRDY
| HS_MBRDY
);
446 lpfc_unblock_mgmt_io(phba
);
447 complete((struct completion
*)(evtp
->evt_arg2
));
449 case LPFC_EVT_WARM_START
:
451 lpfc_reset_barrier(phba
);
452 lpfc_sli_brdreset(phba
);
453 lpfc_hba_down_post(phba
);
454 *(int *)(evtp
->evt_arg1
) =
455 lpfc_sli_brdready(phba
, HS_MBRDY
);
456 lpfc_unblock_mgmt_io(phba
);
457 complete((struct completion
*)(evtp
->evt_arg2
));
461 *(int *)(evtp
->evt_arg1
)
462 = (phba
->pport
->stopped
)
463 ? 0 : lpfc_sli_brdkill(phba
);
464 lpfc_unblock_mgmt_io(phba
);
465 complete((struct completion
*)(evtp
->evt_arg2
));
467 case LPFC_EVT_FASTPATH_MGMT_EVT
:
468 lpfc_send_fastpath_evt(phba
, evtp
);
474 spin_lock_irq(&phba
->hbalock
);
476 spin_unlock_irq(&phba
->hbalock
);
481 lpfc_work_done(struct lpfc_hba
*phba
)
483 struct lpfc_sli_ring
*pring
;
484 uint32_t ha_copy
, status
, control
, work_port_events
;
485 struct lpfc_vport
**vports
;
486 struct lpfc_vport
*vport
;
489 spin_lock_irq(&phba
->hbalock
);
490 ha_copy
= phba
->work_ha
;
492 spin_unlock_irq(&phba
->hbalock
);
494 if (ha_copy
& HA_ERATT
)
495 /* Handle the error attention event */
496 lpfc_handle_eratt(phba
);
498 if (ha_copy
& HA_MBATT
)
499 lpfc_sli_handle_mb_event(phba
);
501 if (ha_copy
& HA_LATT
)
502 lpfc_handle_latt(phba
);
504 vports
= lpfc_create_vport_work_array(phba
);
506 for(i
= 0; i
<= phba
->max_vpi
; i
++) {
508 * We could have no vports in array if unloading, so if
509 * this happens then just use the pport
511 if (vports
[i
] == NULL
&& i
== 0)
517 spin_lock_irq(&vport
->work_port_lock
);
518 work_port_events
= vport
->work_port_events
;
519 vport
->work_port_events
&= ~work_port_events
;
520 spin_unlock_irq(&vport
->work_port_lock
);
521 if (work_port_events
& WORKER_DISC_TMO
)
522 lpfc_disc_timeout_handler(vport
);
523 if (work_port_events
& WORKER_ELS_TMO
)
524 lpfc_els_timeout_handler(vport
);
525 if (work_port_events
& WORKER_HB_TMO
)
526 lpfc_hb_timeout_handler(phba
);
527 if (work_port_events
& WORKER_MBOX_TMO
)
528 lpfc_mbox_timeout_handler(phba
);
529 if (work_port_events
& WORKER_FABRIC_BLOCK_TMO
)
530 lpfc_unblock_fabric_iocbs(phba
);
531 if (work_port_events
& WORKER_FDMI_TMO
)
532 lpfc_fdmi_timeout_handler(vport
);
533 if (work_port_events
& WORKER_RAMP_DOWN_QUEUE
)
534 lpfc_ramp_down_queue_handler(phba
);
535 if (work_port_events
& WORKER_RAMP_UP_QUEUE
)
536 lpfc_ramp_up_queue_handler(phba
);
538 lpfc_destroy_vport_work_array(phba
, vports
);
540 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
541 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
542 status
>>= (4*LPFC_ELS_RING
);
543 if ((status
& HA_RXMASK
)
544 || (pring
->flag
& LPFC_DEFERRED_RING_EVENT
)) {
545 if (pring
->flag
& LPFC_STOP_IOCB_EVENT
) {
546 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
547 /* Set the lpfc data pending flag */
548 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
550 pring
->flag
&= ~LPFC_DEFERRED_RING_EVENT
;
551 lpfc_sli_handle_slow_ring_event(phba
, pring
,
556 * Turn on Ring interrupts
558 spin_lock_irq(&phba
->hbalock
);
559 control
= readl(phba
->HCregaddr
);
560 if (!(control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
))) {
561 lpfc_debugfs_slow_ring_trc(phba
,
562 "WRK Enable ring: cntl:x%x hacopy:x%x",
563 control
, ha_copy
, 0);
565 control
|= (HC_R0INT_ENA
<< LPFC_ELS_RING
);
566 writel(control
, phba
->HCregaddr
);
567 readl(phba
->HCregaddr
); /* flush */
570 lpfc_debugfs_slow_ring_trc(phba
,
571 "WRK Ring ok: cntl:x%x hacopy:x%x",
572 control
, ha_copy
, 0);
574 spin_unlock_irq(&phba
->hbalock
);
576 lpfc_work_list_done(phba
);
580 lpfc_do_work(void *p
)
582 struct lpfc_hba
*phba
= p
;
585 set_user_nice(current
, -20);
586 phba
->data_flags
= 0;
588 while (!kthread_should_stop()) {
589 /* wait and check worker queue activities */
590 rc
= wait_event_interruptible(phba
->work_waitq
,
591 (test_and_clear_bit(LPFC_DATA_READY
,
593 || kthread_should_stop()));
594 /* Signal wakeup shall terminate the worker thread */
596 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
597 "0433 Wakeup on signal: rc=x%x\n", rc
);
601 /* Attend pending lpfc data processing */
602 lpfc_work_done(phba
);
604 phba
->worker_thread
= NULL
;
605 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
606 "0432 Worker thread stopped.\n");
611 * This is only called to handle FC worker events. Since this a rare
612 * occurance, we allocate a struct lpfc_work_evt structure here instead of
613 * embedding it in the IOCB.
616 lpfc_workq_post_event(struct lpfc_hba
*phba
, void *arg1
, void *arg2
,
619 struct lpfc_work_evt
*evtp
;
623 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
624 * be queued to worker thread for processing
626 evtp
= kmalloc(sizeof(struct lpfc_work_evt
), GFP_ATOMIC
);
630 evtp
->evt_arg1
= arg1
;
631 evtp
->evt_arg2
= arg2
;
634 spin_lock_irqsave(&phba
->hbalock
, flags
);
635 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
636 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
638 lpfc_worker_wake_up(phba
);
644 lpfc_cleanup_rpis(struct lpfc_vport
*vport
, int remove
)
646 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
647 struct lpfc_hba
*phba
= vport
->phba
;
648 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
651 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
652 if (!NLP_CHK_NODE_ACT(ndlp
))
654 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
656 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) ||
657 ((vport
->port_type
== LPFC_NPIV_PORT
) &&
658 (ndlp
->nlp_DID
== NameServer_DID
)))
659 lpfc_unreg_rpi(vport
, ndlp
);
661 /* Leave Fabric nodes alone on link down */
662 if (!remove
&& ndlp
->nlp_type
& NLP_FABRIC
)
664 rc
= lpfc_disc_state_machine(vport
, ndlp
, NULL
,
667 : NLP_EVT_DEVICE_RECOVERY
);
669 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) {
670 lpfc_mbx_unreg_vpi(vport
);
671 spin_lock_irq(shost
->host_lock
);
672 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
673 spin_unlock_irq(shost
->host_lock
);
678 lpfc_port_link_failure(struct lpfc_vport
*vport
)
680 /* Cleanup any outstanding RSCN activity */
681 lpfc_els_flush_rscn(vport
);
683 /* Cleanup any outstanding ELS commands */
684 lpfc_els_flush_cmd(vport
);
686 lpfc_cleanup_rpis(vport
, 0);
688 /* Turn off discovery timer if its running */
689 lpfc_can_disctmo(vport
);
693 lpfc_linkdown_port(struct lpfc_vport
*vport
)
695 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
697 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKDOWN
, 0);
699 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
700 "Link Down: state:x%x rtry:x%x flg:x%x",
701 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
703 lpfc_port_link_failure(vport
);
708 lpfc_linkdown(struct lpfc_hba
*phba
)
710 struct lpfc_vport
*vport
= phba
->pport
;
711 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
712 struct lpfc_vport
**vports
;
716 if (phba
->link_state
== LPFC_LINK_DOWN
)
718 spin_lock_irq(&phba
->hbalock
);
719 if (phba
->link_state
> LPFC_LINK_DOWN
) {
720 phba
->link_state
= LPFC_LINK_DOWN
;
721 phba
->pport
->fc_flag
&= ~FC_LBIT
;
723 spin_unlock_irq(&phba
->hbalock
);
724 vports
= lpfc_create_vport_work_array(phba
);
726 for(i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++) {
727 /* Issue a LINK DOWN event to all nodes */
728 lpfc_linkdown_port(vports
[i
]);
730 lpfc_destroy_vport_work_array(phba
, vports
);
731 /* Clean up any firmware default rpi's */
732 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
734 lpfc_unreg_did(phba
, 0xffff, 0xffffffff, mb
);
736 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
737 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
738 == MBX_NOT_FINISHED
) {
739 mempool_free(mb
, phba
->mbox_mem_pool
);
743 /* Setup myDID for link up if we are in pt2pt mode */
744 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
745 phba
->pport
->fc_myDID
= 0;
746 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
748 lpfc_config_link(phba
, mb
);
749 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
751 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
752 == MBX_NOT_FINISHED
) {
753 mempool_free(mb
, phba
->mbox_mem_pool
);
756 spin_lock_irq(shost
->host_lock
);
757 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
758 spin_unlock_irq(shost
->host_lock
);
765 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
767 struct lpfc_nodelist
*ndlp
;
769 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
770 if (!NLP_CHK_NODE_ACT(ndlp
))
772 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
774 if (ndlp
->nlp_type
& NLP_FABRIC
) {
775 /* On Linkup its safe to clean up the ndlp
776 * from Fabric connections.
778 if (ndlp
->nlp_DID
!= Fabric_DID
)
779 lpfc_unreg_rpi(vport
, ndlp
);
780 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
781 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
782 /* Fail outstanding IO now since device is
785 lpfc_unreg_rpi(vport
, ndlp
);
791 lpfc_linkup_port(struct lpfc_vport
*vport
)
793 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
794 struct lpfc_hba
*phba
= vport
->phba
;
796 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
799 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
800 "Link Up: top:x%x speed:x%x flg:x%x",
801 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
803 /* If NPIV is not enabled, only bring the physical port up */
804 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
805 (vport
!= phba
->pport
))
808 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKUP
, 0);
810 spin_lock_irq(shost
->host_lock
);
811 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
812 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
813 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
814 vport
->fc_ns_retry
= 0;
815 spin_unlock_irq(shost
->host_lock
);
817 if (vport
->fc_flag
& FC_LBIT
)
818 lpfc_linkup_cleanup_nodes(vport
);
823 lpfc_linkup(struct lpfc_hba
*phba
)
825 struct lpfc_vport
**vports
;
828 phba
->link_state
= LPFC_LINK_UP
;
830 /* Unblock fabric iocbs if they are blocked */
831 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
832 del_timer_sync(&phba
->fabric_block_timer
);
834 vports
= lpfc_create_vport_work_array(phba
);
836 for(i
= 0; i
<= phba
->max_vpi
&& vports
[i
] != NULL
; i
++)
837 lpfc_linkup_port(vports
[i
]);
838 lpfc_destroy_vport_work_array(phba
, vports
);
839 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
840 lpfc_issue_clear_la(phba
, phba
->pport
);
846 * This routine handles processing a CLEAR_LA mailbox
847 * command upon completion. It is setup in the LPFC_MBOXQ
848 * as the completion routine when the command is
849 * handed off to the SLI layer.
852 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
854 struct lpfc_vport
*vport
= pmb
->vport
;
855 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
856 struct lpfc_sli
*psli
= &phba
->sli
;
857 MAILBOX_t
*mb
= &pmb
->mb
;
860 /* Since we don't do discovery right now, turn these off here */
861 psli
->ring
[psli
->extra_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
862 psli
->ring
[psli
->fcp_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
863 psli
->ring
[psli
->next_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
865 /* Check for error */
866 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
867 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
868 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
869 "0320 CLEAR_LA mbxStatus error x%x hba "
871 mb
->mbxStatus
, vport
->port_state
);
872 phba
->link_state
= LPFC_HBA_ERROR
;
876 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
877 phba
->link_state
= LPFC_HBA_READY
;
879 spin_lock_irq(&phba
->hbalock
);
880 psli
->sli_flag
|= LPFC_PROCESS_LA
;
881 control
= readl(phba
->HCregaddr
);
882 control
|= HC_LAINT_ENA
;
883 writel(control
, phba
->HCregaddr
);
884 readl(phba
->HCregaddr
); /* flush */
885 spin_unlock_irq(&phba
->hbalock
);
886 mempool_free(pmb
, phba
->mbox_mem_pool
);
890 /* Device Discovery completes */
891 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
892 "0225 Device Discovery completes\n");
893 mempool_free(pmb
, phba
->mbox_mem_pool
);
895 spin_lock_irq(shost
->host_lock
);
896 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
897 spin_unlock_irq(shost
->host_lock
);
899 lpfc_can_disctmo(vport
);
901 /* turn on Link Attention interrupts */
903 spin_lock_irq(&phba
->hbalock
);
904 psli
->sli_flag
|= LPFC_PROCESS_LA
;
905 control
= readl(phba
->HCregaddr
);
906 control
|= HC_LAINT_ENA
;
907 writel(control
, phba
->HCregaddr
);
908 readl(phba
->HCregaddr
); /* flush */
909 spin_unlock_irq(&phba
->hbalock
);
916 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
918 struct lpfc_vport
*vport
= pmb
->vport
;
920 if (pmb
->mb
.mbxStatus
)
923 mempool_free(pmb
, phba
->mbox_mem_pool
);
925 if (phba
->fc_topology
== TOPOLOGY_LOOP
&&
926 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
927 !(vport
->fc_flag
& FC_LBIT
)) {
928 /* Need to wait for FAN - use discovery timer
929 * for timeout. port_state is identically
930 * LPFC_LOCAL_CFG_LINK while waiting for FAN
932 lpfc_set_disctmo(vport
);
936 /* Start discovery by sending a FLOGI. port_state is identically
937 * LPFC_FLOGI while waiting for FLOGI cmpl
939 if (vport
->port_state
!= LPFC_FLOGI
) {
940 lpfc_initial_flogi(vport
);
945 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
946 "0306 CONFIG_LINK mbxStatus error x%x "
948 pmb
->mb
.mbxStatus
, vport
->port_state
);
949 mempool_free(pmb
, phba
->mbox_mem_pool
);
953 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
954 "0200 CONFIG_LINK bad hba state x%x\n",
957 lpfc_issue_clear_la(phba
, vport
);
962 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
964 MAILBOX_t
*mb
= &pmb
->mb
;
965 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
966 struct lpfc_vport
*vport
= pmb
->vport
;
969 /* Check for error */
971 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
972 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
973 "0319 READ_SPARAM mbxStatus error x%x "
975 mb
->mbxStatus
, vport
->port_state
);
980 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
981 sizeof (struct serv_parm
));
982 if (phba
->cfg_soft_wwnn
)
983 u64_to_wwn(phba
->cfg_soft_wwnn
,
984 vport
->fc_sparam
.nodeName
.u
.wwn
);
985 if (phba
->cfg_soft_wwpn
)
986 u64_to_wwn(phba
->cfg_soft_wwpn
,
987 vport
->fc_sparam
.portName
.u
.wwn
);
988 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
989 sizeof(vport
->fc_nodename
));
990 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
991 sizeof(vport
->fc_portname
));
992 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
993 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
994 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
997 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
999 mempool_free(pmb
, phba
->mbox_mem_pool
);
1003 pmb
->context1
= NULL
;
1004 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1006 lpfc_issue_clear_la(phba
, vport
);
1007 mempool_free(pmb
, phba
->mbox_mem_pool
);
1012 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, READ_LA_VAR
*la
)
1014 struct lpfc_vport
*vport
= phba
->pport
;
1015 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
;
1017 struct lpfc_dmabuf
*mp
;
1020 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1021 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1023 spin_lock_irq(&phba
->hbalock
);
1024 switch (la
->UlnkSpeed
) {
1026 phba
->fc_linkspeed
= LA_1GHZ_LINK
;
1029 phba
->fc_linkspeed
= LA_2GHZ_LINK
;
1032 phba
->fc_linkspeed
= LA_4GHZ_LINK
;
1035 phba
->fc_linkspeed
= LA_8GHZ_LINK
;
1038 phba
->fc_linkspeed
= LA_UNKNW_LINK
;
1042 phba
->fc_topology
= la
->topology
;
1043 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
1045 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1046 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
1048 if (phba
->cfg_enable_npiv
)
1049 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1050 "1309 Link Up Event npiv not supported in loop "
1052 /* Get Loop Map information */
1054 vport
->fc_flag
|= FC_LBIT
;
1056 vport
->fc_myDID
= la
->granted_AL_PA
;
1057 i
= la
->un
.lilpBde64
.tus
.f
.bdeSize
;
1060 phba
->alpa_map
[0] = 0;
1062 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
1073 numalpa
= phba
->alpa_map
[0];
1075 while (j
< numalpa
) {
1076 memset(un
.pamap
, 0, 16);
1077 for (k
= 1; j
< numalpa
; k
++) {
1079 phba
->alpa_map
[j
+ 1];
1084 /* Link Up Event ALPA map */
1085 lpfc_printf_log(phba
,
1088 "1304 Link Up Event "
1089 "ALPA map Data: x%x "
1091 un
.pa
.wd1
, un
.pa
.wd2
,
1092 un
.pa
.wd3
, un
.pa
.wd4
);
1097 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
1098 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1099 (phba
->sli_rev
== 3))
1100 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
1102 vport
->fc_myDID
= phba
->fc_pref_DID
;
1103 vport
->fc_flag
|= FC_LBIT
;
1105 spin_unlock_irq(&phba
->hbalock
);
1109 lpfc_read_sparam(phba
, sparam_mbox
, 0);
1110 sparam_mbox
->vport
= vport
;
1111 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
1112 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
1113 if (rc
== MBX_NOT_FINISHED
) {
1114 mp
= (struct lpfc_dmabuf
*) sparam_mbox
->context1
;
1115 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1117 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
1119 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
1125 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
1126 lpfc_config_link(phba
, cfglink_mbox
);
1127 cfglink_mbox
->vport
= vport
;
1128 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
1129 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
1130 if (rc
!= MBX_NOT_FINISHED
)
1132 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
1135 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1136 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1137 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
1138 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
1139 lpfc_issue_clear_la(phba
, vport
);
1144 lpfc_enable_la(struct lpfc_hba
*phba
)
1147 struct lpfc_sli
*psli
= &phba
->sli
;
1148 spin_lock_irq(&phba
->hbalock
);
1149 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1150 control
= readl(phba
->HCregaddr
);
1151 control
|= HC_LAINT_ENA
;
1152 writel(control
, phba
->HCregaddr
);
1153 readl(phba
->HCregaddr
); /* flush */
1154 spin_unlock_irq(&phba
->hbalock
);
1158 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
1160 lpfc_linkdown(phba
);
1161 lpfc_enable_la(phba
);
1162 /* turn on Link Attention interrupts - no CLEAR_LA needed */
1167 * This routine handles processing a READ_LA mailbox
1168 * command upon completion. It is setup in the LPFC_MBOXQ
1169 * as the completion routine when the command is
1170 * handed off to the SLI layer.
1173 lpfc_mbx_cmpl_read_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1175 struct lpfc_vport
*vport
= pmb
->vport
;
1176 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1178 MAILBOX_t
*mb
= &pmb
->mb
;
1179 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1181 /* Unblock ELS traffic */
1182 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1183 /* Check for error */
1184 if (mb
->mbxStatus
) {
1185 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1186 "1307 READ_LA mbox error x%x state x%x\n",
1187 mb
->mbxStatus
, vport
->port_state
);
1188 lpfc_mbx_issue_link_down(phba
);
1189 phba
->link_state
= LPFC_HBA_ERROR
;
1190 goto lpfc_mbx_cmpl_read_la_free_mbuf
;
1193 la
= (READ_LA_VAR
*) & pmb
->mb
.un
.varReadLA
;
1195 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
1197 spin_lock_irq(shost
->host_lock
);
1199 vport
->fc_flag
|= FC_BYPASSED_MODE
;
1201 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
1202 spin_unlock_irq(shost
->host_lock
);
1204 if (((phba
->fc_eventTag
+ 1) < la
->eventTag
) ||
1205 (phba
->fc_eventTag
== la
->eventTag
)) {
1206 phba
->fc_stat
.LinkMultiEvent
++;
1207 if (la
->attType
== AT_LINK_UP
)
1208 if (phba
->fc_eventTag
!= 0)
1209 lpfc_linkdown(phba
);
1212 phba
->fc_eventTag
= la
->eventTag
;
1214 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
1216 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
1218 if (la
->attType
== AT_LINK_UP
&& (!la
->mm
)) {
1219 phba
->fc_stat
.LinkUp
++;
1220 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
1221 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1222 "1306 Link Up Event in loop back mode "
1223 "x%x received Data: x%x x%x x%x x%x\n",
1224 la
->eventTag
, phba
->fc_eventTag
,
1225 la
->granted_AL_PA
, la
->UlnkSpeed
,
1228 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1229 "1303 Link Up Event x%x received "
1230 "Data: x%x x%x x%x x%x x%x x%x %d\n",
1231 la
->eventTag
, phba
->fc_eventTag
,
1232 la
->granted_AL_PA
, la
->UlnkSpeed
,
1235 phba
->wait_4_mlo_maint_flg
);
1237 lpfc_mbx_process_link_up(phba
, la
);
1238 } else if (la
->attType
== AT_LINK_DOWN
) {
1239 phba
->fc_stat
.LinkDown
++;
1240 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
1241 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1242 "1308 Link Down Event in loop back mode "
1244 "Data: x%x x%x x%x\n",
1245 la
->eventTag
, phba
->fc_eventTag
,
1246 phba
->pport
->port_state
, vport
->fc_flag
);
1249 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1250 "1305 Link Down Event x%x received "
1251 "Data: x%x x%x x%x x%x x%x\n",
1252 la
->eventTag
, phba
->fc_eventTag
,
1253 phba
->pport
->port_state
, vport
->fc_flag
,
1256 lpfc_mbx_issue_link_down(phba
);
1258 if (la
->mm
&& la
->attType
== AT_LINK_UP
) {
1259 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
1260 phba
->fc_stat
.LinkDown
++;
1261 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1262 "1312 Link Down Event x%x received "
1263 "Data: x%x x%x x%x\n",
1264 la
->eventTag
, phba
->fc_eventTag
,
1265 phba
->pport
->port_state
, vport
->fc_flag
);
1266 lpfc_mbx_issue_link_down(phba
);
1268 lpfc_enable_la(phba
);
1270 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1271 "1310 Menlo Maint Mode Link up Event x%x rcvd "
1272 "Data: x%x x%x x%x\n",
1273 la
->eventTag
, phba
->fc_eventTag
,
1274 phba
->pport
->port_state
, vport
->fc_flag
);
1276 * The cmnd that triggered this will be waiting for this
1279 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
1280 if (phba
->wait_4_mlo_maint_flg
) {
1281 phba
->wait_4_mlo_maint_flg
= 0;
1282 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
1288 lpfc_issue_clear_la(phba
, vport
);
1289 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1290 "1311 fa %d\n", la
->fa
);
1293 lpfc_mbx_cmpl_read_la_free_mbuf
:
1294 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1296 mempool_free(pmb
, phba
->mbox_mem_pool
);
1301 * This routine handles processing a REG_LOGIN mailbox
1302 * command upon completion. It is setup in the LPFC_MBOXQ
1303 * as the completion routine when the command is
1304 * handed off to the SLI layer.
1307 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1309 struct lpfc_vport
*vport
= pmb
->vport
;
1310 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1311 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1313 pmb
->context1
= NULL
;
1315 /* Good status, call state machine */
1316 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
1317 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1319 mempool_free(pmb
, phba
->mbox_mem_pool
);
1320 /* decrement the node reference count held for this callback
1329 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1331 MAILBOX_t
*mb
= &pmb
->mb
;
1332 struct lpfc_vport
*vport
= pmb
->vport
;
1333 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1335 switch (mb
->mbxStatus
) {
1339 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1340 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
1344 vport
->unreg_vpi_cmpl
= VPORT_OK
;
1345 mempool_free(pmb
, phba
->mbox_mem_pool
);
1347 * This shost reference might have been taken at the beginning of
1348 * lpfc_vport_delete()
1350 if (vport
->load_flag
& FC_UNLOADING
)
1351 scsi_host_put(shost
);
1355 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
1357 struct lpfc_hba
*phba
= vport
->phba
;
1361 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1365 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
1366 mbox
->vport
= vport
;
1367 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
1368 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1369 if (rc
== MBX_NOT_FINISHED
) {
1370 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1371 "1800 Could not issue unreg_vpi\n");
1372 mempool_free(mbox
, phba
->mbox_mem_pool
);
1373 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
1380 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1382 struct lpfc_vport
*vport
= pmb
->vport
;
1383 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1384 MAILBOX_t
*mb
= &pmb
->mb
;
1386 switch (mb
->mbxStatus
) {
1390 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1391 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
1393 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1394 spin_lock_irq(shost
->host_lock
);
1395 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
1396 spin_unlock_irq(shost
->host_lock
);
1397 vport
->fc_myDID
= 0;
1401 vport
->num_disc_nodes
= 0;
1402 /* go thru NPR list and issue ELS PLOGIs */
1403 if (vport
->fc_npr_cnt
)
1404 lpfc_els_disc_plogi(vport
);
1406 if (!vport
->num_disc_nodes
) {
1407 spin_lock_irq(shost
->host_lock
);
1408 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1409 spin_unlock_irq(shost
->host_lock
);
1410 lpfc_can_disctmo(vport
);
1412 vport
->port_state
= LPFC_VPORT_READY
;
1415 mempool_free(pmb
, phba
->mbox_mem_pool
);
1420 * This routine handles processing a Fabric REG_LOGIN mailbox
1421 * command upon completion. It is setup in the LPFC_MBOXQ
1422 * as the completion routine when the command is
1423 * handed off to the SLI layer.
1426 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1428 struct lpfc_vport
*vport
= pmb
->vport
;
1429 MAILBOX_t
*mb
= &pmb
->mb
;
1430 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1431 struct lpfc_nodelist
*ndlp
;
1432 struct lpfc_vport
**vports
;
1435 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1436 pmb
->context1
= NULL
;
1437 pmb
->context2
= NULL
;
1438 if (mb
->mbxStatus
) {
1439 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1441 mempool_free(pmb
, phba
->mbox_mem_pool
);
1443 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1444 /* FLOGI failed, use loop map to make discovery list */
1445 lpfc_disc_list_loopmap(vport
);
1447 /* Start discovery */
1448 lpfc_disc_start(vport
);
1449 /* Decrement the reference count to ndlp after the
1450 * reference to the ndlp are done.
1456 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1457 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1458 "0258 Register Fabric login error: 0x%x\n",
1460 /* Decrement the reference count to ndlp after the reference
1461 * to the ndlp are done.
1467 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1468 ndlp
->nlp_type
|= NLP_FABRIC
;
1469 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1471 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
1472 vports
= lpfc_create_vport_work_array(phba
);
1475 i
<= phba
->max_vpi
&& vports
[i
] != NULL
;
1477 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
1479 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1480 lpfc_vport_set_state(vports
[i
],
1484 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
1485 lpfc_initial_fdisc(vports
[i
]);
1487 lpfc_vport_set_state(vports
[i
],
1488 FC_VPORT_NO_FABRIC_SUPP
);
1489 lpfc_printf_vlog(vport
, KERN_ERR
,
1492 "Fabric support\n");
1495 lpfc_destroy_vport_work_array(phba
, vports
);
1496 lpfc_do_scr_ns_plogi(phba
, vport
);
1499 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1501 mempool_free(pmb
, phba
->mbox_mem_pool
);
1503 /* Drop the reference count from the mbox at the end after
1504 * all the current reference to the ndlp have been done.
1511 * This routine handles processing a NameServer REG_LOGIN mailbox
1512 * command upon completion. It is setup in the LPFC_MBOXQ
1513 * as the completion routine when the command is
1514 * handed off to the SLI layer.
1517 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1519 MAILBOX_t
*mb
= &pmb
->mb
;
1520 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1521 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1522 struct lpfc_vport
*vport
= pmb
->vport
;
1524 if (mb
->mbxStatus
) {
1526 /* decrement the node reference count held for this
1527 * callback function.
1530 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1532 mempool_free(pmb
, phba
->mbox_mem_pool
);
1534 /* If no other thread is using the ndlp, free it */
1535 lpfc_nlp_not_used(ndlp
);
1537 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1539 * RegLogin failed, use loop map to make discovery
1542 lpfc_disc_list_loopmap(vport
);
1544 /* Start discovery */
1545 lpfc_disc_start(vport
);
1548 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1549 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1550 "0260 Register NameServer error: 0x%x\n",
1555 pmb
->context1
= NULL
;
1557 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1558 ndlp
->nlp_type
|= NLP_FABRIC
;
1559 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1561 if (vport
->port_state
< LPFC_VPORT_READY
) {
1562 /* Link up discovery requires Fabric registration. */
1563 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, 0); /* Do this first! */
1564 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
1565 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
1566 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
1567 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
1569 /* Issue SCR just before NameServer GID_FT Query */
1570 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
1573 vport
->fc_ns_retry
= 0;
1574 /* Good status, issue CT Request to NameServer */
1575 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0)) {
1576 /* Cannot issue NameServer Query, so finish up discovery */
1580 /* decrement the node reference count held for this
1581 * callback function.
1584 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1586 mempool_free(pmb
, phba
->mbox_mem_pool
);
1592 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1594 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1595 struct fc_rport
*rport
;
1596 struct lpfc_rport_data
*rdata
;
1597 struct fc_rport_identifiers rport_ids
;
1598 struct lpfc_hba
*phba
= vport
->phba
;
1600 /* Remote port has reappeared. Re-register w/ FC transport */
1601 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
1602 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
1603 rport_ids
.port_id
= ndlp
->nlp_DID
;
1604 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
1607 * We leave our node pointer in rport->dd_data when we unregister a
1608 * FCP target port. But fc_remote_port_add zeros the space to which
1609 * rport->dd_data points. So, if we're reusing a previously
1610 * registered port, drop the reference that we took the last time we
1611 * registered the port.
1613 if (ndlp
->rport
&& ndlp
->rport
->dd_data
&&
1614 ((struct lpfc_rport_data
*) ndlp
->rport
->dd_data
)->pnode
== ndlp
)
1617 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
1618 "rport add: did:x%x flg:x%x type x%x",
1619 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
1621 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
1622 if (!rport
|| !get_device(&rport
->dev
)) {
1623 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
1624 "Warning: fc_remote_port_add failed\n");
1628 /* initialize static port data */
1629 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
1630 rport
->supported_classes
= ndlp
->nlp_class_sup
;
1631 rdata
= rport
->dd_data
;
1632 rdata
->pnode
= lpfc_nlp_get(ndlp
);
1634 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1635 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1636 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
1637 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1640 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
1641 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
1643 if ((rport
->scsi_target_id
!= -1) &&
1644 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
1645 ndlp
->nlp_sid
= rport
->scsi_target_id
;
1651 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
1653 struct fc_rport
*rport
= ndlp
->rport
;
1655 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
1656 "rport delete: did:x%x flg:x%x type x%x",
1657 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
1659 fc_remote_port_delete(rport
);
1665 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
1667 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1669 spin_lock_irq(shost
->host_lock
);
1671 case NLP_STE_UNUSED_NODE
:
1672 vport
->fc_unused_cnt
+= count
;
1674 case NLP_STE_PLOGI_ISSUE
:
1675 vport
->fc_plogi_cnt
+= count
;
1677 case NLP_STE_ADISC_ISSUE
:
1678 vport
->fc_adisc_cnt
+= count
;
1680 case NLP_STE_REG_LOGIN_ISSUE
:
1681 vport
->fc_reglogin_cnt
+= count
;
1683 case NLP_STE_PRLI_ISSUE
:
1684 vport
->fc_prli_cnt
+= count
;
1686 case NLP_STE_UNMAPPED_NODE
:
1687 vport
->fc_unmap_cnt
+= count
;
1689 case NLP_STE_MAPPED_NODE
:
1690 vport
->fc_map_cnt
+= count
;
1692 case NLP_STE_NPR_NODE
:
1693 vport
->fc_npr_cnt
+= count
;
1696 spin_unlock_irq(shost
->host_lock
);
1700 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1701 int old_state
, int new_state
)
1703 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1705 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
1706 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
1707 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
1708 ndlp
->nlp_type
|= NLP_FC_NODE
;
1710 if (new_state
== NLP_STE_MAPPED_NODE
)
1711 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
1712 if (new_state
== NLP_STE_NPR_NODE
)
1713 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
1715 /* Transport interface */
1716 if (ndlp
->rport
&& (old_state
== NLP_STE_MAPPED_NODE
||
1717 old_state
== NLP_STE_UNMAPPED_NODE
)) {
1718 vport
->phba
->nport_event_cnt
++;
1719 lpfc_unregister_remote_port(ndlp
);
1722 if (new_state
== NLP_STE_MAPPED_NODE
||
1723 new_state
== NLP_STE_UNMAPPED_NODE
) {
1724 vport
->phba
->nport_event_cnt
++;
1726 * Tell the fc transport about the port, if we haven't
1727 * already. If we have, and it's a scsi entity, be
1728 * sure to unblock any attached scsi devices
1730 lpfc_register_remote_port(vport
, ndlp
);
1732 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
1733 (vport
->stat_data_enabled
)) {
1735 * A new target is discovered, if there is no buffer for
1736 * statistical data collection allocate buffer.
1738 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
1739 sizeof(struct lpfc_scsicmd_bkt
),
1742 if (!ndlp
->lat_data
)
1743 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
1744 "0286 lpfc_nlp_state_cleanup failed to "
1745 "allocate statistical data buffer DID "
1746 "0x%x\n", ndlp
->nlp_DID
);
1749 * if we added to Mapped list, but the remote port
1750 * registration failed or assigned a target id outside
1751 * our presentable range - move the node to the
1754 if (new_state
== NLP_STE_MAPPED_NODE
&&
1756 ndlp
->rport
->scsi_target_id
== -1 ||
1757 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
1758 spin_lock_irq(shost
->host_lock
);
1759 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
1760 spin_unlock_irq(shost
->host_lock
);
1761 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1766 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
1768 static char *states
[] = {
1769 [NLP_STE_UNUSED_NODE
] = "UNUSED",
1770 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
1771 [NLP_STE_ADISC_ISSUE
] = "ADISC",
1772 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
1773 [NLP_STE_PRLI_ISSUE
] = "PRLI",
1774 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
1775 [NLP_STE_MAPPED_NODE
] = "MAPPED",
1776 [NLP_STE_NPR_NODE
] = "NPR",
1779 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
1780 strlcpy(buffer
, states
[state
], size
);
1782 snprintf(buffer
, size
, "unknown (%d)", state
);
1787 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1790 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1791 int old_state
= ndlp
->nlp_state
;
1792 char name1
[16], name2
[16];
1794 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1795 "0904 NPort state transition x%06x, %s -> %s\n",
1797 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
1798 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
1800 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
1801 "node statechg did:x%x old:%d ste:%d",
1802 ndlp
->nlp_DID
, old_state
, state
);
1804 if (old_state
== NLP_STE_NPR_NODE
&&
1805 state
!= NLP_STE_NPR_NODE
)
1806 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1807 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
1808 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
1809 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
1812 if (list_empty(&ndlp
->nlp_listp
)) {
1813 spin_lock_irq(shost
->host_lock
);
1814 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
1815 spin_unlock_irq(shost
->host_lock
);
1816 } else if (old_state
)
1817 lpfc_nlp_counters(vport
, old_state
, -1);
1819 ndlp
->nlp_state
= state
;
1820 lpfc_nlp_counters(vport
, state
, 1);
1821 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
1825 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1827 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1829 if (list_empty(&ndlp
->nlp_listp
)) {
1830 spin_lock_irq(shost
->host_lock
);
1831 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
1832 spin_unlock_irq(shost
->host_lock
);
1837 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1839 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1841 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1842 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
1843 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
1844 spin_lock_irq(shost
->host_lock
);
1845 list_del_init(&ndlp
->nlp_listp
);
1846 spin_unlock_irq(shost
->host_lock
);
1847 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
1848 NLP_STE_UNUSED_NODE
);
1852 lpfc_disable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1854 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1855 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
1856 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
1857 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
1858 NLP_STE_UNUSED_NODE
);
1861 * lpfc_initialize_node - Initialize all fields of node object
1862 * @vport: Pointer to Virtual Port object.
1863 * @ndlp: Pointer to FC node object.
1864 * @did: FC_ID of the node.
1866 * This function is always called when node object need to be initialized.
1867 * It initializes all the fields of the node object. Although the reference
1868 * to phba from @ndlp can be obtained indirectly through it's reference to
1869 * @vport, a direct reference to phba is taken here by @ndlp. This is due
1870 * to the life-span of the @ndlp might go beyond the existence of @vport as
1871 * the final release of ndlp is determined by its reference count. And, the
1872 * operation on @ndlp needs the reference to phba.
1875 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1878 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
1879 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
1880 init_timer(&ndlp
->nlp_delayfunc
);
1881 ndlp
->nlp_delayfunc
.function
= lpfc_els_retry_delay
;
1882 ndlp
->nlp_delayfunc
.data
= (unsigned long)ndlp
;
1883 ndlp
->nlp_DID
= did
;
1884 ndlp
->vport
= vport
;
1885 ndlp
->phba
= vport
->phba
;
1886 ndlp
->nlp_sid
= NLP_NO_SID
;
1887 kref_init(&ndlp
->kref
);
1888 NLP_INT_NODE_ACT(ndlp
);
1889 atomic_set(&ndlp
->cmd_pending
, 0);
1890 ndlp
->cmd_qdepth
= LPFC_MAX_TGT_QDEPTH
;
1893 struct lpfc_nodelist
*
1894 lpfc_enable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1897 struct lpfc_hba
*phba
= vport
->phba
;
1899 unsigned long flags
;
1904 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
1905 /* The ndlp should not be in memory free mode */
1906 if (NLP_CHK_FREE_REQ(ndlp
)) {
1907 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
1908 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
1909 "0277 lpfc_enable_node: ndlp:x%p "
1910 "usgmap:x%x refcnt:%d\n",
1911 (void *)ndlp
, ndlp
->nlp_usg_map
,
1912 atomic_read(&ndlp
->kref
.refcount
));
1915 /* The ndlp should not already be in active mode */
1916 if (NLP_CHK_NODE_ACT(ndlp
)) {
1917 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
1918 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
1919 "0278 lpfc_enable_node: ndlp:x%p "
1920 "usgmap:x%x refcnt:%d\n",
1921 (void *)ndlp
, ndlp
->nlp_usg_map
,
1922 atomic_read(&ndlp
->kref
.refcount
));
1926 /* Keep the original DID */
1927 did
= ndlp
->nlp_DID
;
1929 /* re-initialize ndlp except of ndlp linked list pointer */
1930 memset((((char *)ndlp
) + sizeof (struct list_head
)), 0,
1931 sizeof (struct lpfc_nodelist
) - sizeof (struct list_head
));
1932 lpfc_initialize_node(vport
, ndlp
, did
);
1934 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
1936 if (state
!= NLP_STE_UNUSED_NODE
)
1937 lpfc_nlp_set_state(vport
, ndlp
, state
);
1939 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
1940 "node enable: did:x%x",
1941 ndlp
->nlp_DID
, 0, 0);
1946 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1949 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
1950 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
1951 * the ndlp from the vport. The ndlp marked as UNUSED on the list
1952 * until ALL other outstanding threads have completed. We check
1953 * that the ndlp not already in the UNUSED state before we proceed.
1955 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
1957 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1963 * Start / ReStart rescue timer for Discovery / RSCN handling
1966 lpfc_set_disctmo(struct lpfc_vport
*vport
)
1968 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1969 struct lpfc_hba
*phba
= vport
->phba
;
1972 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
1973 /* For FAN, timeout should be greater than edtov */
1974 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
1976 /* Normal discovery timeout should be > than ELS/CT timeout
1977 * FC spec states we need 3 * ratov for CT requests
1979 tmo
= ((phba
->fc_ratov
* 3) + 3);
1983 if (!timer_pending(&vport
->fc_disctmo
)) {
1984 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1985 "set disc timer: tmo:x%x state:x%x flg:x%x",
1986 tmo
, vport
->port_state
, vport
->fc_flag
);
1989 mod_timer(&vport
->fc_disctmo
, jiffies
+ HZ
* tmo
);
1990 spin_lock_irq(shost
->host_lock
);
1991 vport
->fc_flag
|= FC_DISC_TMO
;
1992 spin_unlock_irq(shost
->host_lock
);
1994 /* Start Discovery Timer state <hba_state> */
1995 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1996 "0247 Start Discovery Timer state x%x "
1997 "Data: x%x x%lx x%x x%x\n",
1998 vport
->port_state
, tmo
,
1999 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
2000 vport
->fc_adisc_cnt
);
2006 * Cancel rescue timer for Discovery / RSCN handling
2009 lpfc_can_disctmo(struct lpfc_vport
*vport
)
2011 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2012 unsigned long iflags
;
2014 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2015 "can disc timer: state:x%x rtry:x%x flg:x%x",
2016 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
2018 /* Turn off discovery timer if its running */
2019 if (vport
->fc_flag
& FC_DISC_TMO
) {
2020 spin_lock_irqsave(shost
->host_lock
, iflags
);
2021 vport
->fc_flag
&= ~FC_DISC_TMO
;
2022 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
2023 del_timer_sync(&vport
->fc_disctmo
);
2024 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
2025 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
2026 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
2029 /* Cancel Discovery Timer state <hba_state> */
2030 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2031 "0248 Cancel Discovery Timer state x%x "
2032 "Data: x%x x%x x%x\n",
2033 vport
->port_state
, vport
->fc_flag
,
2034 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
2039 * Check specified ring for outstanding IOCB on the SLI queue
2040 * Return true if iocb matches the specified nport
2043 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
2044 struct lpfc_sli_ring
*pring
,
2045 struct lpfc_iocbq
*iocb
,
2046 struct lpfc_nodelist
*ndlp
)
2048 struct lpfc_sli
*psli
= &phba
->sli
;
2049 IOCB_t
*icmd
= &iocb
->iocb
;
2050 struct lpfc_vport
*vport
= ndlp
->vport
;
2052 if (iocb
->vport
!= vport
)
2055 if (pring
->ringno
== LPFC_ELS_RING
) {
2056 switch (icmd
->ulpCommand
) {
2057 case CMD_GEN_REQUEST64_CR
:
2058 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
)
2060 case CMD_ELS_REQUEST64_CR
:
2061 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
2063 case CMD_XMIT_ELS_RSP64_CX
:
2064 if (iocb
->context1
== (uint8_t *) ndlp
)
2067 } else if (pring
->ringno
== psli
->extra_ring
) {
2069 } else if (pring
->ringno
== psli
->fcp_ring
) {
2070 /* Skip match check if waiting to relogin to FCP target */
2071 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
2072 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2075 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
2078 } else if (pring
->ringno
== psli
->next_ring
) {
2085 * Free resources / clean up outstanding I/Os
2086 * associated with nlp_rpi in the LPFC_NODELIST entry.
2089 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
2091 LIST_HEAD(completions
);
2092 struct lpfc_sli
*psli
;
2093 struct lpfc_sli_ring
*pring
;
2094 struct lpfc_iocbq
*iocb
, *next_iocb
;
2097 lpfc_fabric_abort_nport(ndlp
);
2100 * Everything that matches on txcmplq will be returned
2101 * by firmware with a no rpi error.
2104 rpi
= ndlp
->nlp_rpi
;
2106 /* Now process each ring */
2107 for (i
= 0; i
< psli
->num_rings
; i
++) {
2108 pring
= &psli
->ring
[i
];
2110 spin_lock_irq(&phba
->hbalock
);
2111 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
,
2114 * Check to see if iocb matches the nport we are
2117 if ((lpfc_check_sli_ndlp(phba
, pring
, iocb
,
2119 /* It matches, so deque and call compl
2121 list_move_tail(&iocb
->list
,
2126 spin_unlock_irq(&phba
->hbalock
);
2130 /* Cancel all the IOCBs from the completions list */
2131 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
2138 * Free rpi associated with LPFC_NODELIST entry.
2139 * This routine is called from lpfc_freenode(), when we are removing
2140 * a LPFC_NODELIST entry. It is also called if the driver initiates a
2141 * LOGO that completes successfully, and we are waiting to PLOGI back
2142 * to the remote NPort. In addition, it is called after we receive
2143 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
2144 * we are waiting to PLOGI back to the remote NPort.
2147 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2149 struct lpfc_hba
*phba
= vport
->phba
;
2153 if (ndlp
->nlp_rpi
) {
2154 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2156 lpfc_unreg_login(phba
, vport
->vpi
, ndlp
->nlp_rpi
, mbox
);
2157 mbox
->vport
= vport
;
2158 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2159 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2160 if (rc
== MBX_NOT_FINISHED
)
2161 mempool_free(mbox
, phba
->mbox_mem_pool
);
2163 lpfc_no_rpi(phba
, ndlp
);
2171 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
2173 struct lpfc_hba
*phba
= vport
->phba
;
2177 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2179 lpfc_unreg_login(phba
, vport
->vpi
, 0xffff, mbox
);
2180 mbox
->vport
= vport
;
2181 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2182 mbox
->context1
= NULL
;
2183 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2184 if (rc
!= MBX_TIMEOUT
)
2185 mempool_free(mbox
, phba
->mbox_mem_pool
);
2187 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
2188 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
2189 "1836 Could not issue "
2190 "unreg_login(all_rpis) status %d\n", rc
);
2195 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
2197 struct lpfc_hba
*phba
= vport
->phba
;
2201 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2203 lpfc_unreg_did(phba
, vport
->vpi
, 0xffffffff, mbox
);
2204 mbox
->vport
= vport
;
2205 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2206 mbox
->context1
= NULL
;
2207 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
2208 if (rc
!= MBX_TIMEOUT
)
2209 mempool_free(mbox
, phba
->mbox_mem_pool
);
2211 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
2212 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
2213 "1815 Could not issue "
2214 "unreg_did (default rpis) status %d\n",
2220 * Free resources associated with LPFC_NODELIST entry
2221 * so it can be freed.
2224 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2226 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2227 struct lpfc_hba
*phba
= vport
->phba
;
2228 LPFC_MBOXQ_t
*mb
, *nextmb
;
2229 struct lpfc_dmabuf
*mp
;
2231 /* Cleanup node for NPort <nlp_DID> */
2232 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2233 "0900 Cleanup node for NPort x%x "
2234 "Data: x%x x%x x%x\n",
2235 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
2236 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2237 if (NLP_CHK_FREE_REQ(ndlp
)) {
2238 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2239 "0280 lpfc_cleanup_node: ndlp:x%p "
2240 "usgmap:x%x refcnt:%d\n",
2241 (void *)ndlp
, ndlp
->nlp_usg_map
,
2242 atomic_read(&ndlp
->kref
.refcount
));
2243 lpfc_dequeue_node(vport
, ndlp
);
2245 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2246 "0281 lpfc_cleanup_node: ndlp:x%p "
2247 "usgmap:x%x refcnt:%d\n",
2248 (void *)ndlp
, ndlp
->nlp_usg_map
,
2249 atomic_read(&ndlp
->kref
.refcount
));
2250 lpfc_disable_node(vport
, ndlp
);
2253 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
2254 if ((mb
= phba
->sli
.mbox_active
)) {
2255 if ((mb
->mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
2256 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
2257 mb
->context2
= NULL
;
2258 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2262 spin_lock_irq(&phba
->hbalock
);
2263 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
2264 if ((mb
->mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
2265 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
2266 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
2268 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2271 list_del(&mb
->list
);
2272 mempool_free(mb
, phba
->mbox_mem_pool
);
2273 /* We shall not invoke the lpfc_nlp_put to decrement
2274 * the ndlp reference count as we are in the process
2275 * of lpfc_nlp_release.
2279 spin_unlock_irq(&phba
->hbalock
);
2281 lpfc_els_abort(phba
, ndlp
);
2283 spin_lock_irq(shost
->host_lock
);
2284 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2285 spin_unlock_irq(shost
->host_lock
);
2287 ndlp
->nlp_last_elscmd
= 0;
2288 del_timer_sync(&ndlp
->nlp_delayfunc
);
2290 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
2291 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
2293 lpfc_unreg_rpi(vport
, ndlp
);
2299 * Check to see if we can free the nlp back to the freelist.
2300 * If we are in the middle of using the nlp in the discovery state
2301 * machine, defer the free till we reach the end of the state machine.
2304 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2306 struct lpfc_hba
*phba
= vport
->phba
;
2307 struct lpfc_rport_data
*rdata
;
2311 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2312 if (ndlp
->nlp_flag
& NLP_DEFER_RM
&& !ndlp
->nlp_rpi
) {
2313 /* For this case we need to cleanup the default rpi
2314 * allocated by the firmware.
2316 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
))
2318 rc
= lpfc_reg_login(phba
, vport
->vpi
, ndlp
->nlp_DID
,
2319 (uint8_t *) &vport
->fc_sparam
, mbox
, 0);
2321 mempool_free(mbox
, phba
->mbox_mem_pool
);
2324 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
2325 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
2326 mbox
->vport
= vport
;
2327 mbox
->context2
= NULL
;
2328 rc
=lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2329 if (rc
== MBX_NOT_FINISHED
) {
2330 mempool_free(mbox
, phba
->mbox_mem_pool
);
2335 lpfc_cleanup_node(vport
, ndlp
);
2338 * We can get here with a non-NULL ndlp->rport because when we
2339 * unregister a rport we don't break the rport/node linkage. So if we
2340 * do, make sure we don't leaving any dangling pointers behind.
2343 rdata
= ndlp
->rport
->dd_data
;
2344 rdata
->pnode
= NULL
;
2350 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2353 D_ID mydid
, ndlpdid
, matchdid
;
2355 if (did
== Bcast_DID
)
2358 /* First check for Direct match */
2359 if (ndlp
->nlp_DID
== did
)
2362 /* Next check for area/domain identically equals 0 match */
2363 mydid
.un
.word
= vport
->fc_myDID
;
2364 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
2368 matchdid
.un
.word
= did
;
2369 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
2370 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
2371 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
2372 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
2373 if ((ndlpdid
.un
.b
.domain
== 0) &&
2374 (ndlpdid
.un
.b
.area
== 0)) {
2375 if (ndlpdid
.un
.b
.id
)
2381 matchdid
.un
.word
= ndlp
->nlp_DID
;
2382 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
2383 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
2384 if ((matchdid
.un
.b
.domain
== 0) &&
2385 (matchdid
.un
.b
.area
== 0)) {
2386 if (matchdid
.un
.b
.id
)
2394 /* Search for a nodelist entry */
2395 static struct lpfc_nodelist
*
2396 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
2398 struct lpfc_nodelist
*ndlp
;
2401 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2402 if (lpfc_matchdid(vport
, ndlp
, did
)) {
2403 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
2404 ((uint32_t) ndlp
->nlp_xri
<< 16) |
2405 ((uint32_t) ndlp
->nlp_type
<< 8) |
2406 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
2407 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2408 "0929 FIND node DID "
2409 "Data: x%p x%x x%x x%x\n",
2410 ndlp
, ndlp
->nlp_DID
,
2411 ndlp
->nlp_flag
, data1
);
2416 /* FIND node did <did> NOT FOUND */
2417 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2418 "0932 FIND node did x%x NOT FOUND.\n", did
);
2422 struct lpfc_nodelist
*
2423 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
2425 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2426 struct lpfc_nodelist
*ndlp
;
2428 spin_lock_irq(shost
->host_lock
);
2429 ndlp
= __lpfc_findnode_did(vport
, did
);
2430 spin_unlock_irq(shost
->host_lock
);
2434 struct lpfc_nodelist
*
2435 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
2437 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2438 struct lpfc_nodelist
*ndlp
;
2440 ndlp
= lpfc_findnode_did(vport
, did
);
2442 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
2443 lpfc_rscn_payload_check(vport
, did
) == 0)
2445 ndlp
= (struct lpfc_nodelist
*)
2446 mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
2449 lpfc_nlp_init(vport
, ndlp
, did
);
2450 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2451 spin_lock_irq(shost
->host_lock
);
2452 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2453 spin_unlock_irq(shost
->host_lock
);
2455 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2456 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
2459 spin_lock_irq(shost
->host_lock
);
2460 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2461 spin_unlock_irq(shost
->host_lock
);
2465 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
2466 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
2467 if (lpfc_rscn_payload_check(vport
, did
)) {
2468 /* If we've already recieved a PLOGI from this NPort
2469 * we don't need to try to discover it again.
2471 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
2474 /* Since this node is marked for discovery,
2475 * delay timeout is not needed.
2477 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2478 spin_lock_irq(shost
->host_lock
);
2479 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2480 spin_unlock_irq(shost
->host_lock
);
2484 /* If we've already recieved a PLOGI from this NPort,
2485 * or we are already in the process of discovery on it,
2486 * we don't need to try to discover it again.
2488 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
2489 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
2490 ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
2492 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2493 spin_lock_irq(shost
->host_lock
);
2494 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2495 spin_unlock_irq(shost
->host_lock
);
2500 /* Build a list of nodes to discover based on the loopmap */
2502 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
2504 struct lpfc_hba
*phba
= vport
->phba
;
2506 uint32_t alpa
, index
;
2508 if (!lpfc_is_link_up(phba
))
2511 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
2514 /* Check for loop map present or not */
2515 if (phba
->alpa_map
[0]) {
2516 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
2517 alpa
= phba
->alpa_map
[j
];
2518 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
2520 lpfc_setup_disc_node(vport
, alpa
);
2523 /* No alpamap, so try all alpa's */
2524 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
2525 /* If cfg_scan_down is set, start from highest
2526 * ALPA (0xef) to lowest (0x1).
2528 if (vport
->cfg_scan_down
)
2531 index
= FC_MAXLOOP
- j
- 1;
2532 alpa
= lpfcAlpaArray
[index
];
2533 if ((vport
->fc_myDID
& 0xff) == alpa
)
2535 lpfc_setup_disc_node(vport
, alpa
);
2542 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
2545 struct lpfc_sli
*psli
= &phba
->sli
;
2546 struct lpfc_sli_ring
*extra_ring
= &psli
->ring
[psli
->extra_ring
];
2547 struct lpfc_sli_ring
*fcp_ring
= &psli
->ring
[psli
->fcp_ring
];
2548 struct lpfc_sli_ring
*next_ring
= &psli
->ring
[psli
->next_ring
];
2552 * if it's not a physical port or if we already send
2553 * clear_la then don't send it.
2555 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
2556 (vport
->port_type
!= LPFC_PHYSICAL_PORT
))
2559 /* Link up discovery */
2560 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
2561 phba
->link_state
= LPFC_CLEAR_LA
;
2562 lpfc_clear_la(phba
, mbox
);
2563 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
2564 mbox
->vport
= vport
;
2565 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2566 if (rc
== MBX_NOT_FINISHED
) {
2567 mempool_free(mbox
, phba
->mbox_mem_pool
);
2568 lpfc_disc_flush_list(vport
);
2569 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2570 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2571 next_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2572 phba
->link_state
= LPFC_HBA_ERROR
;
2577 /* Reg_vpi to tell firmware to resume normal operations */
2579 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
2581 LPFC_MBOXQ_t
*regvpimbox
;
2583 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2585 lpfc_reg_vpi(phba
, vport
->vpi
, vport
->fc_myDID
, regvpimbox
);
2586 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
2587 regvpimbox
->vport
= vport
;
2588 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
2589 == MBX_NOT_FINISHED
) {
2590 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
2595 /* Start Link up / RSCN discovery on NPR nodes */
2597 lpfc_disc_start(struct lpfc_vport
*vport
)
2599 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2600 struct lpfc_hba
*phba
= vport
->phba
;
2602 uint32_t clear_la_pending
;
2605 if (!lpfc_is_link_up(phba
))
2608 if (phba
->link_state
== LPFC_CLEAR_LA
)
2609 clear_la_pending
= 1;
2611 clear_la_pending
= 0;
2613 if (vport
->port_state
< LPFC_VPORT_READY
)
2614 vport
->port_state
= LPFC_DISC_AUTH
;
2616 lpfc_set_disctmo(vport
);
2618 if (vport
->fc_prevDID
== vport
->fc_myDID
)
2623 vport
->fc_prevDID
= vport
->fc_myDID
;
2624 vport
->num_disc_nodes
= 0;
2626 /* Start Discovery state <hba_state> */
2627 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2628 "0202 Start Discovery hba state x%x "
2629 "Data: x%x x%x x%x\n",
2630 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
2631 vport
->fc_adisc_cnt
);
2633 /* First do ADISCs - if any */
2634 num_sent
= lpfc_els_disc_adisc(vport
);
2640 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
2641 * continue discovery.
2643 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2644 !(vport
->fc_flag
& FC_PT2PT
) &&
2645 !(vport
->fc_flag
& FC_RSCN_MODE
)) {
2646 lpfc_issue_reg_vpi(phba
, vport
);
2651 * For SLI2, we need to set port_state to READY and continue
2654 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
2655 /* If we get here, there is nothing to ADISC */
2656 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
2657 lpfc_issue_clear_la(phba
, vport
);
2659 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
2660 vport
->num_disc_nodes
= 0;
2661 /* go thru NPR nodes and issue ELS PLOGIs */
2662 if (vport
->fc_npr_cnt
)
2663 lpfc_els_disc_plogi(vport
);
2665 if (!vport
->num_disc_nodes
) {
2666 spin_lock_irq(shost
->host_lock
);
2667 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2668 spin_unlock_irq(shost
->host_lock
);
2669 lpfc_can_disctmo(vport
);
2672 vport
->port_state
= LPFC_VPORT_READY
;
2674 /* Next do PLOGIs - if any */
2675 num_sent
= lpfc_els_disc_plogi(vport
);
2680 if (vport
->fc_flag
& FC_RSCN_MODE
) {
2681 /* Check to see if more RSCNs came in while we
2682 * were processing this one.
2684 if ((vport
->fc_rscn_id_cnt
== 0) &&
2685 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
2686 spin_lock_irq(shost
->host_lock
);
2687 vport
->fc_flag
&= ~FC_RSCN_MODE
;
2688 spin_unlock_irq(shost
->host_lock
);
2689 lpfc_can_disctmo(vport
);
2691 lpfc_els_handle_rscn(vport
);
2698 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2699 * ring the match the sppecified nodelist.
2702 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
2704 LIST_HEAD(completions
);
2705 struct lpfc_sli
*psli
;
2707 struct lpfc_iocbq
*iocb
, *next_iocb
;
2708 struct lpfc_sli_ring
*pring
;
2711 pring
= &psli
->ring
[LPFC_ELS_RING
];
2713 /* Error matching iocb on txq or txcmplq
2714 * First check the txq.
2716 spin_lock_irq(&phba
->hbalock
);
2717 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
2718 if (iocb
->context1
!= ndlp
) {
2722 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
2723 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
2725 list_move_tail(&iocb
->list
, &completions
);
2730 /* Next check the txcmplq */
2731 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
2732 if (iocb
->context1
!= ndlp
) {
2736 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
2737 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
2738 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
2741 spin_unlock_irq(&phba
->hbalock
);
2743 /* Cancel all the IOCBs from the completions list */
2744 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
2749 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
2751 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2752 struct lpfc_hba
*phba
= vport
->phba
;
2754 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
2755 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
2757 if (!NLP_CHK_NODE_ACT(ndlp
))
2759 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
2760 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
2761 lpfc_free_tx(phba
, ndlp
);
2768 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
2770 lpfc_els_flush_rscn(vport
);
2771 lpfc_els_flush_cmd(vport
);
2772 lpfc_disc_flush_list(vport
);
2775 /*****************************************************************************/
2777 * NAME: lpfc_disc_timeout
2779 * FUNCTION: Fibre Channel driver discovery timeout routine.
2781 * EXECUTION ENVIRONMENT: interrupt only
2789 /*****************************************************************************/
2791 lpfc_disc_timeout(unsigned long ptr
)
2793 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
2794 struct lpfc_hba
*phba
= vport
->phba
;
2795 uint32_t tmo_posted
;
2796 unsigned long flags
= 0;
2798 if (unlikely(!phba
))
2801 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
2802 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
2804 vport
->work_port_events
|= WORKER_DISC_TMO
;
2805 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
2808 lpfc_worker_wake_up(phba
);
2813 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
2815 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2816 struct lpfc_hba
*phba
= vport
->phba
;
2817 struct lpfc_sli
*psli
= &phba
->sli
;
2818 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2819 LPFC_MBOXQ_t
*initlinkmbox
;
2820 int rc
, clrlaerr
= 0;
2822 if (!(vport
->fc_flag
& FC_DISC_TMO
))
2825 spin_lock_irq(shost
->host_lock
);
2826 vport
->fc_flag
&= ~FC_DISC_TMO
;
2827 spin_unlock_irq(shost
->host_lock
);
2829 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2830 "disc timeout: state:x%x rtry:x%x flg:x%x",
2831 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
2833 switch (vport
->port_state
) {
2835 case LPFC_LOCAL_CFG_LINK
:
2836 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2840 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
2841 "0221 FAN timeout\n");
2842 /* Start discovery by sending FLOGI, clean up old rpis */
2843 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
2845 if (!NLP_CHK_NODE_ACT(ndlp
))
2847 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
2849 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2850 /* Clean up the ndlp on Fabric connections */
2851 lpfc_drop_node(vport
, ndlp
);
2853 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
2854 /* Fail outstanding IO now since device
2855 * is marked for PLOGI.
2857 lpfc_unreg_rpi(vport
, ndlp
);
2860 if (vport
->port_state
!= LPFC_FLOGI
) {
2861 lpfc_initial_flogi(vport
);
2868 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2869 /* Initial FLOGI timeout */
2870 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2871 "0222 Initial %s timeout\n",
2872 vport
->vpi
? "FDISC" : "FLOGI");
2874 /* Assume no Fabric and go on with discovery.
2875 * Check for outstanding ELS FLOGI to abort.
2878 /* FLOGI failed, so just use loop map to make discovery list */
2879 lpfc_disc_list_loopmap(vport
);
2881 /* Start discovery */
2882 lpfc_disc_start(vport
);
2885 case LPFC_FABRIC_CFG_LINK
:
2886 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2888 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2889 "0223 Timeout while waiting for "
2890 "NameServer login\n");
2891 /* Next look for NameServer ndlp */
2892 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
2893 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
2894 lpfc_els_abort(phba
, ndlp
);
2896 /* ReStart discovery */
2900 /* Check for wait for NameServer Rsp timeout */
2901 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2902 "0224 NameServer Query timeout "
2904 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
2906 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
2907 /* Try it one more time */
2908 vport
->fc_ns_retry
++;
2909 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
,
2910 vport
->fc_ns_retry
, 0);
2914 vport
->fc_ns_retry
= 0;
2918 * Discovery is over.
2919 * set port_state to PORT_READY if SLI2.
2920 * cmpl_reg_vpi will set port_state to READY for SLI3.
2922 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2923 lpfc_issue_reg_vpi(phba
, vport
);
2924 else { /* NPIV Not enabled */
2925 lpfc_issue_clear_la(phba
, vport
);
2926 vport
->port_state
= LPFC_VPORT_READY
;
2929 /* Setup and issue mailbox INITIALIZE LINK command */
2930 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2931 if (!initlinkmbox
) {
2932 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2933 "0206 Device Discovery "
2934 "completion error\n");
2935 phba
->link_state
= LPFC_HBA_ERROR
;
2939 lpfc_linkdown(phba
);
2940 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
2941 phba
->cfg_link_speed
);
2942 initlinkmbox
->mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
2943 initlinkmbox
->vport
= vport
;
2944 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2945 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
2946 lpfc_set_loopback_flag(phba
);
2947 if (rc
== MBX_NOT_FINISHED
)
2948 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
2952 case LPFC_DISC_AUTH
:
2953 /* Node Authentication timeout */
2954 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2955 "0227 Node Authentication timeout\n");
2956 lpfc_disc_flush_list(vport
);
2959 * set port_state to PORT_READY if SLI2.
2960 * cmpl_reg_vpi will set port_state to READY for SLI3.
2962 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2963 lpfc_issue_reg_vpi(phba
, vport
);
2964 else { /* NPIV Not enabled */
2965 lpfc_issue_clear_la(phba
, vport
);
2966 vport
->port_state
= LPFC_VPORT_READY
;
2970 case LPFC_VPORT_READY
:
2971 if (vport
->fc_flag
& FC_RSCN_MODE
) {
2972 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2973 "0231 RSCN timeout Data: x%x "
2975 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
2977 /* Cleanup any outstanding ELS commands */
2978 lpfc_els_flush_cmd(vport
);
2980 lpfc_els_flush_rscn(vport
);
2981 lpfc_disc_flush_list(vport
);
2986 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2987 "0273 Unexpected discovery timeout, "
2988 "vport State x%x\n", vport
->port_state
);
2992 switch (phba
->link_state
) {
2994 /* CLEAR LA timeout */
2995 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2996 "0228 CLEAR LA timeout\n");
3001 lpfc_issue_clear_la(phba
, vport
);
3003 case LPFC_LINK_UNKNOWN
:
3004 case LPFC_WARM_START
:
3005 case LPFC_INIT_START
:
3006 case LPFC_INIT_MBX_CMDS
:
3007 case LPFC_LINK_DOWN
:
3008 case LPFC_HBA_ERROR
:
3009 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3010 "0230 Unexpected timeout, hba link "
3011 "state x%x\n", phba
->link_state
);
3015 case LPFC_HBA_READY
:
3020 lpfc_disc_flush_list(vport
);
3021 psli
->ring
[(psli
->extra_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
3022 psli
->ring
[(psli
->fcp_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
3023 psli
->ring
[(psli
->next_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
3024 vport
->port_state
= LPFC_VPORT_READY
;
3031 * This routine handles processing a NameServer REG_LOGIN mailbox
3032 * command upon completion. It is setup in the LPFC_MBOXQ
3033 * as the completion routine when the command is
3034 * handed off to the SLI layer.
3037 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3039 MAILBOX_t
*mb
= &pmb
->mb
;
3040 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3041 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3042 struct lpfc_vport
*vport
= pmb
->vport
;
3044 pmb
->context1
= NULL
;
3046 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3047 ndlp
->nlp_type
|= NLP_FABRIC
;
3048 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3051 * Start issuing Fabric-Device Management Interface (FDMI) command to
3052 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
3053 * fdmi-on=2 (supporting RPA/hostnmae)
3056 if (vport
->cfg_fdmi_on
== 1)
3057 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
);
3059 mod_timer(&vport
->fc_fdmitmo
, jiffies
+ HZ
* 60);
3061 /* decrement the node reference count held for this callback
3065 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3067 mempool_free(pmb
, phba
->mbox_mem_pool
);
3073 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
3075 uint16_t *rpi
= param
;
3077 return ndlp
->nlp_rpi
== *rpi
;
3081 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
3083 return memcmp(&ndlp
->nlp_portname
, param
,
3084 sizeof(ndlp
->nlp_portname
)) == 0;
3087 static struct lpfc_nodelist
*
3088 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
3090 struct lpfc_nodelist
*ndlp
;
3092 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3093 if (filter(ndlp
, param
))
3100 * This routine looks up the ndlp lists for the given RPI. If rpi found it
3101 * returns the node list element pointer else return NULL.
3103 struct lpfc_nodelist
*
3104 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
3106 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
3110 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
3111 * returns the node element list pointer else return NULL.
3113 struct lpfc_nodelist
*
3114 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
3116 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3117 struct lpfc_nodelist
*ndlp
;
3119 spin_lock_irq(shost
->host_lock
);
3120 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
3121 spin_unlock_irq(shost
->host_lock
);
3126 lpfc_nlp_init(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3129 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
3131 lpfc_initialize_node(vport
, ndlp
, did
);
3132 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
3134 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
3135 "node init: did:x%x",
3136 ndlp
->nlp_DID
, 0, 0);
3141 /* This routine releases all resources associated with a specifc NPort's ndlp
3142 * and mempool_free's the nodelist.
3145 lpfc_nlp_release(struct kref
*kref
)
3147 struct lpfc_hba
*phba
;
3148 unsigned long flags
;
3149 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
3152 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
3153 "node release: did:x%x flg:x%x type:x%x",
3154 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
3156 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
3157 "0279 lpfc_nlp_release: ndlp:x%p "
3158 "usgmap:x%x refcnt:%d\n",
3159 (void *)ndlp
, ndlp
->nlp_usg_map
,
3160 atomic_read(&ndlp
->kref
.refcount
));
3162 /* remove ndlp from action. */
3163 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
3165 /* clear the ndlp active flag for all release cases */
3167 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3168 NLP_CLR_NODE_ACT(ndlp
);
3169 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3171 /* free ndlp memory for final ndlp release */
3172 if (NLP_CHK_FREE_REQ(ndlp
)) {
3173 kfree(ndlp
->lat_data
);
3174 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
3178 /* This routine bumps the reference count for a ndlp structure to ensure
3179 * that one discovery thread won't free a ndlp while another discovery thread
3182 struct lpfc_nodelist
*
3183 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
3185 struct lpfc_hba
*phba
;
3186 unsigned long flags
;
3189 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
3190 "node get: did:x%x flg:x%x refcnt:x%x",
3191 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3192 atomic_read(&ndlp
->kref
.refcount
));
3193 /* The check of ndlp usage to prevent incrementing the
3194 * ndlp reference count that is in the process of being
3198 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3199 if (!NLP_CHK_NODE_ACT(ndlp
) || NLP_CHK_FREE_ACK(ndlp
)) {
3200 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3201 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
3202 "0276 lpfc_nlp_get: ndlp:x%p "
3203 "usgmap:x%x refcnt:%d\n",
3204 (void *)ndlp
, ndlp
->nlp_usg_map
,
3205 atomic_read(&ndlp
->kref
.refcount
));
3208 kref_get(&ndlp
->kref
);
3209 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3214 /* This routine decrements the reference count for a ndlp structure. If the
3215 * count goes to 0, this indicates the the associated nodelist should be
3216 * freed. Returning 1 indicates the ndlp resource has been released; on the
3217 * other hand, returning 0 indicates the ndlp resource has not been released
3221 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
3223 struct lpfc_hba
*phba
;
3224 unsigned long flags
;
3229 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
3230 "node put: did:x%x flg:x%x refcnt:x%x",
3231 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3232 atomic_read(&ndlp
->kref
.refcount
));
3234 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3235 /* Check the ndlp memory free acknowledge flag to avoid the
3236 * possible race condition that kref_put got invoked again
3237 * after previous one has done ndlp memory free.
3239 if (NLP_CHK_FREE_ACK(ndlp
)) {
3240 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3241 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
3242 "0274 lpfc_nlp_put: ndlp:x%p "
3243 "usgmap:x%x refcnt:%d\n",
3244 (void *)ndlp
, ndlp
->nlp_usg_map
,
3245 atomic_read(&ndlp
->kref
.refcount
));
3248 /* Check the ndlp inactivate log flag to avoid the possible
3249 * race condition that kref_put got invoked again after ndlp
3250 * is already in inactivating state.
3252 if (NLP_CHK_IACT_REQ(ndlp
)) {
3253 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3254 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
3255 "0275 lpfc_nlp_put: ndlp:x%p "
3256 "usgmap:x%x refcnt:%d\n",
3257 (void *)ndlp
, ndlp
->nlp_usg_map
,
3258 atomic_read(&ndlp
->kref
.refcount
));
3261 /* For last put, mark the ndlp usage flags to make sure no
3262 * other kref_get and kref_put on the same ndlp shall get
3263 * in between the process when the final kref_put has been
3264 * invoked on this ndlp.
3266 if (atomic_read(&ndlp
->kref
.refcount
) == 1) {
3267 /* Indicate ndlp is put to inactive state. */
3268 NLP_SET_IACT_REQ(ndlp
);
3269 /* Acknowledge ndlp memory free has been seen. */
3270 if (NLP_CHK_FREE_REQ(ndlp
))
3271 NLP_SET_FREE_ACK(ndlp
);
3273 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3274 /* Note, the kref_put returns 1 when decrementing a reference
3275 * count that was 1, it invokes the release callback function,
3276 * but it still left the reference count as 1 (not actually
3277 * performs the last decrementation). Otherwise, it actually
3278 * decrements the reference count and returns 0.
3280 return kref_put(&ndlp
->kref
, lpfc_nlp_release
);
3283 /* This routine free's the specified nodelist if it is not in use
3284 * by any other discovery thread. This routine returns 1 if the
3285 * ndlp has been freed. A return value of 0 indicates the ndlp is
3286 * not yet been released.
3289 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
3291 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
3292 "node not used: did:x%x flg:x%x refcnt:x%x",
3293 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3294 atomic_read(&ndlp
->kref
.refcount
));
3295 if (atomic_read(&ndlp
->kref
.refcount
) == 1)
3296 if (lpfc_nlp_put(ndlp
))