1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 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/slab.h>
24 #include <linux/pci.h>
25 #include <linux/kthread.h>
26 #include <linux/interrupt.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_host.h>
31 #include <scsi/scsi_transport_fc.h>
36 #include "lpfc_disc.h"
38 #include "lpfc_sli4.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_vport.h"
44 #include "lpfc_debugfs.h"
46 /* AlpaArray for assignment of scsid for scan-down and bind_method */
47 static uint8_t lpfcAlpaArray
[] = {
48 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
49 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
50 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
51 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
52 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
53 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
54 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
55 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
56 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
57 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
58 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
59 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
60 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
63 static void lpfc_disc_timeout_handler(struct lpfc_vport
*);
64 static void lpfc_disc_flush_list(struct lpfc_vport
*vport
);
65 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*, LPFC_MBOXQ_t
*);
68 lpfc_terminate_rport_io(struct fc_rport
*rport
)
70 struct lpfc_rport_data
*rdata
;
71 struct lpfc_nodelist
* ndlp
;
72 struct lpfc_hba
*phba
;
74 rdata
= rport
->dd_data
;
77 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
78 if (rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)
79 printk(KERN_ERR
"Cannot find remote node"
80 " to terminate I/O Data x%x\n",
87 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
88 "rport terminate: sid:x%x did:x%x flg:x%x",
89 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
91 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
92 lpfc_sli_abort_iocb(ndlp
->vport
,
93 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
94 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
99 * This function will be called when dev_loss_tmo fire.
102 lpfc_dev_loss_tmo_callbk(struct fc_rport
*rport
)
104 struct lpfc_rport_data
*rdata
;
105 struct lpfc_nodelist
* ndlp
;
106 struct lpfc_vport
*vport
;
107 struct lpfc_hba
*phba
;
108 struct lpfc_work_evt
*evtp
;
112 rdata
= rport
->dd_data
;
114 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
120 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
121 "rport devlosscb: sid:x%x did:x%x flg:x%x",
122 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
124 /* Don't defer this if we are in the process of deleting the vport
125 * or unloading the driver. The unload will cleanup the node
126 * appropriately we just need to cleanup the ndlp rport info here.
128 if (vport
->load_flag
& FC_UNLOADING
) {
129 put_node
= rdata
->pnode
!= NULL
;
130 put_rport
= ndlp
->rport
!= NULL
;
136 put_device(&rport
->dev
);
140 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)
143 evtp
= &ndlp
->dev_loss_evt
;
145 if (!list_empty(&evtp
->evt_listp
))
148 spin_lock_irq(&phba
->hbalock
);
149 /* We need to hold the node by incrementing the reference
150 * count until this queued work is done
152 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
153 if (evtp
->evt_arg1
) {
154 evtp
->evt
= LPFC_EVT_DEV_LOSS
;
155 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
156 lpfc_worker_wake_up(phba
);
158 spin_unlock_irq(&phba
->hbalock
);
164 * This function is called from the worker thread when dev_loss_tmo
168 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist
*ndlp
)
170 struct lpfc_rport_data
*rdata
;
171 struct fc_rport
*rport
;
172 struct lpfc_vport
*vport
;
173 struct lpfc_hba
*phba
;
184 rdata
= rport
->dd_data
;
185 name
= (uint8_t *) &ndlp
->nlp_portname
;
189 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
190 "rport devlosstmo:did:x%x type:x%x id:x%x",
191 ndlp
->nlp_DID
, ndlp
->nlp_type
, rport
->scsi_target_id
);
193 /* Don't defer this if we are in the process of deleting the vport
194 * or unloading the driver. The unload will cleanup the node
195 * appropriately we just need to cleanup the ndlp rport info here.
197 if (vport
->load_flag
& FC_UNLOADING
) {
198 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
199 /* flush the target */
200 lpfc_sli_abort_iocb(vport
,
201 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
202 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
204 put_node
= rdata
->pnode
!= NULL
;
205 put_rport
= ndlp
->rport
!= NULL
;
211 put_device(&rport
->dev
);
215 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
216 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
217 "0284 Devloss timeout Ignored on "
218 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
220 *name
, *(name
+1), *(name
+2), *(name
+3),
221 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
226 if (ndlp
->nlp_type
& NLP_FABRIC
) {
227 /* We will clean up these Nodes in linkup */
228 put_node
= rdata
->pnode
!= NULL
;
229 put_rport
= ndlp
->rport
!= NULL
;
235 put_device(&rport
->dev
);
239 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
241 /* flush the target */
242 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
243 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
247 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
248 "0203 Devloss timeout on "
249 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
250 "NPort x%06x Data: x%x x%x x%x\n",
251 *name
, *(name
+1), *(name
+2), *(name
+3),
252 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
253 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
254 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
256 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
257 "0204 Devloss timeout on "
258 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
259 "NPort x%06x Data: x%x x%x x%x\n",
260 *name
, *(name
+1), *(name
+2), *(name
+3),
261 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
262 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
263 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
266 put_node
= rdata
->pnode
!= NULL
;
267 put_rport
= ndlp
->rport
!= NULL
;
273 put_device(&rport
->dev
);
275 if (!(vport
->load_flag
& FC_UNLOADING
) &&
276 !(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
277 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
278 (ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
))
279 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
281 lpfc_unregister_unused_fcf(phba
);
285 * lpfc_alloc_fast_evt - Allocates data structure for posting event
286 * @phba: Pointer to hba context object.
288 * This function is called from the functions which need to post
289 * events from interrupt context. This function allocates data
290 * structure required for posting event. It also keeps track of
291 * number of events pending and prevent event storm when there are
294 struct lpfc_fast_path_event
*
295 lpfc_alloc_fast_evt(struct lpfc_hba
*phba
) {
296 struct lpfc_fast_path_event
*ret
;
298 /* If there are lot of fast event do not exhaust memory due to this */
299 if (atomic_read(&phba
->fast_event_count
) > LPFC_MAX_EVT_COUNT
)
302 ret
= kzalloc(sizeof(struct lpfc_fast_path_event
),
305 atomic_inc(&phba
->fast_event_count
);
306 INIT_LIST_HEAD(&ret
->work_evt
.evt_listp
);
307 ret
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
313 * lpfc_free_fast_evt - Frees event data structure
314 * @phba: Pointer to hba context object.
315 * @evt: Event object which need to be freed.
317 * This function frees the data structure required for posting
321 lpfc_free_fast_evt(struct lpfc_hba
*phba
,
322 struct lpfc_fast_path_event
*evt
) {
324 atomic_dec(&phba
->fast_event_count
);
329 * lpfc_send_fastpath_evt - Posts events generated from fast path
330 * @phba: Pointer to hba context object.
331 * @evtp: Event data structure.
333 * This function is called from worker thread, when the interrupt
334 * context need to post an event. This function posts the event
335 * to fc transport netlink interface.
338 lpfc_send_fastpath_evt(struct lpfc_hba
*phba
,
339 struct lpfc_work_evt
*evtp
)
341 unsigned long evt_category
, evt_sub_category
;
342 struct lpfc_fast_path_event
*fast_evt_data
;
344 uint32_t evt_data_size
;
345 struct Scsi_Host
*shost
;
347 fast_evt_data
= container_of(evtp
, struct lpfc_fast_path_event
,
350 evt_category
= (unsigned long) fast_evt_data
->un
.fabric_evt
.event_type
;
351 evt_sub_category
= (unsigned long) fast_evt_data
->un
.
352 fabric_evt
.subcategory
;
353 shost
= lpfc_shost_from_vport(fast_evt_data
->vport
);
354 if (evt_category
== FC_REG_FABRIC_EVENT
) {
355 if (evt_sub_category
== LPFC_EVENT_FCPRDCHKERR
) {
356 evt_data
= (char *) &fast_evt_data
->un
.read_check_error
;
357 evt_data_size
= sizeof(fast_evt_data
->un
.
359 } else if ((evt_sub_category
== LPFC_EVENT_FABRIC_BUSY
) ||
360 (evt_sub_category
== LPFC_EVENT_PORT_BUSY
)) {
361 evt_data
= (char *) &fast_evt_data
->un
.fabric_evt
;
362 evt_data_size
= sizeof(fast_evt_data
->un
.fabric_evt
);
364 lpfc_free_fast_evt(phba
, fast_evt_data
);
367 } else if (evt_category
== FC_REG_SCSI_EVENT
) {
368 switch (evt_sub_category
) {
369 case LPFC_EVENT_QFULL
:
370 case LPFC_EVENT_DEVBSY
:
371 evt_data
= (char *) &fast_evt_data
->un
.scsi_evt
;
372 evt_data_size
= sizeof(fast_evt_data
->un
.scsi_evt
);
374 case LPFC_EVENT_CHECK_COND
:
375 evt_data
= (char *) &fast_evt_data
->un
.check_cond_evt
;
376 evt_data_size
= sizeof(fast_evt_data
->un
.
379 case LPFC_EVENT_VARQUEDEPTH
:
380 evt_data
= (char *) &fast_evt_data
->un
.queue_depth_evt
;
381 evt_data_size
= sizeof(fast_evt_data
->un
.
385 lpfc_free_fast_evt(phba
, fast_evt_data
);
389 lpfc_free_fast_evt(phba
, fast_evt_data
);
393 fc_host_post_vendor_event(shost
,
394 fc_get_event_number(),
399 lpfc_free_fast_evt(phba
, fast_evt_data
);
404 lpfc_work_list_done(struct lpfc_hba
*phba
)
406 struct lpfc_work_evt
*evtp
= NULL
;
407 struct lpfc_nodelist
*ndlp
;
410 spin_lock_irq(&phba
->hbalock
);
411 while (!list_empty(&phba
->work_list
)) {
412 list_remove_head((&phba
->work_list
), evtp
, typeof(*evtp
),
414 spin_unlock_irq(&phba
->hbalock
);
417 case LPFC_EVT_ELS_RETRY
:
418 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
419 lpfc_els_retry_delay_handler(ndlp
);
420 free_evt
= 0; /* evt is part of ndlp */
421 /* decrement the node reference count held
422 * for this queued work
426 case LPFC_EVT_DEV_LOSS
:
427 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
428 lpfc_dev_loss_tmo_handler(ndlp
);
430 /* decrement the node reference count held for
435 case LPFC_EVT_ONLINE
:
436 if (phba
->link_state
< LPFC_LINK_DOWN
)
437 *(int *) (evtp
->evt_arg1
) = lpfc_online(phba
);
439 *(int *) (evtp
->evt_arg1
) = 0;
440 complete((struct completion
*)(evtp
->evt_arg2
));
442 case LPFC_EVT_OFFLINE_PREP
:
443 if (phba
->link_state
>= LPFC_LINK_DOWN
)
444 lpfc_offline_prep(phba
);
445 *(int *)(evtp
->evt_arg1
) = 0;
446 complete((struct completion
*)(evtp
->evt_arg2
));
448 case LPFC_EVT_OFFLINE
:
450 lpfc_sli_brdrestart(phba
);
451 *(int *)(evtp
->evt_arg1
) =
452 lpfc_sli_brdready(phba
, HS_FFRDY
| HS_MBRDY
);
453 lpfc_unblock_mgmt_io(phba
);
454 complete((struct completion
*)(evtp
->evt_arg2
));
456 case LPFC_EVT_WARM_START
:
458 lpfc_reset_barrier(phba
);
459 lpfc_sli_brdreset(phba
);
460 lpfc_hba_down_post(phba
);
461 *(int *)(evtp
->evt_arg1
) =
462 lpfc_sli_brdready(phba
, HS_MBRDY
);
463 lpfc_unblock_mgmt_io(phba
);
464 complete((struct completion
*)(evtp
->evt_arg2
));
468 *(int *)(evtp
->evt_arg1
)
469 = (phba
->pport
->stopped
)
470 ? 0 : lpfc_sli_brdkill(phba
);
471 lpfc_unblock_mgmt_io(phba
);
472 complete((struct completion
*)(evtp
->evt_arg2
));
474 case LPFC_EVT_FASTPATH_MGMT_EVT
:
475 lpfc_send_fastpath_evt(phba
, evtp
);
478 case LPFC_EVT_RESET_HBA
:
479 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
480 lpfc_reset_hba(phba
);
485 spin_lock_irq(&phba
->hbalock
);
487 spin_unlock_irq(&phba
->hbalock
);
492 lpfc_work_done(struct lpfc_hba
*phba
)
494 struct lpfc_sli_ring
*pring
;
495 uint32_t ha_copy
, status
, control
, work_port_events
;
496 struct lpfc_vport
**vports
;
497 struct lpfc_vport
*vport
;
500 spin_lock_irq(&phba
->hbalock
);
501 ha_copy
= phba
->work_ha
;
503 spin_unlock_irq(&phba
->hbalock
);
505 /* First, try to post the next mailbox command to SLI4 device */
506 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
)
507 lpfc_sli4_post_async_mbox(phba
);
509 if (ha_copy
& HA_ERATT
)
510 /* Handle the error attention event */
511 lpfc_handle_eratt(phba
);
513 if (ha_copy
& HA_MBATT
)
514 lpfc_sli_handle_mb_event(phba
);
516 if (ha_copy
& HA_LATT
)
517 lpfc_handle_latt(phba
);
519 /* Process SLI4 events */
520 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
) {
521 if (phba
->hba_flag
& FCP_XRI_ABORT_EVENT
)
522 lpfc_sli4_fcp_xri_abort_event_proc(phba
);
523 if (phba
->hba_flag
& ELS_XRI_ABORT_EVENT
)
524 lpfc_sli4_els_xri_abort_event_proc(phba
);
525 if (phba
->hba_flag
& ASYNC_EVENT
)
526 lpfc_sli4_async_event_proc(phba
);
527 if (phba
->hba_flag
& HBA_POST_RECEIVE_BUFFER
) {
528 spin_lock_irq(&phba
->hbalock
);
529 phba
->hba_flag
&= ~HBA_POST_RECEIVE_BUFFER
;
530 spin_unlock_irq(&phba
->hbalock
);
531 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
533 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
)
534 lpfc_sli4_fcf_redisc_event_proc(phba
);
537 vports
= lpfc_create_vport_work_array(phba
);
539 for (i
= 0; i
<= phba
->max_vports
; i
++) {
541 * We could have no vports in array if unloading, so if
542 * this happens then just use the pport
544 if (vports
[i
] == NULL
&& i
== 0)
550 spin_lock_irq(&vport
->work_port_lock
);
551 work_port_events
= vport
->work_port_events
;
552 vport
->work_port_events
&= ~work_port_events
;
553 spin_unlock_irq(&vport
->work_port_lock
);
554 if (work_port_events
& WORKER_DISC_TMO
)
555 lpfc_disc_timeout_handler(vport
);
556 if (work_port_events
& WORKER_ELS_TMO
)
557 lpfc_els_timeout_handler(vport
);
558 if (work_port_events
& WORKER_HB_TMO
)
559 lpfc_hb_timeout_handler(phba
);
560 if (work_port_events
& WORKER_MBOX_TMO
)
561 lpfc_mbox_timeout_handler(phba
);
562 if (work_port_events
& WORKER_FABRIC_BLOCK_TMO
)
563 lpfc_unblock_fabric_iocbs(phba
);
564 if (work_port_events
& WORKER_FDMI_TMO
)
565 lpfc_fdmi_timeout_handler(vport
);
566 if (work_port_events
& WORKER_RAMP_DOWN_QUEUE
)
567 lpfc_ramp_down_queue_handler(phba
);
568 if (work_port_events
& WORKER_RAMP_UP_QUEUE
)
569 lpfc_ramp_up_queue_handler(phba
);
571 lpfc_destroy_vport_work_array(phba
, vports
);
573 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
574 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
575 status
>>= (4*LPFC_ELS_RING
);
576 if ((status
& HA_RXMASK
) ||
577 (pring
->flag
& LPFC_DEFERRED_RING_EVENT
) ||
578 (phba
->hba_flag
& HBA_SP_QUEUE_EVT
)) {
579 if (pring
->flag
& LPFC_STOP_IOCB_EVENT
) {
580 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
581 /* Set the lpfc data pending flag */
582 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
584 pring
->flag
&= ~LPFC_DEFERRED_RING_EVENT
;
585 lpfc_sli_handle_slow_ring_event(phba
, pring
,
590 * Turn on Ring interrupts
592 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
593 spin_lock_irq(&phba
->hbalock
);
594 control
= readl(phba
->HCregaddr
);
595 if (!(control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
))) {
596 lpfc_debugfs_slow_ring_trc(phba
,
597 "WRK Enable ring: cntl:x%x hacopy:x%x",
598 control
, ha_copy
, 0);
600 control
|= (HC_R0INT_ENA
<< LPFC_ELS_RING
);
601 writel(control
, phba
->HCregaddr
);
602 readl(phba
->HCregaddr
); /* flush */
604 lpfc_debugfs_slow_ring_trc(phba
,
605 "WRK Ring ok: cntl:x%x hacopy:x%x",
606 control
, ha_copy
, 0);
608 spin_unlock_irq(&phba
->hbalock
);
611 lpfc_work_list_done(phba
);
615 lpfc_do_work(void *p
)
617 struct lpfc_hba
*phba
= p
;
620 set_user_nice(current
, -20);
621 phba
->data_flags
= 0;
623 while (!kthread_should_stop()) {
624 /* wait and check worker queue activities */
625 rc
= wait_event_interruptible(phba
->work_waitq
,
626 (test_and_clear_bit(LPFC_DATA_READY
,
628 || kthread_should_stop()));
629 /* Signal wakeup shall terminate the worker thread */
631 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
632 "0433 Wakeup on signal: rc=x%x\n", rc
);
636 /* Attend pending lpfc data processing */
637 lpfc_work_done(phba
);
639 phba
->worker_thread
= NULL
;
640 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
641 "0432 Worker thread stopped.\n");
646 * This is only called to handle FC worker events. Since this a rare
647 * occurance, we allocate a struct lpfc_work_evt structure here instead of
648 * embedding it in the IOCB.
651 lpfc_workq_post_event(struct lpfc_hba
*phba
, void *arg1
, void *arg2
,
654 struct lpfc_work_evt
*evtp
;
658 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
659 * be queued to worker thread for processing
661 evtp
= kmalloc(sizeof(struct lpfc_work_evt
), GFP_ATOMIC
);
665 evtp
->evt_arg1
= arg1
;
666 evtp
->evt_arg2
= arg2
;
669 spin_lock_irqsave(&phba
->hbalock
, flags
);
670 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
671 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
673 lpfc_worker_wake_up(phba
);
679 lpfc_cleanup_rpis(struct lpfc_vport
*vport
, int remove
)
681 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
682 struct lpfc_hba
*phba
= vport
->phba
;
683 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
686 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
687 if (!NLP_CHK_NODE_ACT(ndlp
))
689 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
691 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) ||
692 ((vport
->port_type
== LPFC_NPIV_PORT
) &&
693 (ndlp
->nlp_DID
== NameServer_DID
)))
694 lpfc_unreg_rpi(vport
, ndlp
);
696 /* Leave Fabric nodes alone on link down */
697 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
698 (!remove
&& ndlp
->nlp_type
& NLP_FABRIC
))
700 rc
= lpfc_disc_state_machine(vport
, ndlp
, NULL
,
703 : NLP_EVT_DEVICE_RECOVERY
);
705 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) {
706 lpfc_mbx_unreg_vpi(vport
);
707 spin_lock_irq(shost
->host_lock
);
708 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
709 spin_unlock_irq(shost
->host_lock
);
714 lpfc_port_link_failure(struct lpfc_vport
*vport
)
716 lpfc_vport_set_state(vport
, FC_VPORT_LINKDOWN
);
718 /* Cleanup any outstanding received buffers */
719 lpfc_cleanup_rcv_buffers(vport
);
721 /* Cleanup any outstanding RSCN activity */
722 lpfc_els_flush_rscn(vport
);
724 /* Cleanup any outstanding ELS commands */
725 lpfc_els_flush_cmd(vport
);
727 lpfc_cleanup_rpis(vport
, 0);
729 /* Turn off discovery timer if its running */
730 lpfc_can_disctmo(vport
);
734 lpfc_linkdown_port(struct lpfc_vport
*vport
)
736 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
738 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKDOWN
, 0);
740 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
741 "Link Down: state:x%x rtry:x%x flg:x%x",
742 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
744 lpfc_port_link_failure(vport
);
749 lpfc_linkdown(struct lpfc_hba
*phba
)
751 struct lpfc_vport
*vport
= phba
->pport
;
752 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
753 struct lpfc_vport
**vports
;
757 if (phba
->link_state
== LPFC_LINK_DOWN
)
760 /* Block all SCSI stack I/Os */
761 lpfc_scsi_dev_block(phba
);
763 spin_lock_irq(&phba
->hbalock
);
764 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
765 spin_unlock_irq(&phba
->hbalock
);
766 if (phba
->link_state
> LPFC_LINK_DOWN
) {
767 phba
->link_state
= LPFC_LINK_DOWN
;
768 spin_lock_irq(shost
->host_lock
);
769 phba
->pport
->fc_flag
&= ~FC_LBIT
;
770 spin_unlock_irq(shost
->host_lock
);
772 vports
= lpfc_create_vport_work_array(phba
);
774 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
775 /* Issue a LINK DOWN event to all nodes */
776 lpfc_linkdown_port(vports
[i
]);
778 lpfc_destroy_vport_work_array(phba
, vports
);
779 /* Clean up any firmware default rpi's */
780 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
782 lpfc_unreg_did(phba
, 0xffff, 0xffffffff, mb
);
784 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
785 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
786 == MBX_NOT_FINISHED
) {
787 mempool_free(mb
, phba
->mbox_mem_pool
);
791 /* Setup myDID for link up if we are in pt2pt mode */
792 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
793 phba
->pport
->fc_myDID
= 0;
794 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
796 lpfc_config_link(phba
, mb
);
797 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
799 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
800 == MBX_NOT_FINISHED
) {
801 mempool_free(mb
, phba
->mbox_mem_pool
);
804 spin_lock_irq(shost
->host_lock
);
805 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
806 spin_unlock_irq(shost
->host_lock
);
813 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
815 struct lpfc_nodelist
*ndlp
;
817 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
818 if (!NLP_CHK_NODE_ACT(ndlp
))
820 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
822 if (ndlp
->nlp_type
& NLP_FABRIC
) {
823 /* On Linkup its safe to clean up the ndlp
824 * from Fabric connections.
826 if (ndlp
->nlp_DID
!= Fabric_DID
)
827 lpfc_unreg_rpi(vport
, ndlp
);
828 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
829 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
830 /* Fail outstanding IO now since device is
833 lpfc_unreg_rpi(vport
, ndlp
);
839 lpfc_linkup_port(struct lpfc_vport
*vport
)
841 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
842 struct lpfc_hba
*phba
= vport
->phba
;
844 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
847 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
848 "Link Up: top:x%x speed:x%x flg:x%x",
849 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
851 /* If NPIV is not enabled, only bring the physical port up */
852 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
853 (vport
!= phba
->pport
))
856 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKUP
, 0);
858 spin_lock_irq(shost
->host_lock
);
859 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
860 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
861 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
862 vport
->fc_ns_retry
= 0;
863 spin_unlock_irq(shost
->host_lock
);
865 if (vport
->fc_flag
& FC_LBIT
)
866 lpfc_linkup_cleanup_nodes(vport
);
871 lpfc_linkup(struct lpfc_hba
*phba
)
873 struct lpfc_vport
**vports
;
876 phba
->link_state
= LPFC_LINK_UP
;
878 /* Unblock fabric iocbs if they are blocked */
879 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
880 del_timer_sync(&phba
->fabric_block_timer
);
882 vports
= lpfc_create_vport_work_array(phba
);
884 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
885 lpfc_linkup_port(vports
[i
]);
886 lpfc_destroy_vport_work_array(phba
, vports
);
887 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
888 (phba
->sli_rev
< LPFC_SLI_REV4
))
889 lpfc_issue_clear_la(phba
, phba
->pport
);
895 * This routine handles processing a CLEAR_LA mailbox
896 * command upon completion. It is setup in the LPFC_MBOXQ
897 * as the completion routine when the command is
898 * handed off to the SLI layer.
901 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
903 struct lpfc_vport
*vport
= pmb
->vport
;
904 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
905 struct lpfc_sli
*psli
= &phba
->sli
;
906 MAILBOX_t
*mb
= &pmb
->u
.mb
;
909 /* Since we don't do discovery right now, turn these off here */
910 psli
->ring
[psli
->extra_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
911 psli
->ring
[psli
->fcp_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
912 psli
->ring
[psli
->next_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
914 /* Check for error */
915 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
916 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
917 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
918 "0320 CLEAR_LA mbxStatus error x%x hba "
920 mb
->mbxStatus
, vport
->port_state
);
921 phba
->link_state
= LPFC_HBA_ERROR
;
925 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
926 phba
->link_state
= LPFC_HBA_READY
;
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
);
935 mempool_free(pmb
, phba
->mbox_mem_pool
);
939 /* Device Discovery completes */
940 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
941 "0225 Device Discovery completes\n");
942 mempool_free(pmb
, phba
->mbox_mem_pool
);
944 spin_lock_irq(shost
->host_lock
);
945 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
946 spin_unlock_irq(shost
->host_lock
);
948 lpfc_can_disctmo(vport
);
950 /* turn on Link Attention interrupts */
952 spin_lock_irq(&phba
->hbalock
);
953 psli
->sli_flag
|= LPFC_PROCESS_LA
;
954 control
= readl(phba
->HCregaddr
);
955 control
|= HC_LAINT_ENA
;
956 writel(control
, phba
->HCregaddr
);
957 readl(phba
->HCregaddr
); /* flush */
958 spin_unlock_irq(&phba
->hbalock
);
965 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
967 struct lpfc_vport
*vport
= pmb
->vport
;
969 if (pmb
->u
.mb
.mbxStatus
)
972 mempool_free(pmb
, phba
->mbox_mem_pool
);
974 if (phba
->fc_topology
== TOPOLOGY_LOOP
&&
975 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
976 !(vport
->fc_flag
& FC_LBIT
)) {
977 /* Need to wait for FAN - use discovery timer
978 * for timeout. port_state is identically
979 * LPFC_LOCAL_CFG_LINK while waiting for FAN
981 lpfc_set_disctmo(vport
);
985 /* Start discovery by sending a FLOGI. port_state is identically
986 * LPFC_FLOGI while waiting for FLOGI cmpl
988 if (vport
->port_state
!= LPFC_FLOGI
) {
989 lpfc_initial_flogi(vport
);
994 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
995 "0306 CONFIG_LINK mbxStatus error x%x "
997 pmb
->u
.mb
.mbxStatus
, vport
->port_state
);
998 mempool_free(pmb
, phba
->mbox_mem_pool
);
1000 lpfc_linkdown(phba
);
1002 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1003 "0200 CONFIG_LINK bad hba state x%x\n",
1006 lpfc_issue_clear_la(phba
, vport
);
1011 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1013 struct lpfc_vport
*vport
= mboxq
->vport
;
1014 unsigned long flags
;
1016 if (mboxq
->u
.mb
.mbxStatus
) {
1017 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1018 "2017 REG_FCFI mbxStatus error x%x "
1020 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
1021 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1025 /* Start FCoE discovery by sending a FLOGI. */
1026 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
, &mboxq
->u
.mqe
.un
.reg_fcfi
);
1027 /* Set the FCFI registered flag */
1028 spin_lock_irqsave(&phba
->hbalock
, flags
);
1029 phba
->fcf
.fcf_flag
|= FCF_REGISTERED
;
1030 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1031 /* If there is a pending FCoE event, restart FCF table scan. */
1032 if (lpfc_check_pending_fcoe_event(phba
, 1)) {
1033 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1036 spin_lock_irqsave(&phba
->hbalock
, flags
);
1037 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1038 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1039 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1040 if (vport
->port_state
!= LPFC_FLOGI
)
1041 lpfc_initial_flogi(vport
);
1043 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1048 * lpfc_fab_name_match - Check if the fcf fabric name match.
1049 * @fab_name: pointer to fabric name.
1050 * @new_fcf_record: pointer to fcf record.
1052 * This routine compare the fcf record's fabric name with provided
1053 * fabric name. If the fabric name are identical this function
1054 * returns 1 else return 0.
1057 lpfc_fab_name_match(uint8_t *fab_name
, struct fcf_record
*new_fcf_record
)
1059 if (fab_name
[0] != bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
))
1061 if (fab_name
[1] != bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
))
1063 if (fab_name
[2] != bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
))
1065 if (fab_name
[3] != bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
))
1067 if (fab_name
[4] != bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
))
1069 if (fab_name
[5] != bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
))
1071 if (fab_name
[6] != bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
))
1073 if (fab_name
[7] != bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
))
1079 * lpfc_sw_name_match - Check if the fcf switch name match.
1080 * @fab_name: pointer to fabric name.
1081 * @new_fcf_record: pointer to fcf record.
1083 * This routine compare the fcf record's switch name with provided
1084 * switch name. If the switch name are identical this function
1085 * returns 1 else return 0.
1088 lpfc_sw_name_match(uint8_t *sw_name
, struct fcf_record
*new_fcf_record
)
1090 if (sw_name
[0] != bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
))
1092 if (sw_name
[1] != bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
))
1094 if (sw_name
[2] != bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
))
1096 if (sw_name
[3] != bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
))
1098 if (sw_name
[4] != bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
))
1100 if (sw_name
[5] != bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
))
1102 if (sw_name
[6] != bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
))
1104 if (sw_name
[7] != bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
))
1110 * lpfc_mac_addr_match - Check if the fcf mac address match.
1111 * @mac_addr: pointer to mac address.
1112 * @new_fcf_record: pointer to fcf record.
1114 * This routine compare the fcf record's mac address with HBA's
1115 * FCF mac address. If the mac addresses are identical this function
1116 * returns 1 else return 0.
1119 lpfc_mac_addr_match(uint8_t *mac_addr
, struct fcf_record
*new_fcf_record
)
1121 if (mac_addr
[0] != bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
))
1123 if (mac_addr
[1] != bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
))
1125 if (mac_addr
[2] != bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
))
1127 if (mac_addr
[3] != bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
))
1129 if (mac_addr
[4] != bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
))
1131 if (mac_addr
[5] != bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
))
1137 lpfc_vlan_id_match(uint16_t curr_vlan_id
, uint16_t new_vlan_id
)
1139 return (curr_vlan_id
== new_vlan_id
);
1143 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1144 * @fcf: pointer to driver fcf record.
1145 * @new_fcf_record: pointer to fcf record.
1147 * This routine copies the FCF information from the FCF
1148 * record to lpfc_hba data structure.
1151 lpfc_copy_fcf_record(struct lpfc_fcf_rec
*fcf_rec
,
1152 struct fcf_record
*new_fcf_record
)
1155 fcf_rec
->fabric_name
[0] =
1156 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
);
1157 fcf_rec
->fabric_name
[1] =
1158 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
);
1159 fcf_rec
->fabric_name
[2] =
1160 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
);
1161 fcf_rec
->fabric_name
[3] =
1162 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
);
1163 fcf_rec
->fabric_name
[4] =
1164 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
);
1165 fcf_rec
->fabric_name
[5] =
1166 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
);
1167 fcf_rec
->fabric_name
[6] =
1168 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
);
1169 fcf_rec
->fabric_name
[7] =
1170 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
);
1172 fcf_rec
->mac_addr
[0] = bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
);
1173 fcf_rec
->mac_addr
[1] = bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
);
1174 fcf_rec
->mac_addr
[2] = bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
);
1175 fcf_rec
->mac_addr
[3] = bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
);
1176 fcf_rec
->mac_addr
[4] = bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
);
1177 fcf_rec
->mac_addr
[5] = bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
);
1178 /* FCF record index */
1179 fcf_rec
->fcf_indx
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1180 /* FCF record priority */
1181 fcf_rec
->priority
= new_fcf_record
->fip_priority
;
1183 fcf_rec
->switch_name
[0] =
1184 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
);
1185 fcf_rec
->switch_name
[1] =
1186 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
);
1187 fcf_rec
->switch_name
[2] =
1188 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
);
1189 fcf_rec
->switch_name
[3] =
1190 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
);
1191 fcf_rec
->switch_name
[4] =
1192 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
);
1193 fcf_rec
->switch_name
[5] =
1194 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
);
1195 fcf_rec
->switch_name
[6] =
1196 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
);
1197 fcf_rec
->switch_name
[7] =
1198 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
);
1202 * lpfc_update_fcf_record - Update driver fcf record
1203 * @phba: pointer to lpfc hba data structure.
1204 * @fcf_rec: pointer to driver fcf record.
1205 * @new_fcf_record: pointer to hba fcf record.
1206 * @addr_mode: address mode to be set to the driver fcf record.
1207 * @vlan_id: vlan tag to be set to the driver fcf record.
1208 * @flag: flag bits to be set to the driver fcf record.
1210 * This routine updates the driver FCF record from the new HBA FCF record
1211 * together with the address mode, vlan_id, and other informations. This
1212 * routine is called with the host lock held.
1215 __lpfc_update_fcf_record(struct lpfc_hba
*phba
, struct lpfc_fcf_rec
*fcf_rec
,
1216 struct fcf_record
*new_fcf_record
, uint32_t addr_mode
,
1217 uint16_t vlan_id
, uint32_t flag
)
1219 /* Copy the fields from the HBA's FCF record */
1220 lpfc_copy_fcf_record(fcf_rec
, new_fcf_record
);
1221 /* Update other fields of driver FCF record */
1222 fcf_rec
->addr_mode
= addr_mode
;
1223 fcf_rec
->vlan_id
= vlan_id
;
1224 fcf_rec
->flag
|= (flag
| RECORD_VALID
);
1228 * lpfc_register_fcf - Register the FCF with hba.
1229 * @phba: pointer to lpfc hba data structure.
1231 * This routine issues a register fcfi mailbox command to register
1235 lpfc_register_fcf(struct lpfc_hba
*phba
)
1237 LPFC_MBOXQ_t
*fcf_mbxq
;
1239 unsigned long flags
;
1241 spin_lock_irqsave(&phba
->hbalock
, flags
);
1243 /* If the FCF is not availabe do nothing. */
1244 if (!(phba
->fcf
.fcf_flag
& FCF_AVAILABLE
)) {
1245 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1246 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1250 /* The FCF is already registered, start discovery */
1251 if (phba
->fcf
.fcf_flag
& FCF_REGISTERED
) {
1252 phba
->fcf
.fcf_flag
|= (FCF_SCAN_DONE
| FCF_IN_USE
);
1253 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1254 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1255 if (phba
->pport
->port_state
!= LPFC_FLOGI
)
1256 lpfc_initial_flogi(phba
->pport
);
1259 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1261 fcf_mbxq
= mempool_alloc(phba
->mbox_mem_pool
,
1264 spin_lock_irqsave(&phba
->hbalock
, flags
);
1265 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1266 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1270 lpfc_reg_fcfi(phba
, fcf_mbxq
);
1271 fcf_mbxq
->vport
= phba
->pport
;
1272 fcf_mbxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_fcfi
;
1273 rc
= lpfc_sli_issue_mbox(phba
, fcf_mbxq
, MBX_NOWAIT
);
1274 if (rc
== MBX_NOT_FINISHED
) {
1275 spin_lock_irqsave(&phba
->hbalock
, flags
);
1276 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1277 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1278 mempool_free(fcf_mbxq
, phba
->mbox_mem_pool
);
1285 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1286 * @phba: pointer to lpfc hba data structure.
1287 * @new_fcf_record: pointer to fcf record.
1288 * @boot_flag: Indicates if this record used by boot bios.
1289 * @addr_mode: The address mode to be used by this FCF
1290 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1292 * This routine compare the fcf record with connect list obtained from the
1293 * config region to decide if this FCF can be used for SAN discovery. It returns
1294 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1295 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1296 * is used by boot bios and addr_mode will indicate the addressing mode to be
1297 * used for this FCF when the function returns.
1298 * If the FCF record need to be used with a particular vlan id, the vlan is
1299 * set in the vlan_id on return of the function. If not VLAN tagging need to
1300 * be used with the FCF vlan_id will be set to 0xFFFF;
1303 lpfc_match_fcf_conn_list(struct lpfc_hba
*phba
,
1304 struct fcf_record
*new_fcf_record
,
1305 uint32_t *boot_flag
, uint32_t *addr_mode
,
1308 struct lpfc_fcf_conn_entry
*conn_entry
;
1309 int i
, j
, fcf_vlan_id
= 0;
1311 /* Find the lowest VLAN id in the FCF record */
1312 for (i
= 0; i
< 512; i
++) {
1313 if (new_fcf_record
->vlan_bitmap
[i
]) {
1314 fcf_vlan_id
= i
* 8;
1316 while (!((new_fcf_record
->vlan_bitmap
[i
] >> j
) & 1)) {
1324 /* If FCF not available return 0 */
1325 if (!bf_get(lpfc_fcf_record_fcf_avail
, new_fcf_record
) ||
1326 !bf_get(lpfc_fcf_record_fcf_valid
, new_fcf_record
))
1329 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
1331 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1333 if (phba
->valid_vlan
)
1334 *vlan_id
= phba
->vlan_id
;
1341 * If there are no FCF connection table entry, driver connect to all
1344 if (list_empty(&phba
->fcf_conn_rec_list
)) {
1346 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1350 * When there are no FCF connect entries, use driver's default
1351 * addressing mode - FPMA.
1353 if (*addr_mode
& LPFC_FCF_FPMA
)
1354 *addr_mode
= LPFC_FCF_FPMA
;
1356 /* If FCF record report a vlan id use that vlan id */
1358 *vlan_id
= fcf_vlan_id
;
1364 list_for_each_entry(conn_entry
,
1365 &phba
->fcf_conn_rec_list
, list
) {
1366 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_VALID
))
1369 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_FBNM_VALID
) &&
1370 !lpfc_fab_name_match(conn_entry
->conn_rec
.fabric_name
,
1373 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_SWNM_VALID
) &&
1374 !lpfc_sw_name_match(conn_entry
->conn_rec
.switch_name
,
1377 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
) {
1379 * If the vlan bit map does not have the bit set for the
1380 * vlan id to be used, then it is not a match.
1382 if (!(new_fcf_record
->vlan_bitmap
1383 [conn_entry
->conn_rec
.vlan_tag
/ 8] &
1384 (1 << (conn_entry
->conn_rec
.vlan_tag
% 8))))
1389 * If connection record does not support any addressing mode,
1390 * skip the FCF record.
1392 if (!(bf_get(lpfc_fcf_record_mac_addr_prov
, new_fcf_record
)
1393 & (LPFC_FCF_FPMA
| LPFC_FCF_SPMA
)))
1397 * Check if the connection record specifies a required
1400 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1401 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)) {
1404 * If SPMA required but FCF not support this continue.
1406 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1407 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1408 new_fcf_record
) & LPFC_FCF_SPMA
))
1412 * If FPMA required but FCF not support this continue.
1414 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1415 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1416 new_fcf_record
) & LPFC_FCF_FPMA
))
1421 * This fcf record matches filtering criteria.
1423 if (conn_entry
->conn_rec
.flags
& FCFCNCT_BOOT
)
1429 * If user did not specify any addressing mode, or if the
1430 * prefered addressing mode specified by user is not supported
1431 * by FCF, allow fabric to pick the addressing mode.
1433 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1436 * If the user specified a required address mode, assign that
1439 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1440 (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)))
1441 *addr_mode
= (conn_entry
->conn_rec
.flags
&
1443 LPFC_FCF_SPMA
: LPFC_FCF_FPMA
;
1445 * If the user specified a prefered address mode, use the
1446 * addr mode only if FCF support the addr_mode.
1448 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1449 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1450 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1451 (*addr_mode
& LPFC_FCF_SPMA
))
1452 *addr_mode
= LPFC_FCF_SPMA
;
1453 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1454 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1455 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1456 (*addr_mode
& LPFC_FCF_FPMA
))
1457 *addr_mode
= LPFC_FCF_FPMA
;
1459 /* If matching connect list has a vlan id, use it */
1460 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
)
1461 *vlan_id
= conn_entry
->conn_rec
.vlan_tag
;
1463 * If no vlan id is specified in connect list, use the vlan id
1466 else if (fcf_vlan_id
)
1467 *vlan_id
= fcf_vlan_id
;
1478 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1479 * @phba: pointer to lpfc hba data structure.
1480 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1482 * This function check if there is any fcoe event pending while driver
1483 * scan FCF entries. If there is any pending event, it will restart the
1484 * FCF saning and return 1 else return 0.
1487 lpfc_check_pending_fcoe_event(struct lpfc_hba
*phba
, uint8_t unreg_fcf
)
1490 * If the Link is up and no FCoE events while in the
1491 * FCF discovery, no need to restart FCF discovery.
1493 if ((phba
->link_state
>= LPFC_LINK_UP
) &&
1494 (phba
->fcoe_eventtag
== phba
->fcoe_eventtag_at_fcf_scan
))
1497 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1498 "2768 Pending link or FCF event during current "
1499 "handling of the previous event: link_state:x%x, "
1500 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1501 phba
->link_state
, phba
->fcoe_eventtag_at_fcf_scan
,
1502 phba
->fcoe_eventtag
);
1504 spin_lock_irq(&phba
->hbalock
);
1505 phba
->fcf
.fcf_flag
&= ~FCF_AVAILABLE
;
1506 spin_unlock_irq(&phba
->hbalock
);
1508 if (phba
->link_state
>= LPFC_LINK_UP
) {
1509 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
1510 "2780 Restart FCF table scan due to "
1511 "pending FCF event:evt_tag_at_scan:x%x, "
1512 "evt_tag_current:x%x\n",
1513 phba
->fcoe_eventtag_at_fcf_scan
,
1514 phba
->fcoe_eventtag
);
1515 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
1518 * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS
1521 spin_lock_irq(&phba
->hbalock
);
1522 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1523 phba
->fcf
.fcf_flag
&= ~(FCF_REDISC_FOV
| FCF_DISCOVERY
);
1524 spin_unlock_irq(&phba
->hbalock
);
1527 /* Unregister the currently registered FCF if required */
1529 spin_lock_irq(&phba
->hbalock
);
1530 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
1531 spin_unlock_irq(&phba
->hbalock
);
1532 lpfc_sli4_unregister_fcf(phba
);
1538 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1539 * @phba: pointer to lpfc hba data structure.
1540 * @fcf_cnt: number of eligible fcf record seen so far.
1542 * This function makes an running random selection decision on FCF record to
1543 * use through a sequence of @fcf_cnt eligible FCF records with equal
1544 * probability. To perform integer manunipulation of random numbers with
1545 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1546 * from random32() are taken as the random random number generated.
1548 * Returns true when outcome is for the newly read FCF record should be
1549 * chosen; otherwise, return false when outcome is for keeping the previously
1550 * chosen FCF record.
1553 lpfc_sli4_new_fcf_random_select(struct lpfc_hba
*phba
, uint32_t fcf_cnt
)
1557 /* Get 16-bit uniform random number */
1558 rand_num
= (0xFFFF & random32());
1560 /* Decision with probability 1/fcf_cnt */
1561 if ((fcf_cnt
* rand_num
) < 0xFFFF)
1568 * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox.
1569 * @phba: pointer to lpfc hba data structure.
1570 * @mboxq: pointer to mailbox object.
1571 * @next_fcf_index: pointer to holder of next fcf index.
1573 * This routine parses the non-embedded fcf mailbox command by performing the
1574 * necessarily error checking, non-embedded read FCF record mailbox command
1575 * SGE parsing, and endianness swapping.
1577 * Returns the pointer to the new FCF record in the non-embedded mailbox
1578 * command DMA memory if successfully, other NULL.
1580 static struct fcf_record
*
1581 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
,
1582 uint16_t *next_fcf_index
)
1585 dma_addr_t phys_addr
;
1586 struct lpfc_mbx_sge sge
;
1587 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
1588 uint32_t shdr_status
, shdr_add_status
;
1589 union lpfc_sli4_cfg_shdr
*shdr
;
1590 struct fcf_record
*new_fcf_record
;
1592 /* Get the first SGE entry from the non-embedded DMA memory. This
1593 * routine only uses a single SGE.
1595 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
1596 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1597 if (unlikely(!mboxq
->sge_array
)) {
1598 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1599 "2524 Failed to get the non-embedded SGE "
1600 "virtual address\n");
1603 virt_addr
= mboxq
->sge_array
->addr
[0];
1605 shdr
= (union lpfc_sli4_cfg_shdr
*)virt_addr
;
1606 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
1607 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
1608 if (shdr_status
|| shdr_add_status
) {
1609 if (shdr_status
== STATUS_FCF_TABLE_EMPTY
)
1610 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1611 "2726 READ_FCF_RECORD Indicates empty "
1614 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
1615 "2521 READ_FCF_RECORD mailbox failed "
1616 "with status x%x add_status x%x, "
1617 "mbx\n", shdr_status
, shdr_add_status
);
1621 /* Interpreting the returned information of the FCF record */
1622 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
1623 lpfc_sli_pcimem_bcopy(read_fcf
, read_fcf
,
1624 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1625 *next_fcf_index
= bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx
, read_fcf
);
1626 new_fcf_record
= (struct fcf_record
*)(virt_addr
+
1627 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1628 lpfc_sli_pcimem_bcopy(new_fcf_record
, new_fcf_record
,
1629 offsetof(struct fcf_record
, vlan_bitmap
));
1630 new_fcf_record
->word137
= le32_to_cpu(new_fcf_record
->word137
);
1631 new_fcf_record
->word138
= le32_to_cpu(new_fcf_record
->word138
);
1633 return new_fcf_record
;
1637 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1638 * @phba: pointer to lpfc hba data structure.
1639 * @fcf_record: pointer to the fcf record.
1640 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1641 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1643 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1647 lpfc_sli4_log_fcf_record_info(struct lpfc_hba
*phba
,
1648 struct fcf_record
*fcf_record
,
1650 uint16_t next_fcf_index
)
1652 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
1653 "2764 READ_FCF_RECORD:\n"
1654 "\tFCF_Index : x%x\n"
1655 "\tFCF_Avail : x%x\n"
1656 "\tFCF_Valid : x%x\n"
1657 "\tFIP_Priority : x%x\n"
1658 "\tMAC_Provider : x%x\n"
1659 "\tLowest VLANID : x%x\n"
1660 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1661 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1662 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1663 "\tNext_FCF_Index: x%x\n",
1664 bf_get(lpfc_fcf_record_fcf_index
, fcf_record
),
1665 bf_get(lpfc_fcf_record_fcf_avail
, fcf_record
),
1666 bf_get(lpfc_fcf_record_fcf_valid
, fcf_record
),
1667 fcf_record
->fip_priority
,
1668 bf_get(lpfc_fcf_record_mac_addr_prov
, fcf_record
),
1670 bf_get(lpfc_fcf_record_mac_0
, fcf_record
),
1671 bf_get(lpfc_fcf_record_mac_1
, fcf_record
),
1672 bf_get(lpfc_fcf_record_mac_2
, fcf_record
),
1673 bf_get(lpfc_fcf_record_mac_3
, fcf_record
),
1674 bf_get(lpfc_fcf_record_mac_4
, fcf_record
),
1675 bf_get(lpfc_fcf_record_mac_5
, fcf_record
),
1676 bf_get(lpfc_fcf_record_fab_name_0
, fcf_record
),
1677 bf_get(lpfc_fcf_record_fab_name_1
, fcf_record
),
1678 bf_get(lpfc_fcf_record_fab_name_2
, fcf_record
),
1679 bf_get(lpfc_fcf_record_fab_name_3
, fcf_record
),
1680 bf_get(lpfc_fcf_record_fab_name_4
, fcf_record
),
1681 bf_get(lpfc_fcf_record_fab_name_5
, fcf_record
),
1682 bf_get(lpfc_fcf_record_fab_name_6
, fcf_record
),
1683 bf_get(lpfc_fcf_record_fab_name_7
, fcf_record
),
1684 bf_get(lpfc_fcf_record_switch_name_0
, fcf_record
),
1685 bf_get(lpfc_fcf_record_switch_name_1
, fcf_record
),
1686 bf_get(lpfc_fcf_record_switch_name_2
, fcf_record
),
1687 bf_get(lpfc_fcf_record_switch_name_3
, fcf_record
),
1688 bf_get(lpfc_fcf_record_switch_name_4
, fcf_record
),
1689 bf_get(lpfc_fcf_record_switch_name_5
, fcf_record
),
1690 bf_get(lpfc_fcf_record_switch_name_6
, fcf_record
),
1691 bf_get(lpfc_fcf_record_switch_name_7
, fcf_record
),
1696 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
1697 * @phba: pointer to lpfc hba data structure.
1698 * @mboxq: pointer to mailbox object.
1700 * This function iterates through all the fcf records available in
1701 * HBA and chooses the optimal FCF record for discovery. After finding
1702 * the FCF for discovery it registers the FCF record and kicks start
1704 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
1705 * use an FCF record which matches fabric name and mac address of the
1706 * currently used FCF record.
1707 * If the driver supports only one FCF, it will try to use the FCF record
1708 * used by BOOT_BIOS.
1711 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1713 struct fcf_record
*new_fcf_record
;
1714 uint32_t boot_flag
, addr_mode
;
1715 uint16_t fcf_index
, next_fcf_index
;
1716 struct lpfc_fcf_rec
*fcf_rec
= NULL
;
1719 bool select_new_fcf
;
1722 /* If there is pending FCoE event restart FCF table scan */
1723 if (lpfc_check_pending_fcoe_event(phba
, 0)) {
1724 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1728 /* Parse the FCF record from the non-embedded mailbox command */
1729 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
1731 if (!new_fcf_record
) {
1732 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
1733 "2765 Mailbox command READ_FCF_RECORD "
1734 "failed to retrieve a FCF record.\n");
1735 /* Let next new FCF event trigger fast failover */
1736 spin_lock_irq(&phba
->hbalock
);
1737 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1738 spin_unlock_irq(&phba
->hbalock
);
1739 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1743 /* Check the FCF record against the connection list */
1744 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
1745 &addr_mode
, &vlan_id
);
1747 /* Log the FCF record information if turned on */
1748 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
1752 * If the fcf record does not match with connect list entries
1753 * read the next entry; otherwise, this is an eligible FCF
1754 * record for round robin FCF failover.
1757 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
1758 "2781 FCF record fcf_index:x%x failed FCF "
1759 "connection list check, fcf_avail:x%x, "
1761 bf_get(lpfc_fcf_record_fcf_index
,
1763 bf_get(lpfc_fcf_record_fcf_avail
,
1765 bf_get(lpfc_fcf_record_fcf_valid
,
1769 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1770 rc
= lpfc_sli4_fcf_rr_index_set(phba
, fcf_index
);
1776 * If this is not the first FCF discovery of the HBA, use last
1777 * FCF record for the discovery. The condition that a rescan
1778 * matches the in-use FCF record: fabric name, switch name, mac
1779 * address, and vlan_id.
1781 spin_lock_irq(&phba
->hbalock
);
1782 if (phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
1783 if (lpfc_fab_name_match(phba
->fcf
.current_rec
.fabric_name
,
1785 lpfc_sw_name_match(phba
->fcf
.current_rec
.switch_name
,
1787 lpfc_mac_addr_match(phba
->fcf
.current_rec
.mac_addr
,
1789 lpfc_vlan_id_match(phba
->fcf
.current_rec
.vlan_id
,
1791 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
1792 if (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)
1793 /* Stop FCF redisc wait timer if pending */
1794 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
1795 else if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
1796 /* If in fast failover, mark it's completed */
1797 phba
->fcf
.fcf_flag
&= ~(FCF_REDISC_FOV
|
1799 spin_unlock_irq(&phba
->hbalock
);
1803 * Read next FCF record from HBA searching for the matching
1804 * with in-use record only if not during the fast failover
1805 * period. In case of fast failover period, it shall try to
1806 * determine whether the FCF record just read should be the
1809 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)) {
1810 spin_unlock_irq(&phba
->hbalock
);
1815 * Update on failover FCF record only if it's in FCF fast-failover
1816 * period; otherwise, update on current FCF record.
1818 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
)
1819 fcf_rec
= &phba
->fcf
.failover_rec
;
1821 fcf_rec
= &phba
->fcf
.current_rec
;
1823 if (phba
->fcf
.fcf_flag
& FCF_AVAILABLE
) {
1825 * If the driver FCF record does not have boot flag
1826 * set and new hba fcf record has boot flag set, use
1827 * the new hba fcf record.
1829 if (boot_flag
&& !(fcf_rec
->flag
& BOOT_ENABLE
)) {
1830 /* Choose this FCF record */
1831 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
1832 addr_mode
, vlan_id
, BOOT_ENABLE
);
1833 spin_unlock_irq(&phba
->hbalock
);
1837 * If the driver FCF record has boot flag set and the
1838 * new hba FCF record does not have boot flag, read
1839 * the next FCF record.
1841 if (!boot_flag
&& (fcf_rec
->flag
& BOOT_ENABLE
)) {
1842 spin_unlock_irq(&phba
->hbalock
);
1846 * If the new hba FCF record has lower priority value
1847 * than the driver FCF record, use the new record.
1849 if (new_fcf_record
->fip_priority
< fcf_rec
->priority
) {
1850 /* Choose the new FCF record with lower priority */
1851 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
1852 addr_mode
, vlan_id
, 0);
1853 /* Reset running random FCF selection count */
1854 phba
->fcf
.eligible_fcf_cnt
= 1;
1855 } else if (new_fcf_record
->fip_priority
== fcf_rec
->priority
) {
1856 /* Update running random FCF selection count */
1857 phba
->fcf
.eligible_fcf_cnt
++;
1858 select_new_fcf
= lpfc_sli4_new_fcf_random_select(phba
,
1859 phba
->fcf
.eligible_fcf_cnt
);
1861 /* Choose the new FCF by random selection */
1862 __lpfc_update_fcf_record(phba
, fcf_rec
,
1864 addr_mode
, vlan_id
, 0);
1866 spin_unlock_irq(&phba
->hbalock
);
1870 * This is the first suitable FCF record, choose this record for
1871 * initial best-fit FCF.
1874 __lpfc_update_fcf_record(phba
, fcf_rec
, new_fcf_record
,
1875 addr_mode
, vlan_id
, (boot_flag
?
1877 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
1878 /* Setup initial running random FCF selection count */
1879 phba
->fcf
.eligible_fcf_cnt
= 1;
1880 /* Seeding the random number generator for random selection */
1881 seed
= (uint32_t)(0xFFFFFFFF & jiffies
);
1884 spin_unlock_irq(&phba
->hbalock
);
1888 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1889 if (next_fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
|| next_fcf_index
== 0) {
1890 if (phba
->fcf
.fcf_flag
& FCF_REDISC_FOV
) {
1892 * Case of FCF fast failover scan
1896 * It has not found any suitable FCF record, cancel
1897 * FCF scan inprogress, and do nothing
1899 if (!(phba
->fcf
.failover_rec
.flag
& RECORD_VALID
)) {
1900 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
1901 "2782 No suitable FCF record "
1902 "found during this round of "
1903 "post FCF rediscovery scan: "
1904 "fcf_evt_tag:x%x, fcf_index: "
1906 phba
->fcoe_eventtag_at_fcf_scan
,
1907 bf_get(lpfc_fcf_record_fcf_index
,
1910 * Let next new FCF event trigger fast
1913 spin_lock_irq(&phba
->hbalock
);
1914 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1915 spin_unlock_irq(&phba
->hbalock
);
1919 * It has found a suitable FCF record that is not
1920 * the same as in-use FCF record, unregister the
1921 * in-use FCF record, replace the in-use FCF record
1922 * with the new FCF record, mark FCF fast failover
1923 * completed, and then start register the new FCF
1927 /* Unregister the current in-use FCF record */
1928 lpfc_unregister_fcf(phba
);
1930 /* Replace in-use record with the new record */
1931 memcpy(&phba
->fcf
.current_rec
,
1932 &phba
->fcf
.failover_rec
,
1933 sizeof(struct lpfc_fcf_rec
));
1934 /* mark the FCF fast failover completed */
1935 spin_lock_irq(&phba
->hbalock
);
1936 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_FOV
;
1937 spin_unlock_irq(&phba
->hbalock
);
1939 * Set up the initial registered FCF index for FLOGI
1940 * round robin FCF failover.
1942 phba
->fcf
.fcf_rr_init_indx
=
1943 phba
->fcf
.failover_rec
.fcf_indx
;
1944 /* Register to the new FCF record */
1945 lpfc_register_fcf(phba
);
1948 * In case of transaction period to fast FCF failover,
1949 * do nothing when search to the end of the FCF table.
1951 if ((phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) ||
1952 (phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
))
1955 * Otherwise, initial scan or post linkdown rescan,
1956 * register with the best FCF record found so far
1957 * through the FCF scanning process.
1960 /* mark the initial FCF discovery completed */
1961 spin_lock_irq(&phba
->hbalock
);
1962 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
1963 spin_unlock_irq(&phba
->hbalock
);
1965 * Set up the initial registered FCF index for FLOGI
1966 * round robin FCF failover
1968 phba
->fcf
.fcf_rr_init_indx
=
1969 phba
->fcf
.current_rec
.fcf_indx
;
1970 /* Register to the new FCF record */
1971 lpfc_register_fcf(phba
);
1974 lpfc_sli4_fcf_scan_read_fcf_rec(phba
, next_fcf_index
);
1978 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1979 lpfc_register_fcf(phba
);
1985 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf round robin read_fcf mbox cmpl hdler
1986 * @phba: pointer to lpfc hba data structure.
1987 * @mboxq: pointer to mailbox object.
1989 * This is the callback function for FLOGI failure round robin FCF failover
1990 * read FCF record mailbox command from the eligible FCF record bmask for
1991 * performing the failover. If the FCF read back is not valid/available, it
1992 * fails through to retrying FLOGI to the currently registered FCF again.
1993 * Otherwise, if the FCF read back is valid and available, it will set the
1994 * newly read FCF record to the failover FCF record, unregister currently
1995 * registered FCF record, copy the failover FCF record to the current
1996 * FCF record, and then register the current FCF record before proceeding
1997 * to trying FLOGI on the new failover FCF.
2000 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2002 struct fcf_record
*new_fcf_record
;
2003 uint32_t boot_flag
, addr_mode
;
2004 uint16_t next_fcf_index
;
2005 uint16_t current_fcf_index
;
2008 /* If link state is not up, stop the round robin failover process */
2009 if (phba
->link_state
< LPFC_LINK_UP
) {
2010 spin_lock_irq(&phba
->hbalock
);
2011 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
2012 spin_unlock_irq(&phba
->hbalock
);
2013 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2017 /* Parse the FCF record from the non-embedded mailbox command */
2018 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2020 if (!new_fcf_record
) {
2021 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
,
2022 "2766 Mailbox command READ_FCF_RECORD "
2023 "failed to retrieve a FCF record.\n");
2027 /* Get the needed parameters from FCF record */
2028 lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2029 &addr_mode
, &vlan_id
);
2031 /* Log the FCF record information if turned on */
2032 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2035 /* Upload new FCF record to the failover FCF record */
2036 spin_lock_irq(&phba
->hbalock
);
2037 __lpfc_update_fcf_record(phba
, &phba
->fcf
.failover_rec
,
2038 new_fcf_record
, addr_mode
, vlan_id
,
2039 (boot_flag
? BOOT_ENABLE
: 0));
2040 spin_unlock_irq(&phba
->hbalock
);
2042 current_fcf_index
= phba
->fcf
.current_rec
.fcf_indx
;
2044 /* Unregister the current in-use FCF record */
2045 lpfc_unregister_fcf(phba
);
2047 /* Replace in-use record with the new record */
2048 memcpy(&phba
->fcf
.current_rec
, &phba
->fcf
.failover_rec
,
2049 sizeof(struct lpfc_fcf_rec
));
2051 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2052 "2783 FLOGI round robin FCF failover from FCF "
2053 "(index:x%x) to FCF (index:x%x).\n",
2055 bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
));
2058 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2059 lpfc_register_fcf(phba
);
2063 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2064 * @phba: pointer to lpfc hba data structure.
2065 * @mboxq: pointer to mailbox object.
2067 * This is the callback function of read FCF record mailbox command for
2068 * updating the eligible FCF bmask for FLOGI failure round robin FCF
2069 * failover when a new FCF event happened. If the FCF read back is
2070 * valid/available and it passes the connection list check, it updates
2071 * the bmask for the eligible FCF record for round robin failover.
2074 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2076 struct fcf_record
*new_fcf_record
;
2077 uint32_t boot_flag
, addr_mode
;
2078 uint16_t fcf_index
, next_fcf_index
;
2082 /* If link state is not up, no need to proceed */
2083 if (phba
->link_state
< LPFC_LINK_UP
)
2086 /* If FCF discovery period is over, no need to proceed */
2087 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
)
2090 /* Parse the FCF record from the non-embedded mailbox command */
2091 new_fcf_record
= lpfc_sli4_fcf_rec_mbox_parse(phba
, mboxq
,
2093 if (!new_fcf_record
) {
2094 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
2095 "2767 Mailbox command READ_FCF_RECORD "
2096 "failed to retrieve a FCF record.\n");
2100 /* Check the connection list for eligibility */
2101 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
, &boot_flag
,
2102 &addr_mode
, &vlan_id
);
2104 /* Log the FCF record information if turned on */
2105 lpfc_sli4_log_fcf_record_info(phba
, new_fcf_record
, vlan_id
,
2111 /* Update the eligible FCF record index bmask */
2112 fcf_index
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
2113 rc
= lpfc_sli4_fcf_rr_index_set(phba
, fcf_index
);
2116 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2120 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2121 * @phba: pointer to lpfc hba data structure.
2122 * @mboxq: pointer to mailbox data structure.
2124 * This function handles completion of init vpi mailbox command.
2127 lpfc_init_vpi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2129 struct lpfc_vport
*vport
= mboxq
->vport
;
2130 struct lpfc_nodelist
*ndlp
;
2131 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2133 if (mboxq
->u
.mb
.mbxStatus
) {
2134 lpfc_printf_vlog(vport
, KERN_ERR
,
2136 "2609 Init VPI mailbox failed 0x%x\n",
2137 mboxq
->u
.mb
.mbxStatus
);
2138 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2139 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2142 spin_lock_irq(shost
->host_lock
);
2143 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
2144 spin_unlock_irq(shost
->host_lock
);
2146 /* If this port is physical port or FDISC is done, do reg_vpi */
2147 if ((phba
->pport
== vport
) || (vport
->port_state
== LPFC_FDISC
)) {
2148 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
2150 lpfc_printf_vlog(vport
, KERN_ERR
,
2152 "2731 Cannot find fabric "
2153 "controller node\n");
2155 lpfc_register_new_vport(phba
, vport
, ndlp
);
2156 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2160 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2161 lpfc_initial_fdisc(vport
);
2163 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
2164 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2165 "2606 No NPIV Fabric support\n");
2167 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2172 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2173 * @vport: pointer to lpfc_vport data structure.
2175 * This function issue a init_vpi mailbox command to initialize
2176 * VPI for the vport.
2179 lpfc_issue_init_vpi(struct lpfc_vport
*vport
)
2181 LPFC_MBOXQ_t
*mboxq
;
2184 mboxq
= mempool_alloc(vport
->phba
->mbox_mem_pool
, GFP_KERNEL
);
2186 lpfc_printf_vlog(vport
, KERN_ERR
,
2187 LOG_MBOX
, "2607 Failed to allocate "
2188 "init_vpi mailbox\n");
2191 lpfc_init_vpi(vport
->phba
, mboxq
, vport
->vpi
);
2192 mboxq
->vport
= vport
;
2193 mboxq
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
2194 rc
= lpfc_sli_issue_mbox(vport
->phba
, mboxq
, MBX_NOWAIT
);
2195 if (rc
== MBX_NOT_FINISHED
) {
2196 lpfc_printf_vlog(vport
, KERN_ERR
,
2197 LOG_MBOX
, "2608 Failed to issue init_vpi mailbox\n");
2198 mempool_free(mboxq
, vport
->phba
->mbox_mem_pool
);
2203 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2204 * @phba: pointer to lpfc hba data structure.
2206 * This function loops through the list of vports on the @phba and issues an
2207 * FDISC if possible.
2210 lpfc_start_fdiscs(struct lpfc_hba
*phba
)
2212 struct lpfc_vport
**vports
;
2215 vports
= lpfc_create_vport_work_array(phba
);
2216 if (vports
!= NULL
) {
2217 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2218 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
2220 /* There are no vpi for this vport */
2221 if (vports
[i
]->vpi
> phba
->max_vpi
) {
2222 lpfc_vport_set_state(vports
[i
],
2226 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2227 lpfc_vport_set_state(vports
[i
],
2231 if (vports
[i
]->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
) {
2232 lpfc_issue_init_vpi(vports
[i
]);
2235 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
2236 lpfc_initial_fdisc(vports
[i
]);
2238 lpfc_vport_set_state(vports
[i
],
2239 FC_VPORT_NO_FABRIC_SUPP
);
2240 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
2243 "Fabric support\n");
2247 lpfc_destroy_vport_work_array(phba
, vports
);
2251 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2253 struct lpfc_dmabuf
*dmabuf
= mboxq
->context1
;
2254 struct lpfc_vport
*vport
= mboxq
->vport
;
2255 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2257 if (mboxq
->u
.mb
.mbxStatus
) {
2258 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2259 "2018 REG_VFI mbxStatus error x%x "
2261 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
2262 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2263 /* FLOGI failed, use loop map to make discovery list */
2264 lpfc_disc_list_loopmap(vport
);
2265 /* Start discovery */
2266 lpfc_disc_start(vport
);
2269 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2272 /* The VPI is implicitly registered when the VFI is registered */
2273 spin_lock_irq(shost
->host_lock
);
2274 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2275 vport
->fc_flag
|= FC_VFI_REGISTERED
;
2276 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2277 spin_unlock_irq(shost
->host_lock
);
2279 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
2280 lpfc_start_fdiscs(phba
);
2281 lpfc_do_scr_ns_plogi(phba
, vport
);
2285 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2286 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
2292 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2294 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2295 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
2296 struct lpfc_vport
*vport
= pmb
->vport
;
2299 /* Check for error */
2300 if (mb
->mbxStatus
) {
2301 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
2302 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2303 "0319 READ_SPARAM mbxStatus error x%x "
2305 mb
->mbxStatus
, vport
->port_state
);
2306 lpfc_linkdown(phba
);
2310 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
2311 sizeof (struct serv_parm
));
2312 if (phba
->cfg_soft_wwnn
)
2313 u64_to_wwn(phba
->cfg_soft_wwnn
,
2314 vport
->fc_sparam
.nodeName
.u
.wwn
);
2315 if (phba
->cfg_soft_wwpn
)
2316 u64_to_wwn(phba
->cfg_soft_wwpn
,
2317 vport
->fc_sparam
.portName
.u
.wwn
);
2318 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
2319 sizeof(vport
->fc_nodename
));
2320 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
2321 sizeof(vport
->fc_portname
));
2322 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
2323 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
2324 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
2327 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2329 mempool_free(pmb
, phba
->mbox_mem_pool
);
2333 pmb
->context1
= NULL
;
2334 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2336 lpfc_issue_clear_la(phba
, vport
);
2337 mempool_free(pmb
, phba
->mbox_mem_pool
);
2342 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, READ_LA_VAR
*la
)
2344 struct lpfc_vport
*vport
= phba
->pport
;
2345 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
= NULL
;
2347 struct lpfc_dmabuf
*mp
;
2349 struct fcf_record
*fcf_record
;
2351 spin_lock_irq(&phba
->hbalock
);
2352 switch (la
->UlnkSpeed
) {
2354 phba
->fc_linkspeed
= LA_1GHZ_LINK
;
2357 phba
->fc_linkspeed
= LA_2GHZ_LINK
;
2360 phba
->fc_linkspeed
= LA_4GHZ_LINK
;
2363 phba
->fc_linkspeed
= LA_8GHZ_LINK
;
2366 phba
->fc_linkspeed
= LA_10GHZ_LINK
;
2369 phba
->fc_linkspeed
= LA_UNKNW_LINK
;
2373 phba
->fc_topology
= la
->topology
;
2374 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
2376 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2377 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
2379 /* if npiv is enabled and this adapter supports npiv log
2380 * a message that npiv is not supported in this topology
2382 if (phba
->cfg_enable_npiv
&& phba
->max_vpi
)
2383 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2384 "1309 Link Up Event npiv not supported in loop "
2386 /* Get Loop Map information */
2388 vport
->fc_flag
|= FC_LBIT
;
2390 vport
->fc_myDID
= la
->granted_AL_PA
;
2391 i
= la
->un
.lilpBde64
.tus
.f
.bdeSize
;
2394 phba
->alpa_map
[0] = 0;
2396 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
2407 numalpa
= phba
->alpa_map
[0];
2409 while (j
< numalpa
) {
2410 memset(un
.pamap
, 0, 16);
2411 for (k
= 1; j
< numalpa
; k
++) {
2413 phba
->alpa_map
[j
+ 1];
2418 /* Link Up Event ALPA map */
2419 lpfc_printf_log(phba
,
2422 "1304 Link Up Event "
2423 "ALPA map Data: x%x "
2425 un
.pa
.wd1
, un
.pa
.wd2
,
2426 un
.pa
.wd3
, un
.pa
.wd4
);
2431 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
2432 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
2433 (phba
->sli_rev
== 3))
2434 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
2436 vport
->fc_myDID
= phba
->fc_pref_DID
;
2437 vport
->fc_flag
|= FC_LBIT
;
2439 spin_unlock_irq(&phba
->hbalock
);
2442 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2446 rc
= lpfc_read_sparam(phba
, sparam_mbox
, 0);
2448 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
2451 sparam_mbox
->vport
= vport
;
2452 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
2453 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
2454 if (rc
== MBX_NOT_FINISHED
) {
2455 mp
= (struct lpfc_dmabuf
*) sparam_mbox
->context1
;
2456 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2458 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
2462 if (!(phba
->hba_flag
& HBA_FCOE_SUPPORT
)) {
2463 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2466 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
2467 lpfc_config_link(phba
, cfglink_mbox
);
2468 cfglink_mbox
->vport
= vport
;
2469 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
2470 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
2471 if (rc
== MBX_NOT_FINISHED
) {
2472 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
2476 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
2478 * Add the driver's default FCF record at FCF index 0 now. This
2479 * is phase 1 implementation that support FCF index 0 and driver
2482 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
2483 fcf_record
= kzalloc(sizeof(struct fcf_record
),
2485 if (unlikely(!fcf_record
)) {
2486 lpfc_printf_log(phba
, KERN_ERR
,
2488 "2554 Could not allocate memmory for "
2494 lpfc_sli4_build_dflt_fcf_record(phba
, fcf_record
,
2495 LPFC_FCOE_FCF_DEF_INDEX
);
2496 rc
= lpfc_sli4_add_fcf_record(phba
, fcf_record
);
2498 lpfc_printf_log(phba
, KERN_ERR
,
2500 "2013 Could not manually add FCF "
2501 "record 0, status %d\n", rc
);
2509 * The driver is expected to do FIP/FCF. Call the port
2510 * and get the FCF Table.
2512 spin_lock_irq(&phba
->hbalock
);
2513 if (phba
->hba_flag
& FCF_DISC_INPROGRESS
) {
2514 spin_unlock_irq(&phba
->hbalock
);
2517 /* This is the initial FCF discovery scan */
2518 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
2519 spin_unlock_irq(&phba
->hbalock
);
2520 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
2521 "2778 Start FCF table scan at linkup\n");
2523 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
2524 LPFC_FCOE_FCF_GET_FIRST
);
2526 spin_lock_irq(&phba
->hbalock
);
2527 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
2528 spin_unlock_irq(&phba
->hbalock
);
2535 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2536 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2537 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2538 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
2539 lpfc_issue_clear_la(phba
, vport
);
2544 lpfc_enable_la(struct lpfc_hba
*phba
)
2547 struct lpfc_sli
*psli
= &phba
->sli
;
2548 spin_lock_irq(&phba
->hbalock
);
2549 psli
->sli_flag
|= LPFC_PROCESS_LA
;
2550 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
2551 control
= readl(phba
->HCregaddr
);
2552 control
|= HC_LAINT_ENA
;
2553 writel(control
, phba
->HCregaddr
);
2554 readl(phba
->HCregaddr
); /* flush */
2556 spin_unlock_irq(&phba
->hbalock
);
2560 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
2562 lpfc_linkdown(phba
);
2563 lpfc_enable_la(phba
);
2564 lpfc_unregister_unused_fcf(phba
);
2565 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2570 * This routine handles processing a READ_LA mailbox
2571 * command upon completion. It is setup in the LPFC_MBOXQ
2572 * as the completion routine when the command is
2573 * handed off to the SLI layer.
2576 lpfc_mbx_cmpl_read_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2578 struct lpfc_vport
*vport
= pmb
->vport
;
2579 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2581 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2582 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2584 /* Unblock ELS traffic */
2585 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
2586 /* Check for error */
2587 if (mb
->mbxStatus
) {
2588 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
2589 "1307 READ_LA mbox error x%x state x%x\n",
2590 mb
->mbxStatus
, vport
->port_state
);
2591 lpfc_mbx_issue_link_down(phba
);
2592 phba
->link_state
= LPFC_HBA_ERROR
;
2593 goto lpfc_mbx_cmpl_read_la_free_mbuf
;
2596 la
= (READ_LA_VAR
*) &pmb
->u
.mb
.un
.varReadLA
;
2598 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
2600 spin_lock_irq(shost
->host_lock
);
2602 vport
->fc_flag
|= FC_BYPASSED_MODE
;
2604 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
2605 spin_unlock_irq(shost
->host_lock
);
2607 if ((phba
->fc_eventTag
< la
->eventTag
) ||
2608 (phba
->fc_eventTag
== la
->eventTag
)) {
2609 phba
->fc_stat
.LinkMultiEvent
++;
2610 if (la
->attType
== AT_LINK_UP
)
2611 if (phba
->fc_eventTag
!= 0)
2612 lpfc_linkdown(phba
);
2615 phba
->fc_eventTag
= la
->eventTag
;
2616 spin_lock_irq(&phba
->hbalock
);
2618 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
2620 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
2621 spin_unlock_irq(&phba
->hbalock
);
2623 phba
->link_events
++;
2624 if (la
->attType
== AT_LINK_UP
&& (!la
->mm
)) {
2625 phba
->fc_stat
.LinkUp
++;
2626 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
2627 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2628 "1306 Link Up Event in loop back mode "
2629 "x%x received Data: x%x x%x x%x x%x\n",
2630 la
->eventTag
, phba
->fc_eventTag
,
2631 la
->granted_AL_PA
, la
->UlnkSpeed
,
2634 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2635 "1303 Link Up Event x%x received "
2636 "Data: x%x x%x x%x x%x x%x x%x %d\n",
2637 la
->eventTag
, phba
->fc_eventTag
,
2638 la
->granted_AL_PA
, la
->UlnkSpeed
,
2641 phba
->wait_4_mlo_maint_flg
);
2643 lpfc_mbx_process_link_up(phba
, la
);
2644 } else if (la
->attType
== AT_LINK_DOWN
) {
2645 phba
->fc_stat
.LinkDown
++;
2646 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
2647 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2648 "1308 Link Down Event in loop back mode "
2650 "Data: x%x x%x x%x\n",
2651 la
->eventTag
, phba
->fc_eventTag
,
2652 phba
->pport
->port_state
, vport
->fc_flag
);
2655 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2656 "1305 Link Down Event x%x received "
2657 "Data: x%x x%x x%x x%x x%x\n",
2658 la
->eventTag
, phba
->fc_eventTag
,
2659 phba
->pport
->port_state
, vport
->fc_flag
,
2662 lpfc_mbx_issue_link_down(phba
);
2664 if (la
->mm
&& la
->attType
== AT_LINK_UP
) {
2665 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
2666 phba
->fc_stat
.LinkDown
++;
2667 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2668 "1312 Link Down Event x%x received "
2669 "Data: x%x x%x x%x\n",
2670 la
->eventTag
, phba
->fc_eventTag
,
2671 phba
->pport
->port_state
, vport
->fc_flag
);
2672 lpfc_mbx_issue_link_down(phba
);
2674 lpfc_enable_la(phba
);
2676 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2677 "1310 Menlo Maint Mode Link up Event x%x rcvd "
2678 "Data: x%x x%x x%x\n",
2679 la
->eventTag
, phba
->fc_eventTag
,
2680 phba
->pport
->port_state
, vport
->fc_flag
);
2682 * The cmnd that triggered this will be waiting for this
2685 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
2686 if (phba
->wait_4_mlo_maint_flg
) {
2687 phba
->wait_4_mlo_maint_flg
= 0;
2688 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
2694 lpfc_issue_clear_la(phba
, vport
);
2695 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
2696 "1311 fa %d\n", la
->fa
);
2699 lpfc_mbx_cmpl_read_la_free_mbuf
:
2700 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2702 mempool_free(pmb
, phba
->mbox_mem_pool
);
2707 * This routine handles processing a REG_LOGIN mailbox
2708 * command upon completion. It is setup in the LPFC_MBOXQ
2709 * as the completion routine when the command is
2710 * handed off to the SLI layer.
2713 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2715 struct lpfc_vport
*vport
= pmb
->vport
;
2716 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2717 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2719 pmb
->context1
= NULL
;
2721 /* Good status, call state machine */
2722 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
2723 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2725 mempool_free(pmb
, phba
->mbox_mem_pool
);
2726 /* decrement the node reference count held for this callback
2735 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2737 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2738 struct lpfc_vport
*vport
= pmb
->vport
;
2739 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2741 switch (mb
->mbxStatus
) {
2744 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2745 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
2748 /* If VPI is busy, reset the HBA */
2750 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
2751 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
2752 vport
->vpi
, mb
->mbxStatus
);
2753 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
2754 lpfc_workq_post_event(phba
, NULL
, NULL
,
2755 LPFC_EVT_RESET_HBA
);
2757 spin_lock_irq(shost
->host_lock
);
2758 vport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2759 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2760 spin_unlock_irq(shost
->host_lock
);
2761 vport
->unreg_vpi_cmpl
= VPORT_OK
;
2762 mempool_free(pmb
, phba
->mbox_mem_pool
);
2764 * This shost reference might have been taken at the beginning of
2765 * lpfc_vport_delete()
2767 if ((vport
->load_flag
& FC_UNLOADING
) && (vport
!= phba
->pport
))
2768 scsi_host_put(shost
);
2772 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
2774 struct lpfc_hba
*phba
= vport
->phba
;
2778 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2782 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
2783 mbox
->vport
= vport
;
2784 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
2785 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2786 if (rc
== MBX_NOT_FINISHED
) {
2787 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
2788 "1800 Could not issue unreg_vpi\n");
2789 mempool_free(mbox
, phba
->mbox_mem_pool
);
2790 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
2797 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2799 struct lpfc_vport
*vport
= pmb
->vport
;
2800 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2801 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2803 switch (mb
->mbxStatus
) {
2807 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2808 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
2810 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2811 spin_lock_irq(shost
->host_lock
);
2812 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2813 spin_unlock_irq(shost
->host_lock
);
2814 vport
->fc_myDID
= 0;
2818 spin_lock_irq(shost
->host_lock
);
2819 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2820 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
2821 spin_unlock_irq(shost
->host_lock
);
2822 vport
->num_disc_nodes
= 0;
2823 /* go thru NPR list and issue ELS PLOGIs */
2824 if (vport
->fc_npr_cnt
)
2825 lpfc_els_disc_plogi(vport
);
2827 if (!vport
->num_disc_nodes
) {
2828 spin_lock_irq(shost
->host_lock
);
2829 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2830 spin_unlock_irq(shost
->host_lock
);
2831 lpfc_can_disctmo(vport
);
2833 vport
->port_state
= LPFC_VPORT_READY
;
2836 mempool_free(pmb
, phba
->mbox_mem_pool
);
2841 * lpfc_create_static_vport - Read HBA config region to create static vports.
2842 * @phba: pointer to lpfc hba data structure.
2844 * This routine issue a DUMP mailbox command for config region 22 to get
2845 * the list of static vports to be created. The function create vports
2846 * based on the information returned from the HBA.
2849 lpfc_create_static_vport(struct lpfc_hba
*phba
)
2851 LPFC_MBOXQ_t
*pmb
= NULL
;
2853 struct static_vport_info
*vport_info
;
2855 struct fc_vport_identifiers vport_id
;
2856 struct fc_vport
*new_fc_vport
;
2857 struct Scsi_Host
*shost
;
2858 struct lpfc_vport
*vport
;
2859 uint16_t offset
= 0;
2860 uint8_t *vport_buff
;
2861 struct lpfc_dmabuf
*mp
;
2862 uint32_t byte_count
= 0;
2864 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2866 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2867 "0542 lpfc_create_static_vport failed to"
2868 " allocate mailbox memory\n");
2874 vport_info
= kzalloc(sizeof(struct static_vport_info
), GFP_KERNEL
);
2876 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2877 "0543 lpfc_create_static_vport failed to"
2878 " allocate vport_info\n");
2879 mempool_free(pmb
, phba
->mbox_mem_pool
);
2883 vport_buff
= (uint8_t *) vport_info
;
2885 if (lpfc_dump_static_vport(phba
, pmb
, offset
))
2888 pmb
->vport
= phba
->pport
;
2889 rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
, LPFC_MBOX_TMO
);
2891 if ((rc
!= MBX_SUCCESS
) || mb
->mbxStatus
) {
2892 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2893 "0544 lpfc_create_static_vport failed to"
2894 " issue dump mailbox command ret 0x%x "
2900 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2901 byte_count
= pmb
->u
.mqe
.un
.mb_words
[5];
2902 mp
= (struct lpfc_dmabuf
*) pmb
->context2
;
2903 if (byte_count
> sizeof(struct static_vport_info
) -
2905 byte_count
= sizeof(struct static_vport_info
)
2907 memcpy(vport_buff
+ offset
, mp
->virt
, byte_count
);
2908 offset
+= byte_count
;
2910 if (mb
->un
.varDmp
.word_cnt
>
2911 sizeof(struct static_vport_info
) - offset
)
2912 mb
->un
.varDmp
.word_cnt
=
2913 sizeof(struct static_vport_info
)
2915 byte_count
= mb
->un
.varDmp
.word_cnt
;
2916 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
2917 vport_buff
+ offset
,
2920 offset
+= byte_count
;
2923 } while (byte_count
&&
2924 offset
< sizeof(struct static_vport_info
));
2927 if ((le32_to_cpu(vport_info
->signature
) != VPORT_INFO_SIG
) ||
2928 ((le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
)
2929 != VPORT_INFO_REV
)) {
2930 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2931 "0545 lpfc_create_static_vport bad"
2932 " information header 0x%x 0x%x\n",
2933 le32_to_cpu(vport_info
->signature
),
2934 le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
);
2939 shost
= lpfc_shost_from_vport(phba
->pport
);
2941 for (i
= 0; i
< MAX_STATIC_VPORT_COUNT
; i
++) {
2942 memset(&vport_id
, 0, sizeof(vport_id
));
2943 vport_id
.port_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwpn
);
2944 vport_id
.node_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwnn
);
2945 if (!vport_id
.port_name
|| !vport_id
.node_name
)
2948 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
2949 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
2950 vport_id
.disable
= false;
2951 new_fc_vport
= fc_vport_create(shost
, 0, &vport_id
);
2953 if (!new_fc_vport
) {
2954 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2955 "0546 lpfc_create_static_vport failed to"
2960 vport
= *(struct lpfc_vport
**)new_fc_vport
->dd_data
;
2961 vport
->vport_flag
|= STATIC_VPORT
;
2966 if (rc
!= MBX_TIMEOUT
) {
2967 if (pmb
->context2
) {
2968 mp
= (struct lpfc_dmabuf
*) pmb
->context2
;
2969 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2972 mempool_free(pmb
, phba
->mbox_mem_pool
);
2979 * This routine handles processing a Fabric REG_LOGIN mailbox
2980 * command upon completion. It is setup in the LPFC_MBOXQ
2981 * as the completion routine when the command is
2982 * handed off to the SLI layer.
2985 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2987 struct lpfc_vport
*vport
= pmb
->vport
;
2988 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2989 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2990 struct lpfc_nodelist
*ndlp
;
2992 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2993 pmb
->context1
= NULL
;
2994 pmb
->context2
= NULL
;
2995 if (mb
->mbxStatus
) {
2996 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2997 "0258 Register Fabric login error: 0x%x\n",
2999 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3001 mempool_free(pmb
, phba
->mbox_mem_pool
);
3003 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
3004 /* FLOGI failed, use loop map to make discovery list */
3005 lpfc_disc_list_loopmap(vport
);
3007 /* Start discovery */
3008 lpfc_disc_start(vport
);
3009 /* Decrement the reference count to ndlp after the
3010 * reference to the ndlp are done.
3016 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3017 /* Decrement the reference count to ndlp after the reference
3018 * to the ndlp are done.
3024 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3025 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
3026 ndlp
->nlp_type
|= NLP_FABRIC
;
3027 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3029 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
3030 /* when physical port receive logo donot start
3031 * vport discovery */
3032 if (!(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
3033 lpfc_start_fdiscs(phba
);
3035 vport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
3036 lpfc_do_scr_ns_plogi(phba
, vport
);
3039 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3041 mempool_free(pmb
, phba
->mbox_mem_pool
);
3043 /* Drop the reference count from the mbox at the end after
3044 * all the current reference to the ndlp have been done.
3051 * This routine handles processing a NameServer REG_LOGIN mailbox
3052 * command upon completion. It is setup in the LPFC_MBOXQ
3053 * as the completion routine when the command is
3054 * handed off to the SLI layer.
3057 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3059 MAILBOX_t
*mb
= &pmb
->u
.mb
;
3060 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3061 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3062 struct lpfc_vport
*vport
= pmb
->vport
;
3064 if (mb
->mbxStatus
) {
3066 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3067 "0260 Register NameServer error: 0x%x\n",
3069 /* decrement the node reference count held for this
3070 * callback function.
3073 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3075 mempool_free(pmb
, phba
->mbox_mem_pool
);
3077 /* If no other thread is using the ndlp, free it */
3078 lpfc_nlp_not_used(ndlp
);
3080 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
3082 * RegLogin failed, use loop map to make discovery
3085 lpfc_disc_list_loopmap(vport
);
3087 /* Start discovery */
3088 lpfc_disc_start(vport
);
3091 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
3095 pmb
->context1
= NULL
;
3097 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
3098 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
3099 ndlp
->nlp_type
|= NLP_FABRIC
;
3100 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3102 if (vport
->port_state
< LPFC_VPORT_READY
) {
3103 /* Link up discovery requires Fabric registration. */
3104 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, 0); /* Do this first! */
3105 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
3106 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
3107 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
3108 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
3110 /* Issue SCR just before NameServer GID_FT Query */
3111 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
3114 vport
->fc_ns_retry
= 0;
3115 /* Good status, issue CT Request to NameServer */
3116 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0)) {
3117 /* Cannot issue NameServer Query, so finish up discovery */
3121 /* decrement the node reference count held for this
3122 * callback function.
3125 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3127 mempool_free(pmb
, phba
->mbox_mem_pool
);
3133 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3135 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3136 struct fc_rport
*rport
;
3137 struct lpfc_rport_data
*rdata
;
3138 struct fc_rport_identifiers rport_ids
;
3139 struct lpfc_hba
*phba
= vport
->phba
;
3141 /* Remote port has reappeared. Re-register w/ FC transport */
3142 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
3143 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
3144 rport_ids
.port_id
= ndlp
->nlp_DID
;
3145 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
3148 * We leave our node pointer in rport->dd_data when we unregister a
3149 * FCP target port. But fc_remote_port_add zeros the space to which
3150 * rport->dd_data points. So, if we're reusing a previously
3151 * registered port, drop the reference that we took the last time we
3152 * registered the port.
3154 if (ndlp
->rport
&& ndlp
->rport
->dd_data
&&
3155 ((struct lpfc_rport_data
*) ndlp
->rport
->dd_data
)->pnode
== ndlp
)
3158 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
3159 "rport add: did:x%x flg:x%x type x%x",
3160 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
3162 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
3163 if (!rport
|| !get_device(&rport
->dev
)) {
3164 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
3165 "Warning: fc_remote_port_add failed\n");
3169 /* initialize static port data */
3170 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
3171 rport
->supported_classes
= ndlp
->nlp_class_sup
;
3172 rdata
= rport
->dd_data
;
3173 rdata
->pnode
= lpfc_nlp_get(ndlp
);
3175 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
3176 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
3177 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
3178 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
3181 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
3182 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
3184 if ((rport
->scsi_target_id
!= -1) &&
3185 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
3186 ndlp
->nlp_sid
= rport
->scsi_target_id
;
3192 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
3194 struct fc_rport
*rport
= ndlp
->rport
;
3196 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
3197 "rport delete: did:x%x flg:x%x type x%x",
3198 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
3200 fc_remote_port_delete(rport
);
3206 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
3208 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3210 spin_lock_irq(shost
->host_lock
);
3212 case NLP_STE_UNUSED_NODE
:
3213 vport
->fc_unused_cnt
+= count
;
3215 case NLP_STE_PLOGI_ISSUE
:
3216 vport
->fc_plogi_cnt
+= count
;
3218 case NLP_STE_ADISC_ISSUE
:
3219 vport
->fc_adisc_cnt
+= count
;
3221 case NLP_STE_REG_LOGIN_ISSUE
:
3222 vport
->fc_reglogin_cnt
+= count
;
3224 case NLP_STE_PRLI_ISSUE
:
3225 vport
->fc_prli_cnt
+= count
;
3227 case NLP_STE_UNMAPPED_NODE
:
3228 vport
->fc_unmap_cnt
+= count
;
3230 case NLP_STE_MAPPED_NODE
:
3231 vport
->fc_map_cnt
+= count
;
3233 case NLP_STE_NPR_NODE
:
3234 vport
->fc_npr_cnt
+= count
;
3237 spin_unlock_irq(shost
->host_lock
);
3241 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3242 int old_state
, int new_state
)
3244 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3246 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
3247 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
3248 ndlp
->nlp_type
|= NLP_FC_NODE
;
3250 if (new_state
== NLP_STE_MAPPED_NODE
)
3251 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
3252 if (new_state
== NLP_STE_NPR_NODE
)
3253 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
3255 /* Transport interface */
3256 if (ndlp
->rport
&& (old_state
== NLP_STE_MAPPED_NODE
||
3257 old_state
== NLP_STE_UNMAPPED_NODE
)) {
3258 vport
->phba
->nport_event_cnt
++;
3259 lpfc_unregister_remote_port(ndlp
);
3262 if (new_state
== NLP_STE_MAPPED_NODE
||
3263 new_state
== NLP_STE_UNMAPPED_NODE
) {
3264 vport
->phba
->nport_event_cnt
++;
3266 * Tell the fc transport about the port, if we haven't
3267 * already. If we have, and it's a scsi entity, be
3268 * sure to unblock any attached scsi devices
3270 lpfc_register_remote_port(vport
, ndlp
);
3272 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
3273 (vport
->stat_data_enabled
)) {
3275 * A new target is discovered, if there is no buffer for
3276 * statistical data collection allocate buffer.
3278 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
3279 sizeof(struct lpfc_scsicmd_bkt
),
3282 if (!ndlp
->lat_data
)
3283 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
3284 "0286 lpfc_nlp_state_cleanup failed to "
3285 "allocate statistical data buffer DID "
3286 "0x%x\n", ndlp
->nlp_DID
);
3289 * if we added to Mapped list, but the remote port
3290 * registration failed or assigned a target id outside
3291 * our presentable range - move the node to the
3294 if (new_state
== NLP_STE_MAPPED_NODE
&&
3296 ndlp
->rport
->scsi_target_id
== -1 ||
3297 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
3298 spin_lock_irq(shost
->host_lock
);
3299 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
3300 spin_unlock_irq(shost
->host_lock
);
3301 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
3306 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
3308 static char *states
[] = {
3309 [NLP_STE_UNUSED_NODE
] = "UNUSED",
3310 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
3311 [NLP_STE_ADISC_ISSUE
] = "ADISC",
3312 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
3313 [NLP_STE_PRLI_ISSUE
] = "PRLI",
3314 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
3315 [NLP_STE_MAPPED_NODE
] = "MAPPED",
3316 [NLP_STE_NPR_NODE
] = "NPR",
3319 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
3320 strlcpy(buffer
, states
[state
], size
);
3322 snprintf(buffer
, size
, "unknown (%d)", state
);
3327 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3330 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3331 int old_state
= ndlp
->nlp_state
;
3332 char name1
[16], name2
[16];
3334 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3335 "0904 NPort state transition x%06x, %s -> %s\n",
3337 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
3338 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
3340 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
3341 "node statechg did:x%x old:%d ste:%d",
3342 ndlp
->nlp_DID
, old_state
, state
);
3344 if (old_state
== NLP_STE_NPR_NODE
&&
3345 state
!= NLP_STE_NPR_NODE
)
3346 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3347 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
3348 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
3349 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
3352 if (list_empty(&ndlp
->nlp_listp
)) {
3353 spin_lock_irq(shost
->host_lock
);
3354 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
3355 spin_unlock_irq(shost
->host_lock
);
3356 } else if (old_state
)
3357 lpfc_nlp_counters(vport
, old_state
, -1);
3359 ndlp
->nlp_state
= state
;
3360 lpfc_nlp_counters(vport
, state
, 1);
3361 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
3365 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3367 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3369 if (list_empty(&ndlp
->nlp_listp
)) {
3370 spin_lock_irq(shost
->host_lock
);
3371 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
3372 spin_unlock_irq(shost
->host_lock
);
3377 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3379 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3381 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3382 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
3383 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
3384 spin_lock_irq(shost
->host_lock
);
3385 list_del_init(&ndlp
->nlp_listp
);
3386 spin_unlock_irq(shost
->host_lock
);
3387 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
3388 NLP_STE_UNUSED_NODE
);
3392 lpfc_disable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3394 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3395 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
3396 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
3397 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
3398 NLP_STE_UNUSED_NODE
);
3401 * lpfc_initialize_node - Initialize all fields of node object
3402 * @vport: Pointer to Virtual Port object.
3403 * @ndlp: Pointer to FC node object.
3404 * @did: FC_ID of the node.
3406 * This function is always called when node object need to be initialized.
3407 * It initializes all the fields of the node object. Although the reference
3408 * to phba from @ndlp can be obtained indirectly through it's reference to
3409 * @vport, a direct reference to phba is taken here by @ndlp. This is due
3410 * to the life-span of the @ndlp might go beyond the existence of @vport as
3411 * the final release of ndlp is determined by its reference count. And, the
3412 * operation on @ndlp needs the reference to phba.
3415 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3418 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
3419 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
3420 init_timer(&ndlp
->nlp_delayfunc
);
3421 ndlp
->nlp_delayfunc
.function
= lpfc_els_retry_delay
;
3422 ndlp
->nlp_delayfunc
.data
= (unsigned long)ndlp
;
3423 ndlp
->nlp_DID
= did
;
3424 ndlp
->vport
= vport
;
3425 ndlp
->phba
= vport
->phba
;
3426 ndlp
->nlp_sid
= NLP_NO_SID
;
3427 kref_init(&ndlp
->kref
);
3428 NLP_INT_NODE_ACT(ndlp
);
3429 atomic_set(&ndlp
->cmd_pending
, 0);
3430 ndlp
->cmd_qdepth
= LPFC_MAX_TGT_QDEPTH
;
3433 struct lpfc_nodelist
*
3434 lpfc_enable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3437 struct lpfc_hba
*phba
= vport
->phba
;
3439 unsigned long flags
;
3444 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
3445 /* The ndlp should not be in memory free mode */
3446 if (NLP_CHK_FREE_REQ(ndlp
)) {
3447 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3448 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3449 "0277 lpfc_enable_node: ndlp:x%p "
3450 "usgmap:x%x refcnt:%d\n",
3451 (void *)ndlp
, ndlp
->nlp_usg_map
,
3452 atomic_read(&ndlp
->kref
.refcount
));
3455 /* The ndlp should not already be in active mode */
3456 if (NLP_CHK_NODE_ACT(ndlp
)) {
3457 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3458 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3459 "0278 lpfc_enable_node: ndlp:x%p "
3460 "usgmap:x%x refcnt:%d\n",
3461 (void *)ndlp
, ndlp
->nlp_usg_map
,
3462 atomic_read(&ndlp
->kref
.refcount
));
3466 /* Keep the original DID */
3467 did
= ndlp
->nlp_DID
;
3469 /* re-initialize ndlp except of ndlp linked list pointer */
3470 memset((((char *)ndlp
) + sizeof (struct list_head
)), 0,
3471 sizeof (struct lpfc_nodelist
) - sizeof (struct list_head
));
3472 lpfc_initialize_node(vport
, ndlp
, did
);
3474 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
3476 if (state
!= NLP_STE_UNUSED_NODE
)
3477 lpfc_nlp_set_state(vport
, ndlp
, state
);
3479 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
3480 "node enable: did:x%x",
3481 ndlp
->nlp_DID
, 0, 0);
3486 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3489 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
3490 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
3491 * the ndlp from the vport. The ndlp marked as UNUSED on the list
3492 * until ALL other outstanding threads have completed. We check
3493 * that the ndlp not already in the UNUSED state before we proceed.
3495 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
3497 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3503 * Start / ReStart rescue timer for Discovery / RSCN handling
3506 lpfc_set_disctmo(struct lpfc_vport
*vport
)
3508 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3509 struct lpfc_hba
*phba
= vport
->phba
;
3512 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
3513 /* For FAN, timeout should be greater than edtov */
3514 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
3516 /* Normal discovery timeout should be > than ELS/CT timeout
3517 * FC spec states we need 3 * ratov for CT requests
3519 tmo
= ((phba
->fc_ratov
* 3) + 3);
3523 if (!timer_pending(&vport
->fc_disctmo
)) {
3524 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3525 "set disc timer: tmo:x%x state:x%x flg:x%x",
3526 tmo
, vport
->port_state
, vport
->fc_flag
);
3529 mod_timer(&vport
->fc_disctmo
, jiffies
+ HZ
* tmo
);
3530 spin_lock_irq(shost
->host_lock
);
3531 vport
->fc_flag
|= FC_DISC_TMO
;
3532 spin_unlock_irq(shost
->host_lock
);
3534 /* Start Discovery Timer state <hba_state> */
3535 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3536 "0247 Start Discovery Timer state x%x "
3537 "Data: x%x x%lx x%x x%x\n",
3538 vport
->port_state
, tmo
,
3539 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
3540 vport
->fc_adisc_cnt
);
3546 * Cancel rescue timer for Discovery / RSCN handling
3549 lpfc_can_disctmo(struct lpfc_vport
*vport
)
3551 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3552 unsigned long iflags
;
3554 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3555 "can disc timer: state:x%x rtry:x%x flg:x%x",
3556 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
3558 /* Turn off discovery timer if its running */
3559 if (vport
->fc_flag
& FC_DISC_TMO
) {
3560 spin_lock_irqsave(shost
->host_lock
, iflags
);
3561 vport
->fc_flag
&= ~FC_DISC_TMO
;
3562 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
3563 del_timer_sync(&vport
->fc_disctmo
);
3564 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
3565 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
3566 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
3569 /* Cancel Discovery Timer state <hba_state> */
3570 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3571 "0248 Cancel Discovery Timer state x%x "
3572 "Data: x%x x%x x%x\n",
3573 vport
->port_state
, vport
->fc_flag
,
3574 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
3579 * Check specified ring for outstanding IOCB on the SLI queue
3580 * Return true if iocb matches the specified nport
3583 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
3584 struct lpfc_sli_ring
*pring
,
3585 struct lpfc_iocbq
*iocb
,
3586 struct lpfc_nodelist
*ndlp
)
3588 struct lpfc_sli
*psli
= &phba
->sli
;
3589 IOCB_t
*icmd
= &iocb
->iocb
;
3590 struct lpfc_vport
*vport
= ndlp
->vport
;
3592 if (iocb
->vport
!= vport
)
3595 if (pring
->ringno
== LPFC_ELS_RING
) {
3596 switch (icmd
->ulpCommand
) {
3597 case CMD_GEN_REQUEST64_CR
:
3598 if (iocb
->context_un
.ndlp
== ndlp
)
3600 case CMD_ELS_REQUEST64_CR
:
3601 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
3603 case CMD_XMIT_ELS_RSP64_CX
:
3604 if (iocb
->context1
== (uint8_t *) ndlp
)
3607 } else if (pring
->ringno
== psli
->extra_ring
) {
3609 } else if (pring
->ringno
== psli
->fcp_ring
) {
3610 /* Skip match check if waiting to relogin to FCP target */
3611 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3612 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
3615 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
3618 } else if (pring
->ringno
== psli
->next_ring
) {
3625 * Free resources / clean up outstanding I/Os
3626 * associated with nlp_rpi in the LPFC_NODELIST entry.
3629 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
3631 LIST_HEAD(completions
);
3632 struct lpfc_sli
*psli
;
3633 struct lpfc_sli_ring
*pring
;
3634 struct lpfc_iocbq
*iocb
, *next_iocb
;
3637 lpfc_fabric_abort_nport(ndlp
);
3640 * Everything that matches on txcmplq will be returned
3641 * by firmware with a no rpi error.
3644 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
3645 /* Now process each ring */
3646 for (i
= 0; i
< psli
->num_rings
; i
++) {
3647 pring
= &psli
->ring
[i
];
3649 spin_lock_irq(&phba
->hbalock
);
3650 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
,
3653 * Check to see if iocb matches the nport we are
3656 if ((lpfc_check_sli_ndlp(phba
, pring
, iocb
,
3658 /* It matches, so deque and call compl
3660 list_move_tail(&iocb
->list
,
3665 spin_unlock_irq(&phba
->hbalock
);
3669 /* Cancel all the IOCBs from the completions list */
3670 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3677 * Free rpi associated with LPFC_NODELIST entry.
3678 * This routine is called from lpfc_freenode(), when we are removing
3679 * a LPFC_NODELIST entry. It is also called if the driver initiates a
3680 * LOGO that completes successfully, and we are waiting to PLOGI back
3681 * to the remote NPort. In addition, it is called after we receive
3682 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
3683 * we are waiting to PLOGI back to the remote NPort.
3686 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3688 struct lpfc_hba
*phba
= vport
->phba
;
3692 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
3693 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3695 lpfc_unreg_login(phba
, vport
->vpi
, ndlp
->nlp_rpi
, mbox
);
3696 mbox
->vport
= vport
;
3697 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3698 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3699 if (rc
== MBX_NOT_FINISHED
)
3700 mempool_free(mbox
, phba
->mbox_mem_pool
);
3702 lpfc_no_rpi(phba
, ndlp
);
3704 ndlp
->nlp_flag
&= ~NLP_RPI_VALID
;
3705 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3712 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
3713 * @phba: pointer to lpfc hba data structure.
3715 * This routine is invoked to unregister all the currently registered RPIs
3719 lpfc_unreg_hba_rpis(struct lpfc_hba
*phba
)
3721 struct lpfc_vport
**vports
;
3722 struct lpfc_nodelist
*ndlp
;
3723 struct Scsi_Host
*shost
;
3726 vports
= lpfc_create_vport_work_array(phba
);
3727 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
3728 shost
= lpfc_shost_from_vport(vports
[i
]);
3729 spin_lock_irq(shost
->host_lock
);
3730 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
3731 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
3732 /* The mempool_alloc might sleep */
3733 spin_unlock_irq(shost
->host_lock
);
3734 lpfc_unreg_rpi(vports
[i
], ndlp
);
3735 spin_lock_irq(shost
->host_lock
);
3738 spin_unlock_irq(shost
->host_lock
);
3740 lpfc_destroy_vport_work_array(phba
, vports
);
3744 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
3746 struct lpfc_hba
*phba
= vport
->phba
;
3750 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3752 lpfc_unreg_login(phba
, vport
->vpi
, 0xffff, mbox
);
3753 mbox
->vport
= vport
;
3754 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3755 mbox
->context1
= NULL
;
3756 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
3757 if (rc
!= MBX_TIMEOUT
)
3758 mempool_free(mbox
, phba
->mbox_mem_pool
);
3760 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
3761 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3762 "1836 Could not issue "
3763 "unreg_login(all_rpis) status %d\n", rc
);
3768 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
3770 struct lpfc_hba
*phba
= vport
->phba
;
3774 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3776 lpfc_unreg_did(phba
, vport
->vpi
, 0xffffffff, mbox
);
3777 mbox
->vport
= vport
;
3778 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3779 mbox
->context1
= NULL
;
3780 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
3781 if (rc
!= MBX_TIMEOUT
)
3782 mempool_free(mbox
, phba
->mbox_mem_pool
);
3784 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
3785 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3786 "1815 Could not issue "
3787 "unreg_did (default rpis) status %d\n",
3793 * Free resources associated with LPFC_NODELIST entry
3794 * so it can be freed.
3797 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3799 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3800 struct lpfc_hba
*phba
= vport
->phba
;
3801 LPFC_MBOXQ_t
*mb
, *nextmb
;
3802 struct lpfc_dmabuf
*mp
;
3804 /* Cleanup node for NPort <nlp_DID> */
3805 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3806 "0900 Cleanup node for NPort x%x "
3807 "Data: x%x x%x x%x\n",
3808 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3809 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3810 if (NLP_CHK_FREE_REQ(ndlp
)) {
3811 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3812 "0280 lpfc_cleanup_node: ndlp:x%p "
3813 "usgmap:x%x refcnt:%d\n",
3814 (void *)ndlp
, ndlp
->nlp_usg_map
,
3815 atomic_read(&ndlp
->kref
.refcount
));
3816 lpfc_dequeue_node(vport
, ndlp
);
3818 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3819 "0281 lpfc_cleanup_node: ndlp:x%p "
3820 "usgmap:x%x refcnt:%d\n",
3821 (void *)ndlp
, ndlp
->nlp_usg_map
,
3822 atomic_read(&ndlp
->kref
.refcount
));
3823 lpfc_disable_node(vport
, ndlp
);
3826 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
3827 if ((mb
= phba
->sli
.mbox_active
)) {
3828 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
3829 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
3830 mb
->context2
= NULL
;
3831 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3835 spin_lock_irq(&phba
->hbalock
);
3836 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
3837 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
3838 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
3839 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
3841 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3844 list_del(&mb
->list
);
3845 mempool_free(mb
, phba
->mbox_mem_pool
);
3846 /* We shall not invoke the lpfc_nlp_put to decrement
3847 * the ndlp reference count as we are in the process
3848 * of lpfc_nlp_release.
3852 spin_unlock_irq(&phba
->hbalock
);
3854 lpfc_els_abort(phba
, ndlp
);
3856 spin_lock_irq(shost
->host_lock
);
3857 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
3858 spin_unlock_irq(shost
->host_lock
);
3860 ndlp
->nlp_last_elscmd
= 0;
3861 del_timer_sync(&ndlp
->nlp_delayfunc
);
3863 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
3864 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
3866 lpfc_unreg_rpi(vport
, ndlp
);
3872 * Check to see if we can free the nlp back to the freelist.
3873 * If we are in the middle of using the nlp in the discovery state
3874 * machine, defer the free till we reach the end of the state machine.
3877 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3879 struct lpfc_hba
*phba
= vport
->phba
;
3880 struct lpfc_rport_data
*rdata
;
3884 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3885 if ((ndlp
->nlp_flag
& NLP_DEFER_RM
) &&
3886 !(ndlp
->nlp_flag
& NLP_RPI_VALID
)) {
3887 /* For this case we need to cleanup the default rpi
3888 * allocated by the firmware.
3890 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
))
3892 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, ndlp
->nlp_DID
,
3893 (uint8_t *) &vport
->fc_sparam
, mbox
, 0);
3895 mempool_free(mbox
, phba
->mbox_mem_pool
);
3898 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3899 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3900 mbox
->vport
= vport
;
3901 mbox
->context2
= NULL
;
3902 rc
=lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3903 if (rc
== MBX_NOT_FINISHED
) {
3904 mempool_free(mbox
, phba
->mbox_mem_pool
);
3909 lpfc_cleanup_node(vport
, ndlp
);
3912 * We can get here with a non-NULL ndlp->rport because when we
3913 * unregister a rport we don't break the rport/node linkage. So if we
3914 * do, make sure we don't leaving any dangling pointers behind.
3917 rdata
= ndlp
->rport
->dd_data
;
3918 rdata
->pnode
= NULL
;
3924 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3927 D_ID mydid
, ndlpdid
, matchdid
;
3929 if (did
== Bcast_DID
)
3932 /* First check for Direct match */
3933 if (ndlp
->nlp_DID
== did
)
3936 /* Next check for area/domain identically equals 0 match */
3937 mydid
.un
.word
= vport
->fc_myDID
;
3938 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
3942 matchdid
.un
.word
= did
;
3943 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
3944 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
3945 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
3946 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
3947 if ((ndlpdid
.un
.b
.domain
== 0) &&
3948 (ndlpdid
.un
.b
.area
== 0)) {
3949 if (ndlpdid
.un
.b
.id
)
3955 matchdid
.un
.word
= ndlp
->nlp_DID
;
3956 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
3957 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
3958 if ((matchdid
.un
.b
.domain
== 0) &&
3959 (matchdid
.un
.b
.area
== 0)) {
3960 if (matchdid
.un
.b
.id
)
3968 /* Search for a nodelist entry */
3969 static struct lpfc_nodelist
*
3970 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
3972 struct lpfc_nodelist
*ndlp
;
3975 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3976 if (lpfc_matchdid(vport
, ndlp
, did
)) {
3977 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
3978 ((uint32_t) ndlp
->nlp_xri
<< 16) |
3979 ((uint32_t) ndlp
->nlp_type
<< 8) |
3980 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
3981 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3982 "0929 FIND node DID "
3983 "Data: x%p x%x x%x x%x\n",
3984 ndlp
, ndlp
->nlp_DID
,
3985 ndlp
->nlp_flag
, data1
);
3990 /* FIND node did <did> NOT FOUND */
3991 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3992 "0932 FIND node did x%x NOT FOUND.\n", did
);
3996 struct lpfc_nodelist
*
3997 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
3999 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4000 struct lpfc_nodelist
*ndlp
;
4002 spin_lock_irq(shost
->host_lock
);
4003 ndlp
= __lpfc_findnode_did(vport
, did
);
4004 spin_unlock_irq(shost
->host_lock
);
4008 struct lpfc_nodelist
*
4009 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
4011 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4012 struct lpfc_nodelist
*ndlp
;
4014 ndlp
= lpfc_findnode_did(vport
, did
);
4016 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
4017 lpfc_rscn_payload_check(vport
, did
) == 0)
4019 ndlp
= (struct lpfc_nodelist
*)
4020 mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
4023 lpfc_nlp_init(vport
, ndlp
, did
);
4024 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
4025 spin_lock_irq(shost
->host_lock
);
4026 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
4027 spin_unlock_irq(shost
->host_lock
);
4029 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
4030 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
4033 spin_lock_irq(shost
->host_lock
);
4034 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
4035 spin_unlock_irq(shost
->host_lock
);
4039 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
4040 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
4041 if (lpfc_rscn_payload_check(vport
, did
)) {
4042 /* If we've already recieved a PLOGI from this NPort
4043 * we don't need to try to discover it again.
4045 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
4048 /* Since this node is marked for discovery,
4049 * delay timeout is not needed.
4051 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4052 spin_lock_irq(shost
->host_lock
);
4053 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
4054 spin_unlock_irq(shost
->host_lock
);
4058 /* If we've already recieved a PLOGI from this NPort,
4059 * or we are already in the process of discovery on it,
4060 * we don't need to try to discover it again.
4062 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
4063 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
4064 ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
4066 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
4067 spin_lock_irq(shost
->host_lock
);
4068 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
4069 spin_unlock_irq(shost
->host_lock
);
4074 /* Build a list of nodes to discover based on the loopmap */
4076 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
4078 struct lpfc_hba
*phba
= vport
->phba
;
4080 uint32_t alpa
, index
;
4082 if (!lpfc_is_link_up(phba
))
4085 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
4088 /* Check for loop map present or not */
4089 if (phba
->alpa_map
[0]) {
4090 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
4091 alpa
= phba
->alpa_map
[j
];
4092 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
4094 lpfc_setup_disc_node(vport
, alpa
);
4097 /* No alpamap, so try all alpa's */
4098 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
4099 /* If cfg_scan_down is set, start from highest
4100 * ALPA (0xef) to lowest (0x1).
4102 if (vport
->cfg_scan_down
)
4105 index
= FC_MAXLOOP
- j
- 1;
4106 alpa
= lpfcAlpaArray
[index
];
4107 if ((vport
->fc_myDID
& 0xff) == alpa
)
4109 lpfc_setup_disc_node(vport
, alpa
);
4116 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
4119 struct lpfc_sli
*psli
= &phba
->sli
;
4120 struct lpfc_sli_ring
*extra_ring
= &psli
->ring
[psli
->extra_ring
];
4121 struct lpfc_sli_ring
*fcp_ring
= &psli
->ring
[psli
->fcp_ring
];
4122 struct lpfc_sli_ring
*next_ring
= &psli
->ring
[psli
->next_ring
];
4126 * if it's not a physical port or if we already send
4127 * clear_la then don't send it.
4129 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
4130 (vport
->port_type
!= LPFC_PHYSICAL_PORT
) ||
4131 (phba
->sli_rev
== LPFC_SLI_REV4
))
4134 /* Link up discovery */
4135 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
4136 phba
->link_state
= LPFC_CLEAR_LA
;
4137 lpfc_clear_la(phba
, mbox
);
4138 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
4139 mbox
->vport
= vport
;
4140 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4141 if (rc
== MBX_NOT_FINISHED
) {
4142 mempool_free(mbox
, phba
->mbox_mem_pool
);
4143 lpfc_disc_flush_list(vport
);
4144 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
4145 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
4146 next_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
4147 phba
->link_state
= LPFC_HBA_ERROR
;
4152 /* Reg_vpi to tell firmware to resume normal operations */
4154 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
4156 LPFC_MBOXQ_t
*regvpimbox
;
4158 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4160 lpfc_reg_vpi(vport
, regvpimbox
);
4161 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
4162 regvpimbox
->vport
= vport
;
4163 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
4164 == MBX_NOT_FINISHED
) {
4165 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
4170 /* Start Link up / RSCN discovery on NPR nodes */
4172 lpfc_disc_start(struct lpfc_vport
*vport
)
4174 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4175 struct lpfc_hba
*phba
= vport
->phba
;
4177 uint32_t clear_la_pending
;
4180 if (!lpfc_is_link_up(phba
))
4183 if (phba
->link_state
== LPFC_CLEAR_LA
)
4184 clear_la_pending
= 1;
4186 clear_la_pending
= 0;
4188 if (vport
->port_state
< LPFC_VPORT_READY
)
4189 vport
->port_state
= LPFC_DISC_AUTH
;
4191 lpfc_set_disctmo(vport
);
4193 if (vport
->fc_prevDID
== vport
->fc_myDID
)
4198 vport
->fc_prevDID
= vport
->fc_myDID
;
4199 vport
->num_disc_nodes
= 0;
4201 /* Start Discovery state <hba_state> */
4202 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4203 "0202 Start Discovery hba state x%x "
4204 "Data: x%x x%x x%x\n",
4205 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
4206 vport
->fc_adisc_cnt
);
4208 /* First do ADISCs - if any */
4209 num_sent
= lpfc_els_disc_adisc(vport
);
4215 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
4216 * continue discovery.
4218 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4219 !(vport
->fc_flag
& FC_PT2PT
) &&
4220 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
4221 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
4222 lpfc_issue_reg_vpi(phba
, vport
);
4227 * For SLI2, we need to set port_state to READY and continue
4230 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
4231 /* If we get here, there is nothing to ADISC */
4232 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
4233 lpfc_issue_clear_la(phba
, vport
);
4235 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
4236 vport
->num_disc_nodes
= 0;
4237 /* go thru NPR nodes and issue ELS PLOGIs */
4238 if (vport
->fc_npr_cnt
)
4239 lpfc_els_disc_plogi(vport
);
4241 if (!vport
->num_disc_nodes
) {
4242 spin_lock_irq(shost
->host_lock
);
4243 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
4244 spin_unlock_irq(shost
->host_lock
);
4245 lpfc_can_disctmo(vport
);
4248 vport
->port_state
= LPFC_VPORT_READY
;
4250 /* Next do PLOGIs - if any */
4251 num_sent
= lpfc_els_disc_plogi(vport
);
4256 if (vport
->fc_flag
& FC_RSCN_MODE
) {
4257 /* Check to see if more RSCNs came in while we
4258 * were processing this one.
4260 if ((vport
->fc_rscn_id_cnt
== 0) &&
4261 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
4262 spin_lock_irq(shost
->host_lock
);
4263 vport
->fc_flag
&= ~FC_RSCN_MODE
;
4264 spin_unlock_irq(shost
->host_lock
);
4265 lpfc_can_disctmo(vport
);
4267 lpfc_els_handle_rscn(vport
);
4274 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
4275 * ring the match the sppecified nodelist.
4278 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
4280 LIST_HEAD(completions
);
4281 struct lpfc_sli
*psli
;
4283 struct lpfc_iocbq
*iocb
, *next_iocb
;
4284 struct lpfc_sli_ring
*pring
;
4287 pring
= &psli
->ring
[LPFC_ELS_RING
];
4289 /* Error matching iocb on txq or txcmplq
4290 * First check the txq.
4292 spin_lock_irq(&phba
->hbalock
);
4293 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
4294 if (iocb
->context1
!= ndlp
) {
4298 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
4299 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
4301 list_move_tail(&iocb
->list
, &completions
);
4306 /* Next check the txcmplq */
4307 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
4308 if (iocb
->context1
!= ndlp
) {
4312 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
4313 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
4314 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
4317 spin_unlock_irq(&phba
->hbalock
);
4319 /* Cancel all the IOCBs from the completions list */
4320 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
4325 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
4327 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4328 struct lpfc_hba
*phba
= vport
->phba
;
4330 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
4331 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
4333 if (!NLP_CHK_NODE_ACT(ndlp
))
4335 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
4336 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
4337 lpfc_free_tx(phba
, ndlp
);
4344 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
4346 lpfc_els_flush_rscn(vport
);
4347 lpfc_els_flush_cmd(vport
);
4348 lpfc_disc_flush_list(vport
);
4351 /*****************************************************************************/
4353 * NAME: lpfc_disc_timeout
4355 * FUNCTION: Fibre Channel driver discovery timeout routine.
4357 * EXECUTION ENVIRONMENT: interrupt only
4365 /*****************************************************************************/
4367 lpfc_disc_timeout(unsigned long ptr
)
4369 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
4370 struct lpfc_hba
*phba
= vport
->phba
;
4371 uint32_t tmo_posted
;
4372 unsigned long flags
= 0;
4374 if (unlikely(!phba
))
4377 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
4378 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
4380 vport
->work_port_events
|= WORKER_DISC_TMO
;
4381 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
4384 lpfc_worker_wake_up(phba
);
4389 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
4391 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4392 struct lpfc_hba
*phba
= vport
->phba
;
4393 struct lpfc_sli
*psli
= &phba
->sli
;
4394 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4395 LPFC_MBOXQ_t
*initlinkmbox
;
4396 int rc
, clrlaerr
= 0;
4398 if (!(vport
->fc_flag
& FC_DISC_TMO
))
4401 spin_lock_irq(shost
->host_lock
);
4402 vport
->fc_flag
&= ~FC_DISC_TMO
;
4403 spin_unlock_irq(shost
->host_lock
);
4405 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4406 "disc timeout: state:x%x rtry:x%x flg:x%x",
4407 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
4409 switch (vport
->port_state
) {
4411 case LPFC_LOCAL_CFG_LINK
:
4412 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
4416 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
4417 "0221 FAN timeout\n");
4418 /* Start discovery by sending FLOGI, clean up old rpis */
4419 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
4421 if (!NLP_CHK_NODE_ACT(ndlp
))
4423 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
4425 if (ndlp
->nlp_type
& NLP_FABRIC
) {
4426 /* Clean up the ndlp on Fabric connections */
4427 lpfc_drop_node(vport
, ndlp
);
4429 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
4430 /* Fail outstanding IO now since device
4431 * is marked for PLOGI.
4433 lpfc_unreg_rpi(vport
, ndlp
);
4436 if (vport
->port_state
!= LPFC_FLOGI
) {
4437 lpfc_initial_flogi(vport
);
4444 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
4445 /* Initial FLOGI timeout */
4446 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4447 "0222 Initial %s timeout\n",
4448 vport
->vpi
? "FDISC" : "FLOGI");
4450 /* Assume no Fabric and go on with discovery.
4451 * Check for outstanding ELS FLOGI to abort.
4454 /* FLOGI failed, so just use loop map to make discovery list */
4455 lpfc_disc_list_loopmap(vport
);
4457 /* Start discovery */
4458 lpfc_disc_start(vport
);
4461 case LPFC_FABRIC_CFG_LINK
:
4462 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
4464 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4465 "0223 Timeout while waiting for "
4466 "NameServer login\n");
4467 /* Next look for NameServer ndlp */
4468 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4469 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4470 lpfc_els_abort(phba
, ndlp
);
4472 /* ReStart discovery */
4476 /* Check for wait for NameServer Rsp timeout */
4477 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4478 "0224 NameServer Query timeout "
4480 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
4482 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
4483 /* Try it one more time */
4484 vport
->fc_ns_retry
++;
4485 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
,
4486 vport
->fc_ns_retry
, 0);
4490 vport
->fc_ns_retry
= 0;
4494 * Discovery is over.
4495 * set port_state to PORT_READY if SLI2.
4496 * cmpl_reg_vpi will set port_state to READY for SLI3.
4498 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
4499 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
4500 lpfc_issue_reg_vpi(phba
, vport
);
4501 else { /* NPIV Not enabled */
4502 lpfc_issue_clear_la(phba
, vport
);
4503 vport
->port_state
= LPFC_VPORT_READY
;
4507 /* Setup and issue mailbox INITIALIZE LINK command */
4508 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4509 if (!initlinkmbox
) {
4510 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4511 "0206 Device Discovery "
4512 "completion error\n");
4513 phba
->link_state
= LPFC_HBA_ERROR
;
4517 lpfc_linkdown(phba
);
4518 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
4519 phba
->cfg_link_speed
);
4520 initlinkmbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4521 initlinkmbox
->vport
= vport
;
4522 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4523 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
4524 lpfc_set_loopback_flag(phba
);
4525 if (rc
== MBX_NOT_FINISHED
)
4526 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
4530 case LPFC_DISC_AUTH
:
4531 /* Node Authentication timeout */
4532 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4533 "0227 Node Authentication timeout\n");
4534 lpfc_disc_flush_list(vport
);
4537 * set port_state to PORT_READY if SLI2.
4538 * cmpl_reg_vpi will set port_state to READY for SLI3.
4540 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
4541 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
4542 lpfc_issue_reg_vpi(phba
, vport
);
4543 else { /* NPIV Not enabled */
4544 lpfc_issue_clear_la(phba
, vport
);
4545 vport
->port_state
= LPFC_VPORT_READY
;
4550 case LPFC_VPORT_READY
:
4551 if (vport
->fc_flag
& FC_RSCN_MODE
) {
4552 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4553 "0231 RSCN timeout Data: x%x "
4555 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
4557 /* Cleanup any outstanding ELS commands */
4558 lpfc_els_flush_cmd(vport
);
4560 lpfc_els_flush_rscn(vport
);
4561 lpfc_disc_flush_list(vport
);
4566 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4567 "0273 Unexpected discovery timeout, "
4568 "vport State x%x\n", vport
->port_state
);
4572 switch (phba
->link_state
) {
4574 /* CLEAR LA timeout */
4575 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4576 "0228 CLEAR LA timeout\n");
4581 lpfc_issue_clear_la(phba
, vport
);
4583 case LPFC_LINK_UNKNOWN
:
4584 case LPFC_WARM_START
:
4585 case LPFC_INIT_START
:
4586 case LPFC_INIT_MBX_CMDS
:
4587 case LPFC_LINK_DOWN
:
4588 case LPFC_HBA_ERROR
:
4589 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4590 "0230 Unexpected timeout, hba link "
4591 "state x%x\n", phba
->link_state
);
4595 case LPFC_HBA_READY
:
4600 lpfc_disc_flush_list(vport
);
4601 psli
->ring
[(psli
->extra_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4602 psli
->ring
[(psli
->fcp_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4603 psli
->ring
[(psli
->next_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4604 vport
->port_state
= LPFC_VPORT_READY
;
4611 * This routine handles processing a NameServer REG_LOGIN mailbox
4612 * command upon completion. It is setup in the LPFC_MBOXQ
4613 * as the completion routine when the command is
4614 * handed off to the SLI layer.
4617 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4619 MAILBOX_t
*mb
= &pmb
->u
.mb
;
4620 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
4621 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4622 struct lpfc_vport
*vport
= pmb
->vport
;
4624 pmb
->context1
= NULL
;
4626 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
4627 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
4628 ndlp
->nlp_type
|= NLP_FABRIC
;
4629 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4632 * Start issuing Fabric-Device Management Interface (FDMI) command to
4633 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
4634 * fdmi-on=2 (supporting RPA/hostnmae)
4637 if (vport
->cfg_fdmi_on
== 1)
4638 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
);
4640 mod_timer(&vport
->fc_fdmitmo
, jiffies
+ HZ
* 60);
4642 /* decrement the node reference count held for this callback
4646 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4648 mempool_free(pmb
, phba
->mbox_mem_pool
);
4654 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
4656 uint16_t *rpi
= param
;
4658 return ndlp
->nlp_rpi
== *rpi
;
4662 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
4664 return memcmp(&ndlp
->nlp_portname
, param
,
4665 sizeof(ndlp
->nlp_portname
)) == 0;
4668 static struct lpfc_nodelist
*
4669 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
4671 struct lpfc_nodelist
*ndlp
;
4673 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4674 if (filter(ndlp
, param
))
4681 * This routine looks up the ndlp lists for the given RPI. If rpi found it
4682 * returns the node list element pointer else return NULL.
4684 struct lpfc_nodelist
*
4685 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
4687 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
4691 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
4692 * returns the node element list pointer else return NULL.
4694 struct lpfc_nodelist
*
4695 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
4697 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4698 struct lpfc_nodelist
*ndlp
;
4700 spin_lock_irq(shost
->host_lock
);
4701 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
4702 spin_unlock_irq(shost
->host_lock
);
4707 lpfc_nlp_init(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4710 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
4712 lpfc_initialize_node(vport
, ndlp
, did
);
4713 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
4715 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
4716 "node init: did:x%x",
4717 ndlp
->nlp_DID
, 0, 0);
4722 /* This routine releases all resources associated with a specifc NPort's ndlp
4723 * and mempool_free's the nodelist.
4726 lpfc_nlp_release(struct kref
*kref
)
4728 struct lpfc_hba
*phba
;
4729 unsigned long flags
;
4730 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
4733 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4734 "node release: did:x%x flg:x%x type:x%x",
4735 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4737 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
4738 "0279 lpfc_nlp_release: ndlp:x%p "
4739 "usgmap:x%x refcnt:%d\n",
4740 (void *)ndlp
, ndlp
->nlp_usg_map
,
4741 atomic_read(&ndlp
->kref
.refcount
));
4743 /* remove ndlp from action. */
4744 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
4746 /* clear the ndlp active flag for all release cases */
4748 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4749 NLP_CLR_NODE_ACT(ndlp
);
4750 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4752 /* free ndlp memory for final ndlp release */
4753 if (NLP_CHK_FREE_REQ(ndlp
)) {
4754 kfree(ndlp
->lat_data
);
4755 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
4759 /* This routine bumps the reference count for a ndlp structure to ensure
4760 * that one discovery thread won't free a ndlp while another discovery thread
4763 struct lpfc_nodelist
*
4764 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
4766 struct lpfc_hba
*phba
;
4767 unsigned long flags
;
4770 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4771 "node get: did:x%x flg:x%x refcnt:x%x",
4772 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4773 atomic_read(&ndlp
->kref
.refcount
));
4774 /* The check of ndlp usage to prevent incrementing the
4775 * ndlp reference count that is in the process of being
4779 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4780 if (!NLP_CHK_NODE_ACT(ndlp
) || NLP_CHK_FREE_ACK(ndlp
)) {
4781 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4782 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4783 "0276 lpfc_nlp_get: ndlp:x%p "
4784 "usgmap:x%x refcnt:%d\n",
4785 (void *)ndlp
, ndlp
->nlp_usg_map
,
4786 atomic_read(&ndlp
->kref
.refcount
));
4789 kref_get(&ndlp
->kref
);
4790 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4795 /* This routine decrements the reference count for a ndlp structure. If the
4796 * count goes to 0, this indicates the the associated nodelist should be
4797 * freed. Returning 1 indicates the ndlp resource has been released; on the
4798 * other hand, returning 0 indicates the ndlp resource has not been released
4802 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
4804 struct lpfc_hba
*phba
;
4805 unsigned long flags
;
4810 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4811 "node put: did:x%x flg:x%x refcnt:x%x",
4812 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4813 atomic_read(&ndlp
->kref
.refcount
));
4815 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4816 /* Check the ndlp memory free acknowledge flag to avoid the
4817 * possible race condition that kref_put got invoked again
4818 * after previous one has done ndlp memory free.
4820 if (NLP_CHK_FREE_ACK(ndlp
)) {
4821 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4822 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4823 "0274 lpfc_nlp_put: ndlp:x%p "
4824 "usgmap:x%x refcnt:%d\n",
4825 (void *)ndlp
, ndlp
->nlp_usg_map
,
4826 atomic_read(&ndlp
->kref
.refcount
));
4829 /* Check the ndlp inactivate log flag to avoid the possible
4830 * race condition that kref_put got invoked again after ndlp
4831 * is already in inactivating state.
4833 if (NLP_CHK_IACT_REQ(ndlp
)) {
4834 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4835 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4836 "0275 lpfc_nlp_put: ndlp:x%p "
4837 "usgmap:x%x refcnt:%d\n",
4838 (void *)ndlp
, ndlp
->nlp_usg_map
,
4839 atomic_read(&ndlp
->kref
.refcount
));
4842 /* For last put, mark the ndlp usage flags to make sure no
4843 * other kref_get and kref_put on the same ndlp shall get
4844 * in between the process when the final kref_put has been
4845 * invoked on this ndlp.
4847 if (atomic_read(&ndlp
->kref
.refcount
) == 1) {
4848 /* Indicate ndlp is put to inactive state. */
4849 NLP_SET_IACT_REQ(ndlp
);
4850 /* Acknowledge ndlp memory free has been seen. */
4851 if (NLP_CHK_FREE_REQ(ndlp
))
4852 NLP_SET_FREE_ACK(ndlp
);
4854 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4855 /* Note, the kref_put returns 1 when decrementing a reference
4856 * count that was 1, it invokes the release callback function,
4857 * but it still left the reference count as 1 (not actually
4858 * performs the last decrementation). Otherwise, it actually
4859 * decrements the reference count and returns 0.
4861 return kref_put(&ndlp
->kref
, lpfc_nlp_release
);
4864 /* This routine free's the specified nodelist if it is not in use
4865 * by any other discovery thread. This routine returns 1 if the
4866 * ndlp has been freed. A return value of 0 indicates the ndlp is
4867 * not yet been released.
4870 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
4872 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4873 "node not used: did:x%x flg:x%x refcnt:x%x",
4874 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4875 atomic_read(&ndlp
->kref
.refcount
));
4876 if (atomic_read(&ndlp
->kref
.refcount
) == 1)
4877 if (lpfc_nlp_put(ndlp
))
4883 * lpfc_fcf_inuse - Check if FCF can be unregistered.
4884 * @phba: Pointer to hba context object.
4886 * This function iterate through all FC nodes associated
4887 * will all vports to check if there is any node with
4888 * fc_rports associated with it. If there is an fc_rport
4889 * associated with the node, then the node is either in
4890 * discovered state or its devloss_timer is pending.
4893 lpfc_fcf_inuse(struct lpfc_hba
*phba
)
4895 struct lpfc_vport
**vports
;
4897 struct lpfc_nodelist
*ndlp
;
4898 struct Scsi_Host
*shost
;
4900 vports
= lpfc_create_vport_work_array(phba
);
4902 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4903 shost
= lpfc_shost_from_vport(vports
[i
]);
4904 spin_lock_irq(shost
->host_lock
);
4905 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
4906 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
&&
4907 (ndlp
->rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
4909 spin_unlock_irq(shost
->host_lock
);
4912 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
4913 "2624 RPI %x DID %x flg %x still "
4915 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4917 if (ndlp
->nlp_flag
& NLP_RPI_VALID
)
4921 spin_unlock_irq(shost
->host_lock
);
4924 lpfc_destroy_vport_work_array(phba
, vports
);
4929 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
4930 * @phba: Pointer to hba context object.
4931 * @mboxq: Pointer to mailbox object.
4933 * This function frees memory associated with the mailbox command.
4936 lpfc_unregister_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
4938 struct lpfc_vport
*vport
= mboxq
->vport
;
4940 if (mboxq
->u
.mb
.mbxStatus
) {
4941 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4942 "2555 UNREG_VFI mbxStatus error x%x "
4944 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
4946 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4951 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
4952 * @phba: Pointer to hba context object.
4953 * @mboxq: Pointer to mailbox object.
4955 * This function frees memory associated with the mailbox command.
4958 lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
4960 struct lpfc_vport
*vport
= mboxq
->vport
;
4962 if (mboxq
->u
.mb
.mbxStatus
) {
4963 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4964 "2550 UNREG_FCFI mbxStatus error x%x "
4966 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
4968 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4973 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
4974 * @phba: Pointer to hba context object.
4976 * This function prepare the HBA for unregistering the currently registered
4977 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
4981 lpfc_unregister_fcf_prep(struct lpfc_hba
*phba
)
4984 struct lpfc_vport
**vports
;
4985 struct lpfc_nodelist
*ndlp
;
4986 struct Scsi_Host
*shost
;
4989 /* Unregister RPIs */
4990 if (lpfc_fcf_inuse(phba
))
4991 lpfc_unreg_hba_rpis(phba
);
4993 /* At this point, all discovery is aborted */
4994 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4996 /* Unregister VPIs */
4997 vports
= lpfc_create_vport_work_array(phba
);
4998 if (vports
&& (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))
4999 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
5000 /* Stop FLOGI/FDISC retries */
5001 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
5003 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
5004 lpfc_cleanup_pending_mbox(vports
[i
]);
5005 lpfc_mbx_unreg_vpi(vports
[i
]);
5006 shost
= lpfc_shost_from_vport(vports
[i
]);
5007 spin_lock_irq(shost
->host_lock
);
5008 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
5009 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
5010 spin_unlock_irq(shost
->host_lock
);
5012 lpfc_destroy_vport_work_array(phba
, vports
);
5014 /* Cleanup any outstanding ELS commands */
5015 lpfc_els_flush_all_cmd(phba
);
5017 /* Unregister VFI */
5018 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5020 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5021 "2556 UNREG_VFI mbox allocation failed"
5022 "HBA state x%x\n", phba
->pport
->port_state
);
5026 lpfc_unreg_vfi(mbox
, phba
->pport
);
5027 mbox
->vport
= phba
->pport
;
5028 mbox
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
5030 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5031 if (rc
== MBX_NOT_FINISHED
) {
5032 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5033 "2557 UNREG_VFI issue mbox failed rc x%x "
5035 rc
, phba
->pport
->port_state
);
5036 mempool_free(mbox
, phba
->mbox_mem_pool
);
5040 shost
= lpfc_shost_from_vport(phba
->pport
);
5041 spin_lock_irq(shost
->host_lock
);
5042 phba
->pport
->fc_flag
&= ~FC_VFI_REGISTERED
;
5043 spin_unlock_irq(shost
->host_lock
);
5049 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
5050 * @phba: Pointer to hba context object.
5052 * This function issues synchronous unregister FCF mailbox command to HBA to
5053 * unregister the currently registered FCF record. The driver does not reset
5054 * the driver FCF usage state flags.
5056 * Return 0 if successfully issued, none-zero otherwise.
5059 lpfc_sli4_unregister_fcf(struct lpfc_hba
*phba
)
5064 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5066 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5067 "2551 UNREG_FCFI mbox allocation failed"
5068 "HBA state x%x\n", phba
->pport
->port_state
);
5071 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
5072 mbox
->vport
= phba
->pport
;
5073 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
5074 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5076 if (rc
== MBX_NOT_FINISHED
) {
5077 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5078 "2552 Unregister FCFI command failed rc x%x "
5080 rc
, phba
->pport
->port_state
);
5087 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
5088 * @phba: Pointer to hba context object.
5090 * This function unregisters the currently reigstered FCF. This function
5091 * also tries to find another FCF for discovery by rescan the HBA FCF table.
5094 lpfc_unregister_fcf_rescan(struct lpfc_hba
*phba
)
5098 /* Preparation for unregistering fcf */
5099 rc
= lpfc_unregister_fcf_prep(phba
);
5101 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
5102 "2748 Failed to prepare for unregistering "
5103 "HBA's FCF record: rc=%d\n", rc
);
5107 /* Now, unregister FCF record and reset HBA FCF state */
5108 rc
= lpfc_sli4_unregister_fcf(phba
);
5111 /* Reset HBA FCF states after successful unregister FCF */
5112 phba
->fcf
.fcf_flag
= 0;
5113 phba
->fcf
.current_rec
.flag
= 0;
5116 * If driver is not unloading, check if there is any other
5117 * FCF record that can be used for discovery.
5119 if ((phba
->pport
->load_flag
& FC_UNLOADING
) ||
5120 (phba
->link_state
< LPFC_LINK_UP
))
5123 /* This is considered as the initial FCF discovery scan */
5124 spin_lock_irq(&phba
->hbalock
);
5125 phba
->fcf
.fcf_flag
|= FCF_INIT_DISC
;
5126 spin_unlock_irq(&phba
->hbalock
);
5127 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
5130 spin_lock_irq(&phba
->hbalock
);
5131 phba
->fcf
.fcf_flag
&= ~FCF_INIT_DISC
;
5132 spin_unlock_irq(&phba
->hbalock
);
5133 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
5134 "2553 lpfc_unregister_unused_fcf failed "
5135 "to read FCF record HBA state x%x\n",
5136 phba
->pport
->port_state
);
5141 * lpfc_unregister_fcf - Unregister the currently registered fcf record
5142 * @phba: Pointer to hba context object.
5144 * This function just unregisters the currently reigstered FCF. It does not
5145 * try to find another FCF for discovery.
5148 lpfc_unregister_fcf(struct lpfc_hba
*phba
)
5152 /* Preparation for unregistering fcf */
5153 rc
= lpfc_unregister_fcf_prep(phba
);
5155 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
5156 "2749 Failed to prepare for unregistering "
5157 "HBA's FCF record: rc=%d\n", rc
);
5161 /* Now, unregister FCF record and reset HBA FCF state */
5162 rc
= lpfc_sli4_unregister_fcf(phba
);
5165 /* Set proper HBA FCF states after successful unregister FCF */
5166 spin_lock_irq(&phba
->hbalock
);
5167 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
5168 spin_unlock_irq(&phba
->hbalock
);
5172 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
5173 * @phba: Pointer to hba context object.
5175 * This function check if there are any connected remote port for the FCF and
5176 * if all the devices are disconnected, this function unregister FCFI.
5177 * This function also tries to use another FCF for discovery.
5180 lpfc_unregister_unused_fcf(struct lpfc_hba
*phba
)
5183 * If HBA is not running in FIP mode or if HBA does not support
5184 * FCoE or if FCF is not registered, do nothing.
5186 spin_lock_irq(&phba
->hbalock
);
5187 if (!(phba
->hba_flag
& HBA_FCOE_SUPPORT
) ||
5188 !(phba
->fcf
.fcf_flag
& FCF_REGISTERED
) ||
5189 !(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
5190 spin_unlock_irq(&phba
->hbalock
);
5193 spin_unlock_irq(&phba
->hbalock
);
5195 if (lpfc_fcf_inuse(phba
))
5198 lpfc_unregister_fcf_rescan(phba
);
5202 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
5203 * @phba: Pointer to hba context object.
5204 * @buff: Buffer containing the FCF connection table as in the config
5206 * This function create driver data structure for the FCF connection
5207 * record table read from config region 23.
5210 lpfc_read_fcf_conn_tbl(struct lpfc_hba
*phba
,
5213 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
5214 struct lpfc_fcf_conn_hdr
*conn_hdr
;
5215 struct lpfc_fcf_conn_rec
*conn_rec
;
5216 uint32_t record_count
;
5219 /* Free the current connect table */
5220 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
5221 &phba
->fcf_conn_rec_list
, list
) {
5222 list_del_init(&conn_entry
->list
);
5226 conn_hdr
= (struct lpfc_fcf_conn_hdr
*) buff
;
5227 record_count
= conn_hdr
->length
* sizeof(uint32_t)/
5228 sizeof(struct lpfc_fcf_conn_rec
);
5230 conn_rec
= (struct lpfc_fcf_conn_rec
*)
5231 (buff
+ sizeof(struct lpfc_fcf_conn_hdr
));
5233 for (i
= 0; i
< record_count
; i
++) {
5234 if (!(conn_rec
[i
].flags
& FCFCNCT_VALID
))
5236 conn_entry
= kzalloc(sizeof(struct lpfc_fcf_conn_entry
),
5239 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5240 "2566 Failed to allocate connection"
5245 memcpy(&conn_entry
->conn_rec
, &conn_rec
[i
],
5246 sizeof(struct lpfc_fcf_conn_rec
));
5247 conn_entry
->conn_rec
.vlan_tag
=
5248 le16_to_cpu(conn_entry
->conn_rec
.vlan_tag
) & 0xFFF;
5249 conn_entry
->conn_rec
.flags
=
5250 le16_to_cpu(conn_entry
->conn_rec
.flags
);
5251 list_add_tail(&conn_entry
->list
,
5252 &phba
->fcf_conn_rec_list
);
5257 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
5258 * @phba: Pointer to hba context object.
5259 * @buff: Buffer containing the FCoE parameter data structure.
5261 * This function update driver data structure with config
5262 * parameters read from config region 23.
5265 lpfc_read_fcoe_param(struct lpfc_hba
*phba
,
5268 struct lpfc_fip_param_hdr
*fcoe_param_hdr
;
5269 struct lpfc_fcoe_params
*fcoe_param
;
5271 fcoe_param_hdr
= (struct lpfc_fip_param_hdr
*)
5273 fcoe_param
= (struct lpfc_fcoe_params
*)
5274 (buff
+ sizeof(struct lpfc_fip_param_hdr
));
5276 if ((fcoe_param_hdr
->parm_version
!= FIPP_VERSION
) ||
5277 (fcoe_param_hdr
->length
!= FCOE_PARAM_LENGTH
))
5280 if (fcoe_param_hdr
->parm_flags
& FIPP_VLAN_VALID
) {
5281 phba
->valid_vlan
= 1;
5282 phba
->vlan_id
= le16_to_cpu(fcoe_param
->vlan_tag
) &
5286 phba
->fc_map
[0] = fcoe_param
->fc_map
[0];
5287 phba
->fc_map
[1] = fcoe_param
->fc_map
[1];
5288 phba
->fc_map
[2] = fcoe_param
->fc_map
[2];
5293 * lpfc_get_rec_conf23 - Get a record type in config region data.
5294 * @buff: Buffer containing config region 23 data.
5295 * @size: Size of the data buffer.
5296 * @rec_type: Record type to be searched.
5298 * This function searches config region data to find the begining
5299 * of the record specified by record_type. If record found, this
5300 * function return pointer to the record else return NULL.
5303 lpfc_get_rec_conf23(uint8_t *buff
, uint32_t size
, uint8_t rec_type
)
5305 uint32_t offset
= 0, rec_length
;
5307 if ((buff
[0] == LPFC_REGION23_LAST_REC
) ||
5308 (size
< sizeof(uint32_t)))
5311 rec_length
= buff
[offset
+ 1];
5314 * One TLV record has one word header and number of data words
5315 * specified in the rec_length field of the record header.
5317 while ((offset
+ rec_length
* sizeof(uint32_t) + sizeof(uint32_t))
5319 if (buff
[offset
] == rec_type
)
5320 return &buff
[offset
];
5322 if (buff
[offset
] == LPFC_REGION23_LAST_REC
)
5325 offset
+= rec_length
* sizeof(uint32_t) + sizeof(uint32_t);
5326 rec_length
= buff
[offset
+ 1];
5332 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
5333 * @phba: Pointer to lpfc_hba data structure.
5334 * @buff: Buffer containing config region 23 data.
5335 * @size: Size of the data buffer.
5337 * This fuction parse the FCoE config parameters in config region 23 and
5338 * populate driver data structure with the parameters.
5341 lpfc_parse_fcoe_conf(struct lpfc_hba
*phba
,
5345 uint32_t offset
= 0, rec_length
;
5349 * If data size is less than 2 words signature and version cannot be
5352 if (size
< 2*sizeof(uint32_t))
5355 /* Check the region signature first */
5356 if (memcmp(buff
, LPFC_REGION23_SIGNATURE
, 4)) {
5357 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5358 "2567 Config region 23 has bad signature\n");
5364 /* Check the data structure version */
5365 if (buff
[offset
] != LPFC_REGION23_VERSION
) {
5366 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5367 "2568 Config region 23 has bad version\n");
5372 rec_length
= buff
[offset
+ 1];
5374 /* Read FCoE param record */
5375 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
5376 size
- offset
, FCOE_PARAM_TYPE
);
5378 lpfc_read_fcoe_param(phba
, rec_ptr
);
5380 /* Read FCF connection table */
5381 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
5382 size
- offset
, FCOE_CONN_TBL_TYPE
);
5384 lpfc_read_fcf_conn_tbl(phba
, rec_ptr
);