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/pci.h>
24 #include <linux/kthread.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_disc.h"
37 #include "lpfc_sli4.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 /* AlpaArray for assignment of scsid for scan-down and bind_method */
46 static uint8_t lpfcAlpaArray
[] = {
47 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
48 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
49 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
50 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
51 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
52 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
53 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
54 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
55 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
56 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
57 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
58 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
59 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
62 static void lpfc_disc_timeout_handler(struct lpfc_vport
*);
63 static void lpfc_disc_flush_list(struct lpfc_vport
*vport
);
64 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*, LPFC_MBOXQ_t
*);
67 lpfc_terminate_rport_io(struct fc_rport
*rport
)
69 struct lpfc_rport_data
*rdata
;
70 struct lpfc_nodelist
* ndlp
;
71 struct lpfc_hba
*phba
;
73 rdata
= rport
->dd_data
;
76 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
77 if (rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)
78 printk(KERN_ERR
"Cannot find remote node"
79 " to terminate I/O Data x%x\n",
86 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
87 "rport terminate: sid:x%x did:x%x flg:x%x",
88 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
90 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
91 lpfc_sli_abort_iocb(ndlp
->vport
,
92 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
93 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
98 * This function will be called when dev_loss_tmo fire.
101 lpfc_dev_loss_tmo_callbk(struct fc_rport
*rport
)
103 struct lpfc_rport_data
*rdata
;
104 struct lpfc_nodelist
* ndlp
;
105 struct lpfc_vport
*vport
;
106 struct lpfc_hba
*phba
;
107 struct lpfc_work_evt
*evtp
;
111 rdata
= rport
->dd_data
;
113 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
119 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
120 "rport devlosscb: sid:x%x did:x%x flg:x%x",
121 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
123 /* Don't defer this if we are in the process of deleting the vport
124 * or unloading the driver. The unload will cleanup the node
125 * appropriately we just need to cleanup the ndlp rport info here.
127 if (vport
->load_flag
& FC_UNLOADING
) {
128 put_node
= rdata
->pnode
!= NULL
;
129 put_rport
= ndlp
->rport
!= NULL
;
135 put_device(&rport
->dev
);
139 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)
142 evtp
= &ndlp
->dev_loss_evt
;
144 if (!list_empty(&evtp
->evt_listp
))
147 spin_lock_irq(&phba
->hbalock
);
148 /* We need to hold the node by incrementing the reference
149 * count until this queued work is done
151 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
152 if (evtp
->evt_arg1
) {
153 evtp
->evt
= LPFC_EVT_DEV_LOSS
;
154 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
155 lpfc_worker_wake_up(phba
);
157 spin_unlock_irq(&phba
->hbalock
);
163 * This function is called from the worker thread when dev_loss_tmo
167 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist
*ndlp
)
169 struct lpfc_rport_data
*rdata
;
170 struct fc_rport
*rport
;
171 struct lpfc_vport
*vport
;
172 struct lpfc_hba
*phba
;
183 rdata
= rport
->dd_data
;
184 name
= (uint8_t *) &ndlp
->nlp_portname
;
188 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
189 "rport devlosstmo:did:x%x type:x%x id:x%x",
190 ndlp
->nlp_DID
, ndlp
->nlp_type
, rport
->scsi_target_id
);
192 /* Don't defer this if we are in the process of deleting the vport
193 * or unloading the driver. The unload will cleanup the node
194 * appropriately we just need to cleanup the ndlp rport info here.
196 if (vport
->load_flag
& FC_UNLOADING
) {
197 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
198 /* flush the target */
199 lpfc_sli_abort_iocb(vport
,
200 &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
201 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
203 put_node
= rdata
->pnode
!= NULL
;
204 put_rport
= ndlp
->rport
!= NULL
;
210 put_device(&rport
->dev
);
214 if (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
) {
215 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
216 "0284 Devloss timeout Ignored on "
217 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
219 *name
, *(name
+1), *(name
+2), *(name
+3),
220 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
225 if (ndlp
->nlp_type
& NLP_FABRIC
) {
226 /* We will clean up these Nodes in linkup */
227 put_node
= rdata
->pnode
!= NULL
;
228 put_rport
= ndlp
->rport
!= NULL
;
234 put_device(&rport
->dev
);
238 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
240 /* flush the target */
241 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
242 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
246 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
247 "0203 Devloss timeout on "
248 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
249 "NPort x%06x Data: x%x x%x x%x\n",
250 *name
, *(name
+1), *(name
+2), *(name
+3),
251 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
252 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
253 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
255 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
256 "0204 Devloss timeout on "
257 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
258 "NPort x%06x Data: x%x x%x x%x\n",
259 *name
, *(name
+1), *(name
+2), *(name
+3),
260 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
261 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
262 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
265 put_node
= rdata
->pnode
!= NULL
;
266 put_rport
= ndlp
->rport
!= NULL
;
272 put_device(&rport
->dev
);
274 if (!(vport
->load_flag
& FC_UNLOADING
) &&
275 !(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
276 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
277 (ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
))
278 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
280 lpfc_unregister_unused_fcf(phba
);
284 * lpfc_alloc_fast_evt - Allocates data structure for posting event
285 * @phba: Pointer to hba context object.
287 * This function is called from the functions which need to post
288 * events from interrupt context. This function allocates data
289 * structure required for posting event. It also keeps track of
290 * number of events pending and prevent event storm when there are
293 struct lpfc_fast_path_event
*
294 lpfc_alloc_fast_evt(struct lpfc_hba
*phba
) {
295 struct lpfc_fast_path_event
*ret
;
297 /* If there are lot of fast event do not exhaust memory due to this */
298 if (atomic_read(&phba
->fast_event_count
) > LPFC_MAX_EVT_COUNT
)
301 ret
= kzalloc(sizeof(struct lpfc_fast_path_event
),
304 atomic_inc(&phba
->fast_event_count
);
305 INIT_LIST_HEAD(&ret
->work_evt
.evt_listp
);
306 ret
->work_evt
.evt
= LPFC_EVT_FASTPATH_MGMT_EVT
;
312 * lpfc_free_fast_evt - Frees event data structure
313 * @phba: Pointer to hba context object.
314 * @evt: Event object which need to be freed.
316 * This function frees the data structure required for posting
320 lpfc_free_fast_evt(struct lpfc_hba
*phba
,
321 struct lpfc_fast_path_event
*evt
) {
323 atomic_dec(&phba
->fast_event_count
);
328 * lpfc_send_fastpath_evt - Posts events generated from fast path
329 * @phba: Pointer to hba context object.
330 * @evtp: Event data structure.
332 * This function is called from worker thread, when the interrupt
333 * context need to post an event. This function posts the event
334 * to fc transport netlink interface.
337 lpfc_send_fastpath_evt(struct lpfc_hba
*phba
,
338 struct lpfc_work_evt
*evtp
)
340 unsigned long evt_category
, evt_sub_category
;
341 struct lpfc_fast_path_event
*fast_evt_data
;
343 uint32_t evt_data_size
;
344 struct Scsi_Host
*shost
;
346 fast_evt_data
= container_of(evtp
, struct lpfc_fast_path_event
,
349 evt_category
= (unsigned long) fast_evt_data
->un
.fabric_evt
.event_type
;
350 evt_sub_category
= (unsigned long) fast_evt_data
->un
.
351 fabric_evt
.subcategory
;
352 shost
= lpfc_shost_from_vport(fast_evt_data
->vport
);
353 if (evt_category
== FC_REG_FABRIC_EVENT
) {
354 if (evt_sub_category
== LPFC_EVENT_FCPRDCHKERR
) {
355 evt_data
= (char *) &fast_evt_data
->un
.read_check_error
;
356 evt_data_size
= sizeof(fast_evt_data
->un
.
358 } else if ((evt_sub_category
== LPFC_EVENT_FABRIC_BUSY
) ||
359 (evt_sub_category
== LPFC_EVENT_PORT_BUSY
)) {
360 evt_data
= (char *) &fast_evt_data
->un
.fabric_evt
;
361 evt_data_size
= sizeof(fast_evt_data
->un
.fabric_evt
);
363 lpfc_free_fast_evt(phba
, fast_evt_data
);
366 } else if (evt_category
== FC_REG_SCSI_EVENT
) {
367 switch (evt_sub_category
) {
368 case LPFC_EVENT_QFULL
:
369 case LPFC_EVENT_DEVBSY
:
370 evt_data
= (char *) &fast_evt_data
->un
.scsi_evt
;
371 evt_data_size
= sizeof(fast_evt_data
->un
.scsi_evt
);
373 case LPFC_EVENT_CHECK_COND
:
374 evt_data
= (char *) &fast_evt_data
->un
.check_cond_evt
;
375 evt_data_size
= sizeof(fast_evt_data
->un
.
378 case LPFC_EVENT_VARQUEDEPTH
:
379 evt_data
= (char *) &fast_evt_data
->un
.queue_depth_evt
;
380 evt_data_size
= sizeof(fast_evt_data
->un
.
384 lpfc_free_fast_evt(phba
, fast_evt_data
);
388 lpfc_free_fast_evt(phba
, fast_evt_data
);
392 fc_host_post_vendor_event(shost
,
393 fc_get_event_number(),
398 lpfc_free_fast_evt(phba
, fast_evt_data
);
403 lpfc_work_list_done(struct lpfc_hba
*phba
)
405 struct lpfc_work_evt
*evtp
= NULL
;
406 struct lpfc_nodelist
*ndlp
;
409 spin_lock_irq(&phba
->hbalock
);
410 while (!list_empty(&phba
->work_list
)) {
411 list_remove_head((&phba
->work_list
), evtp
, typeof(*evtp
),
413 spin_unlock_irq(&phba
->hbalock
);
416 case LPFC_EVT_ELS_RETRY
:
417 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
418 lpfc_els_retry_delay_handler(ndlp
);
419 free_evt
= 0; /* evt is part of ndlp */
420 /* decrement the node reference count held
421 * for this queued work
425 case LPFC_EVT_DEV_LOSS
:
426 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
427 lpfc_dev_loss_tmo_handler(ndlp
);
429 /* decrement the node reference count held for
434 case LPFC_EVT_ONLINE
:
435 if (phba
->link_state
< LPFC_LINK_DOWN
)
436 *(int *) (evtp
->evt_arg1
) = lpfc_online(phba
);
438 *(int *) (evtp
->evt_arg1
) = 0;
439 complete((struct completion
*)(evtp
->evt_arg2
));
441 case LPFC_EVT_OFFLINE_PREP
:
442 if (phba
->link_state
>= LPFC_LINK_DOWN
)
443 lpfc_offline_prep(phba
);
444 *(int *)(evtp
->evt_arg1
) = 0;
445 complete((struct completion
*)(evtp
->evt_arg2
));
447 case LPFC_EVT_OFFLINE
:
449 lpfc_sli_brdrestart(phba
);
450 *(int *)(evtp
->evt_arg1
) =
451 lpfc_sli_brdready(phba
, HS_FFRDY
| HS_MBRDY
);
452 lpfc_unblock_mgmt_io(phba
);
453 complete((struct completion
*)(evtp
->evt_arg2
));
455 case LPFC_EVT_WARM_START
:
457 lpfc_reset_barrier(phba
);
458 lpfc_sli_brdreset(phba
);
459 lpfc_hba_down_post(phba
);
460 *(int *)(evtp
->evt_arg1
) =
461 lpfc_sli_brdready(phba
, HS_MBRDY
);
462 lpfc_unblock_mgmt_io(phba
);
463 complete((struct completion
*)(evtp
->evt_arg2
));
467 *(int *)(evtp
->evt_arg1
)
468 = (phba
->pport
->stopped
)
469 ? 0 : lpfc_sli_brdkill(phba
);
470 lpfc_unblock_mgmt_io(phba
);
471 complete((struct completion
*)(evtp
->evt_arg2
));
473 case LPFC_EVT_FASTPATH_MGMT_EVT
:
474 lpfc_send_fastpath_evt(phba
, evtp
);
480 spin_lock_irq(&phba
->hbalock
);
482 spin_unlock_irq(&phba
->hbalock
);
487 lpfc_work_done(struct lpfc_hba
*phba
)
489 struct lpfc_sli_ring
*pring
;
490 uint32_t ha_copy
, status
, control
, work_port_events
;
491 struct lpfc_vport
**vports
;
492 struct lpfc_vport
*vport
;
495 spin_lock_irq(&phba
->hbalock
);
496 ha_copy
= phba
->work_ha
;
498 spin_unlock_irq(&phba
->hbalock
);
500 /* First, try to post the next mailbox command to SLI4 device */
501 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
)
502 lpfc_sli4_post_async_mbox(phba
);
504 if (ha_copy
& HA_ERATT
)
505 /* Handle the error attention event */
506 lpfc_handle_eratt(phba
);
508 if (ha_copy
& HA_MBATT
)
509 lpfc_sli_handle_mb_event(phba
);
511 if (ha_copy
& HA_LATT
)
512 lpfc_handle_latt(phba
);
514 /* Process SLI4 events */
515 if (phba
->pci_dev_grp
== LPFC_PCI_DEV_OC
) {
516 if (phba
->hba_flag
& FCP_XRI_ABORT_EVENT
)
517 lpfc_sli4_fcp_xri_abort_event_proc(phba
);
518 if (phba
->hba_flag
& ELS_XRI_ABORT_EVENT
)
519 lpfc_sli4_els_xri_abort_event_proc(phba
);
520 if (phba
->hba_flag
& ASYNC_EVENT
)
521 lpfc_sli4_async_event_proc(phba
);
522 if (phba
->hba_flag
& HBA_POST_RECEIVE_BUFFER
) {
523 spin_lock_irq(&phba
->hbalock
);
524 phba
->hba_flag
&= ~HBA_POST_RECEIVE_BUFFER
;
525 spin_unlock_irq(&phba
->hbalock
);
526 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
530 vports
= lpfc_create_vport_work_array(phba
);
532 for (i
= 0; i
<= phba
->max_vports
; i
++) {
534 * We could have no vports in array if unloading, so if
535 * this happens then just use the pport
537 if (vports
[i
] == NULL
&& i
== 0)
543 spin_lock_irq(&vport
->work_port_lock
);
544 work_port_events
= vport
->work_port_events
;
545 vport
->work_port_events
&= ~work_port_events
;
546 spin_unlock_irq(&vport
->work_port_lock
);
547 if (work_port_events
& WORKER_DISC_TMO
)
548 lpfc_disc_timeout_handler(vport
);
549 if (work_port_events
& WORKER_ELS_TMO
)
550 lpfc_els_timeout_handler(vport
);
551 if (work_port_events
& WORKER_HB_TMO
)
552 lpfc_hb_timeout_handler(phba
);
553 if (work_port_events
& WORKER_MBOX_TMO
)
554 lpfc_mbox_timeout_handler(phba
);
555 if (work_port_events
& WORKER_FABRIC_BLOCK_TMO
)
556 lpfc_unblock_fabric_iocbs(phba
);
557 if (work_port_events
& WORKER_FDMI_TMO
)
558 lpfc_fdmi_timeout_handler(vport
);
559 if (work_port_events
& WORKER_RAMP_DOWN_QUEUE
)
560 lpfc_ramp_down_queue_handler(phba
);
561 if (work_port_events
& WORKER_RAMP_UP_QUEUE
)
562 lpfc_ramp_up_queue_handler(phba
);
564 lpfc_destroy_vport_work_array(phba
, vports
);
566 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
567 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
568 status
>>= (4*LPFC_ELS_RING
);
569 if ((status
& HA_RXMASK
) ||
570 (pring
->flag
& LPFC_DEFERRED_RING_EVENT
) ||
571 (phba
->hba_flag
& HBA_SP_QUEUE_EVT
)) {
572 if (pring
->flag
& LPFC_STOP_IOCB_EVENT
) {
573 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
574 /* Set the lpfc data pending flag */
575 set_bit(LPFC_DATA_READY
, &phba
->data_flags
);
577 pring
->flag
&= ~LPFC_DEFERRED_RING_EVENT
;
578 lpfc_sli_handle_slow_ring_event(phba
, pring
,
583 * Turn on Ring interrupts
585 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
586 spin_lock_irq(&phba
->hbalock
);
587 control
= readl(phba
->HCregaddr
);
588 if (!(control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
))) {
589 lpfc_debugfs_slow_ring_trc(phba
,
590 "WRK Enable ring: cntl:x%x hacopy:x%x",
591 control
, ha_copy
, 0);
593 control
|= (HC_R0INT_ENA
<< LPFC_ELS_RING
);
594 writel(control
, phba
->HCregaddr
);
595 readl(phba
->HCregaddr
); /* flush */
597 lpfc_debugfs_slow_ring_trc(phba
,
598 "WRK Ring ok: cntl:x%x hacopy:x%x",
599 control
, ha_copy
, 0);
601 spin_unlock_irq(&phba
->hbalock
);
604 lpfc_work_list_done(phba
);
608 lpfc_do_work(void *p
)
610 struct lpfc_hba
*phba
= p
;
613 set_user_nice(current
, -20);
614 phba
->data_flags
= 0;
616 while (!kthread_should_stop()) {
617 /* wait and check worker queue activities */
618 rc
= wait_event_interruptible(phba
->work_waitq
,
619 (test_and_clear_bit(LPFC_DATA_READY
,
621 || kthread_should_stop()));
622 /* Signal wakeup shall terminate the worker thread */
624 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
625 "0433 Wakeup on signal: rc=x%x\n", rc
);
629 /* Attend pending lpfc data processing */
630 lpfc_work_done(phba
);
632 phba
->worker_thread
= NULL
;
633 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
634 "0432 Worker thread stopped.\n");
639 * This is only called to handle FC worker events. Since this a rare
640 * occurance, we allocate a struct lpfc_work_evt structure here instead of
641 * embedding it in the IOCB.
644 lpfc_workq_post_event(struct lpfc_hba
*phba
, void *arg1
, void *arg2
,
647 struct lpfc_work_evt
*evtp
;
651 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
652 * be queued to worker thread for processing
654 evtp
= kmalloc(sizeof(struct lpfc_work_evt
), GFP_ATOMIC
);
658 evtp
->evt_arg1
= arg1
;
659 evtp
->evt_arg2
= arg2
;
662 spin_lock_irqsave(&phba
->hbalock
, flags
);
663 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
664 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
666 lpfc_worker_wake_up(phba
);
672 lpfc_cleanup_rpis(struct lpfc_vport
*vport
, int remove
)
674 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
675 struct lpfc_hba
*phba
= vport
->phba
;
676 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
679 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
680 if (!NLP_CHK_NODE_ACT(ndlp
))
682 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
684 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) ||
685 ((vport
->port_type
== LPFC_NPIV_PORT
) &&
686 (ndlp
->nlp_DID
== NameServer_DID
)))
687 lpfc_unreg_rpi(vport
, ndlp
);
689 /* Leave Fabric nodes alone on link down */
690 if ((phba
->sli_rev
< LPFC_SLI_REV4
) &&
691 (!remove
&& ndlp
->nlp_type
& NLP_FABRIC
))
693 rc
= lpfc_disc_state_machine(vport
, ndlp
, NULL
,
696 : NLP_EVT_DEVICE_RECOVERY
);
698 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) {
699 lpfc_mbx_unreg_vpi(vport
);
700 spin_lock_irq(shost
->host_lock
);
701 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
702 spin_unlock_irq(shost
->host_lock
);
707 lpfc_port_link_failure(struct lpfc_vport
*vport
)
709 /* Cleanup any outstanding received buffers */
710 lpfc_cleanup_rcv_buffers(vport
);
712 /* Cleanup any outstanding RSCN activity */
713 lpfc_els_flush_rscn(vport
);
715 /* Cleanup any outstanding ELS commands */
716 lpfc_els_flush_cmd(vport
);
718 lpfc_cleanup_rpis(vport
, 0);
720 /* Turn off discovery timer if its running */
721 lpfc_can_disctmo(vport
);
725 lpfc_linkdown_port(struct lpfc_vport
*vport
)
727 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
729 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKDOWN
, 0);
731 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
732 "Link Down: state:x%x rtry:x%x flg:x%x",
733 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
735 lpfc_port_link_failure(vport
);
740 lpfc_linkdown(struct lpfc_hba
*phba
)
742 struct lpfc_vport
*vport
= phba
->pport
;
743 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
744 struct lpfc_vport
**vports
;
748 if (phba
->link_state
== LPFC_LINK_DOWN
)
751 /* Block all SCSI stack I/Os */
752 lpfc_scsi_dev_block(phba
);
754 spin_lock_irq(&phba
->hbalock
);
755 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_DISCOVERED
);
756 if (phba
->link_state
> LPFC_LINK_DOWN
) {
757 phba
->link_state
= LPFC_LINK_DOWN
;
758 phba
->pport
->fc_flag
&= ~FC_LBIT
;
760 spin_unlock_irq(&phba
->hbalock
);
761 vports
= lpfc_create_vport_work_array(phba
);
763 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
764 /* Issue a LINK DOWN event to all nodes */
765 lpfc_linkdown_port(vports
[i
]);
767 lpfc_destroy_vport_work_array(phba
, vports
);
768 /* Clean up any firmware default rpi's */
769 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
771 lpfc_unreg_did(phba
, 0xffff, 0xffffffff, mb
);
773 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
774 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
775 == MBX_NOT_FINISHED
) {
776 mempool_free(mb
, phba
->mbox_mem_pool
);
780 /* Setup myDID for link up if we are in pt2pt mode */
781 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
782 phba
->pport
->fc_myDID
= 0;
783 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
785 lpfc_config_link(phba
, mb
);
786 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
788 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
789 == MBX_NOT_FINISHED
) {
790 mempool_free(mb
, phba
->mbox_mem_pool
);
793 spin_lock_irq(shost
->host_lock
);
794 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
795 spin_unlock_irq(shost
->host_lock
);
802 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
804 struct lpfc_nodelist
*ndlp
;
806 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
807 if (!NLP_CHK_NODE_ACT(ndlp
))
809 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
811 if (ndlp
->nlp_type
& NLP_FABRIC
) {
812 /* On Linkup its safe to clean up the ndlp
813 * from Fabric connections.
815 if (ndlp
->nlp_DID
!= Fabric_DID
)
816 lpfc_unreg_rpi(vport
, ndlp
);
817 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
818 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
819 /* Fail outstanding IO now since device is
822 lpfc_unreg_rpi(vport
, ndlp
);
828 lpfc_linkup_port(struct lpfc_vport
*vport
)
830 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
831 struct lpfc_hba
*phba
= vport
->phba
;
833 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
836 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
837 "Link Up: top:x%x speed:x%x flg:x%x",
838 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
840 /* If NPIV is not enabled, only bring the physical port up */
841 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
842 (vport
!= phba
->pport
))
845 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKUP
, 0);
847 spin_lock_irq(shost
->host_lock
);
848 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
849 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
850 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
851 vport
->fc_ns_retry
= 0;
852 spin_unlock_irq(shost
->host_lock
);
854 if (vport
->fc_flag
& FC_LBIT
)
855 lpfc_linkup_cleanup_nodes(vport
);
860 lpfc_linkup(struct lpfc_hba
*phba
)
862 struct lpfc_vport
**vports
;
865 phba
->link_state
= LPFC_LINK_UP
;
867 /* Unblock fabric iocbs if they are blocked */
868 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
869 del_timer_sync(&phba
->fabric_block_timer
);
871 vports
= lpfc_create_vport_work_array(phba
);
873 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
874 lpfc_linkup_port(vports
[i
]);
875 lpfc_destroy_vport_work_array(phba
, vports
);
876 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
877 (phba
->sli_rev
< LPFC_SLI_REV4
))
878 lpfc_issue_clear_la(phba
, phba
->pport
);
884 * This routine handles processing a CLEAR_LA mailbox
885 * command upon completion. It is setup in the LPFC_MBOXQ
886 * as the completion routine when the command is
887 * handed off to the SLI layer.
890 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
892 struct lpfc_vport
*vport
= pmb
->vport
;
893 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
894 struct lpfc_sli
*psli
= &phba
->sli
;
895 MAILBOX_t
*mb
= &pmb
->u
.mb
;
898 /* Since we don't do discovery right now, turn these off here */
899 psli
->ring
[psli
->extra_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
900 psli
->ring
[psli
->fcp_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
901 psli
->ring
[psli
->next_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
903 /* Check for error */
904 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
905 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
906 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
907 "0320 CLEAR_LA mbxStatus error x%x hba "
909 mb
->mbxStatus
, vport
->port_state
);
910 phba
->link_state
= LPFC_HBA_ERROR
;
914 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
915 phba
->link_state
= LPFC_HBA_READY
;
917 spin_lock_irq(&phba
->hbalock
);
918 psli
->sli_flag
|= LPFC_PROCESS_LA
;
919 control
= readl(phba
->HCregaddr
);
920 control
|= HC_LAINT_ENA
;
921 writel(control
, phba
->HCregaddr
);
922 readl(phba
->HCregaddr
); /* flush */
923 spin_unlock_irq(&phba
->hbalock
);
924 mempool_free(pmb
, phba
->mbox_mem_pool
);
928 /* Device Discovery completes */
929 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
930 "0225 Device Discovery completes\n");
931 mempool_free(pmb
, phba
->mbox_mem_pool
);
933 spin_lock_irq(shost
->host_lock
);
934 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
935 spin_unlock_irq(shost
->host_lock
);
937 lpfc_can_disctmo(vport
);
939 /* turn on Link Attention interrupts */
941 spin_lock_irq(&phba
->hbalock
);
942 psli
->sli_flag
|= LPFC_PROCESS_LA
;
943 control
= readl(phba
->HCregaddr
);
944 control
|= HC_LAINT_ENA
;
945 writel(control
, phba
->HCregaddr
);
946 readl(phba
->HCregaddr
); /* flush */
947 spin_unlock_irq(&phba
->hbalock
);
954 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
956 struct lpfc_vport
*vport
= pmb
->vport
;
958 if (pmb
->u
.mb
.mbxStatus
)
961 mempool_free(pmb
, phba
->mbox_mem_pool
);
963 if (phba
->fc_topology
== TOPOLOGY_LOOP
&&
964 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
965 !(vport
->fc_flag
& FC_LBIT
)) {
966 /* Need to wait for FAN - use discovery timer
967 * for timeout. port_state is identically
968 * LPFC_LOCAL_CFG_LINK while waiting for FAN
970 lpfc_set_disctmo(vport
);
974 /* Start discovery by sending a FLOGI. port_state is identically
975 * LPFC_FLOGI while waiting for FLOGI cmpl
977 if (vport
->port_state
!= LPFC_FLOGI
) {
978 lpfc_initial_flogi(vport
);
983 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
984 "0306 CONFIG_LINK mbxStatus error x%x "
986 pmb
->u
.mb
.mbxStatus
, vport
->port_state
);
987 mempool_free(pmb
, phba
->mbox_mem_pool
);
991 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
992 "0200 CONFIG_LINK bad hba state x%x\n",
995 lpfc_issue_clear_la(phba
, vport
);
1000 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1002 struct lpfc_vport
*vport
= mboxq
->vport
;
1003 unsigned long flags
;
1005 if (mboxq
->u
.mb
.mbxStatus
) {
1006 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1007 "2017 REG_FCFI mbxStatus error x%x "
1009 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
1010 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1014 /* Start FCoE discovery by sending a FLOGI. */
1015 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
, &mboxq
->u
.mqe
.un
.reg_fcfi
);
1016 /* Set the FCFI registered flag */
1017 spin_lock_irqsave(&phba
->hbalock
, flags
);
1018 phba
->fcf
.fcf_flag
|= FCF_REGISTERED
;
1019 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1020 /* If there is a pending FCoE event, restart FCF table scan. */
1021 if (lpfc_check_pending_fcoe_event(phba
, 1)) {
1022 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1025 spin_lock_irqsave(&phba
->hbalock
, flags
);
1026 phba
->fcf
.fcf_flag
|= (FCF_DISCOVERED
| FCF_IN_USE
);
1027 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1028 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1029 if (vport
->port_state
!= LPFC_FLOGI
)
1030 lpfc_initial_flogi(vport
);
1032 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1037 * lpfc_fab_name_match - Check if the fcf fabric name match.
1038 * @fab_name: pointer to fabric name.
1039 * @new_fcf_record: pointer to fcf record.
1041 * This routine compare the fcf record's fabric name with provided
1042 * fabric name. If the fabric name are identical this function
1043 * returns 1 else return 0.
1046 lpfc_fab_name_match(uint8_t *fab_name
, struct fcf_record
*new_fcf_record
)
1049 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
)) &&
1051 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
)) &&
1053 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
)) &&
1055 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
)) &&
1057 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
)) &&
1059 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
)) &&
1061 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
)) &&
1063 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
)))
1070 * lpfc_sw_name_match - Check if the fcf switch name match.
1071 * @fab_name: pointer to fabric name.
1072 * @new_fcf_record: pointer to fcf record.
1074 * This routine compare the fcf record's switch name with provided
1075 * switch name. If the switch name are identical this function
1076 * returns 1 else return 0.
1079 lpfc_sw_name_match(uint8_t *sw_name
, struct fcf_record
*new_fcf_record
)
1082 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
)) &&
1084 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
)) &&
1086 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
)) &&
1088 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
)) &&
1090 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
)) &&
1092 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
)) &&
1094 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
)) &&
1096 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
)))
1103 * lpfc_mac_addr_match - Check if the fcf mac address match.
1104 * @phba: pointer to lpfc hba data structure.
1105 * @new_fcf_record: pointer to fcf record.
1107 * This routine compare the fcf record's mac address with HBA's
1108 * FCF mac address. If the mac addresses are identical this function
1109 * returns 1 else return 0.
1112 lpfc_mac_addr_match(struct lpfc_hba
*phba
, struct fcf_record
*new_fcf_record
)
1114 if ((phba
->fcf
.mac_addr
[0] ==
1115 bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
)) &&
1116 (phba
->fcf
.mac_addr
[1] ==
1117 bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
)) &&
1118 (phba
->fcf
.mac_addr
[2] ==
1119 bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
)) &&
1120 (phba
->fcf
.mac_addr
[3] ==
1121 bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
)) &&
1122 (phba
->fcf
.mac_addr
[4] ==
1123 bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
)) &&
1124 (phba
->fcf
.mac_addr
[5] ==
1125 bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
)))
1132 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1133 * @phba: pointer to lpfc hba data structure.
1134 * @new_fcf_record: pointer to fcf record.
1136 * This routine copies the FCF information from the FCF
1137 * record to lpfc_hba data structure.
1140 lpfc_copy_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*new_fcf_record
)
1142 phba
->fcf
.fabric_name
[0] =
1143 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
);
1144 phba
->fcf
.fabric_name
[1] =
1145 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
);
1146 phba
->fcf
.fabric_name
[2] =
1147 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
);
1148 phba
->fcf
.fabric_name
[3] =
1149 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
);
1150 phba
->fcf
.fabric_name
[4] =
1151 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
);
1152 phba
->fcf
.fabric_name
[5] =
1153 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
);
1154 phba
->fcf
.fabric_name
[6] =
1155 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
);
1156 phba
->fcf
.fabric_name
[7] =
1157 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
);
1158 phba
->fcf
.mac_addr
[0] =
1159 bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
);
1160 phba
->fcf
.mac_addr
[1] =
1161 bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
);
1162 phba
->fcf
.mac_addr
[2] =
1163 bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
);
1164 phba
->fcf
.mac_addr
[3] =
1165 bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
);
1166 phba
->fcf
.mac_addr
[4] =
1167 bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
);
1168 phba
->fcf
.mac_addr
[5] =
1169 bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
);
1170 phba
->fcf
.fcf_indx
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1171 phba
->fcf
.priority
= new_fcf_record
->fip_priority
;
1172 phba
->fcf
.switch_name
[0] =
1173 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
);
1174 phba
->fcf
.switch_name
[1] =
1175 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
);
1176 phba
->fcf
.switch_name
[2] =
1177 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
);
1178 phba
->fcf
.switch_name
[3] =
1179 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
);
1180 phba
->fcf
.switch_name
[4] =
1181 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
);
1182 phba
->fcf
.switch_name
[5] =
1183 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
);
1184 phba
->fcf
.switch_name
[6] =
1185 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
);
1186 phba
->fcf
.switch_name
[7] =
1187 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
);
1191 * lpfc_register_fcf - Register the FCF with hba.
1192 * @phba: pointer to lpfc hba data structure.
1194 * This routine issues a register fcfi mailbox command to register
1198 lpfc_register_fcf(struct lpfc_hba
*phba
)
1200 LPFC_MBOXQ_t
*fcf_mbxq
;
1202 unsigned long flags
;
1204 spin_lock_irqsave(&phba
->hbalock
, flags
);
1206 /* If the FCF is not availabe do nothing. */
1207 if (!(phba
->fcf
.fcf_flag
& FCF_AVAILABLE
)) {
1208 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1209 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1213 /* The FCF is already registered, start discovery */
1214 if (phba
->fcf
.fcf_flag
& FCF_REGISTERED
) {
1215 phba
->fcf
.fcf_flag
|= (FCF_DISCOVERED
| FCF_IN_USE
);
1216 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1217 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1218 if (phba
->pport
->port_state
!= LPFC_FLOGI
)
1219 lpfc_initial_flogi(phba
->pport
);
1222 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1224 fcf_mbxq
= mempool_alloc(phba
->mbox_mem_pool
,
1227 spin_lock_irqsave(&phba
->hbalock
, flags
);
1228 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1229 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1233 lpfc_reg_fcfi(phba
, fcf_mbxq
);
1234 fcf_mbxq
->vport
= phba
->pport
;
1235 fcf_mbxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_fcfi
;
1236 rc
= lpfc_sli_issue_mbox(phba
, fcf_mbxq
, MBX_NOWAIT
);
1237 if (rc
== MBX_NOT_FINISHED
) {
1238 spin_lock_irqsave(&phba
->hbalock
, flags
);
1239 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1240 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1241 mempool_free(fcf_mbxq
, phba
->mbox_mem_pool
);
1248 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1249 * @phba: pointer to lpfc hba data structure.
1250 * @new_fcf_record: pointer to fcf record.
1251 * @boot_flag: Indicates if this record used by boot bios.
1252 * @addr_mode: The address mode to be used by this FCF
1254 * This routine compare the fcf record with connect list obtained from the
1255 * config region to decide if this FCF can be used for SAN discovery. It returns
1256 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1257 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1258 * is used by boot bios and addr_mode will indicate the addressing mode to be
1259 * used for this FCF when the function returns.
1260 * If the FCF record need to be used with a particular vlan id, the vlan is
1261 * set in the vlan_id on return of the function. If not VLAN tagging need to
1262 * be used with the FCF vlan_id will be set to 0xFFFF;
1265 lpfc_match_fcf_conn_list(struct lpfc_hba
*phba
,
1266 struct fcf_record
*new_fcf_record
,
1267 uint32_t *boot_flag
, uint32_t *addr_mode
,
1270 struct lpfc_fcf_conn_entry
*conn_entry
;
1271 int i
, j
, fcf_vlan_id
= 0;
1273 /* Find the lowest VLAN id in the FCF record */
1274 for (i
= 0; i
< 512; i
++) {
1275 if (new_fcf_record
->vlan_bitmap
[i
]) {
1276 fcf_vlan_id
= i
* 8;
1278 while (!((new_fcf_record
->vlan_bitmap
[i
] >> j
) & 1)) {
1286 /* If FCF not available return 0 */
1287 if (!bf_get(lpfc_fcf_record_fcf_avail
, new_fcf_record
) ||
1288 !bf_get(lpfc_fcf_record_fcf_valid
, new_fcf_record
))
1291 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
1293 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1295 if (phba
->valid_vlan
)
1296 *vlan_id
= phba
->vlan_id
;
1303 * If there are no FCF connection table entry, driver connect to all
1306 if (list_empty(&phba
->fcf_conn_rec_list
)) {
1308 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1312 * When there are no FCF connect entries, use driver's default
1313 * addressing mode - FPMA.
1315 if (*addr_mode
& LPFC_FCF_FPMA
)
1316 *addr_mode
= LPFC_FCF_FPMA
;
1318 /* If FCF record report a vlan id use that vlan id */
1320 *vlan_id
= fcf_vlan_id
;
1326 list_for_each_entry(conn_entry
, &phba
->fcf_conn_rec_list
, list
) {
1327 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_VALID
))
1330 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_FBNM_VALID
) &&
1331 !lpfc_fab_name_match(conn_entry
->conn_rec
.fabric_name
,
1334 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_SWNM_VALID
) &&
1335 !lpfc_sw_name_match(conn_entry
->conn_rec
.switch_name
,
1338 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
) {
1340 * If the vlan bit map does not have the bit set for the
1341 * vlan id to be used, then it is not a match.
1343 if (!(new_fcf_record
->vlan_bitmap
1344 [conn_entry
->conn_rec
.vlan_tag
/ 8] &
1345 (1 << (conn_entry
->conn_rec
.vlan_tag
% 8))))
1350 * If connection record does not support any addressing mode,
1351 * skip the FCF record.
1353 if (!(bf_get(lpfc_fcf_record_mac_addr_prov
, new_fcf_record
)
1354 & (LPFC_FCF_FPMA
| LPFC_FCF_SPMA
)))
1358 * Check if the connection record specifies a required
1361 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1362 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)) {
1365 * If SPMA required but FCF not support this continue.
1367 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1368 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1369 new_fcf_record
) & LPFC_FCF_SPMA
))
1373 * If FPMA required but FCF not support this continue.
1375 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1376 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1377 new_fcf_record
) & LPFC_FCF_FPMA
))
1382 * This fcf record matches filtering criteria.
1384 if (conn_entry
->conn_rec
.flags
& FCFCNCT_BOOT
)
1390 * If user did not specify any addressing mode, or if the
1391 * prefered addressing mode specified by user is not supported
1392 * by FCF, allow fabric to pick the addressing mode.
1394 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1397 * If the user specified a required address mode, assign that
1400 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1401 (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)))
1402 *addr_mode
= (conn_entry
->conn_rec
.flags
&
1404 LPFC_FCF_SPMA
: LPFC_FCF_FPMA
;
1406 * If the user specified a prefered address mode, use the
1407 * addr mode only if FCF support the addr_mode.
1409 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1410 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1411 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1412 (*addr_mode
& LPFC_FCF_SPMA
))
1413 *addr_mode
= LPFC_FCF_SPMA
;
1414 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1415 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1416 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1417 (*addr_mode
& LPFC_FCF_FPMA
))
1418 *addr_mode
= LPFC_FCF_FPMA
;
1420 /* If matching connect list has a vlan id, use it */
1421 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
)
1422 *vlan_id
= conn_entry
->conn_rec
.vlan_tag
;
1424 * If no vlan id is specified in connect list, use the vlan id
1427 else if (fcf_vlan_id
)
1428 *vlan_id
= fcf_vlan_id
;
1439 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1440 * @phba: pointer to lpfc hba data structure.
1441 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1443 * This function check if there is any fcoe event pending while driver
1444 * scan FCF entries. If there is any pending event, it will restart the
1445 * FCF saning and return 1 else return 0.
1448 lpfc_check_pending_fcoe_event(struct lpfc_hba
*phba
, uint8_t unreg_fcf
)
1453 * If the Link is up and no FCoE events while in the
1454 * FCF discovery, no need to restart FCF discovery.
1456 if ((phba
->link_state
>= LPFC_LINK_UP
) &&
1457 (phba
->fcoe_eventtag
== phba
->fcoe_eventtag_at_fcf_scan
))
1460 spin_lock_irq(&phba
->hbalock
);
1461 phba
->fcf
.fcf_flag
&= ~FCF_AVAILABLE
;
1462 spin_unlock_irq(&phba
->hbalock
);
1464 if (phba
->link_state
>= LPFC_LINK_UP
)
1465 lpfc_sli4_read_fcf_record(phba
, LPFC_FCOE_FCF_GET_FIRST
);
1468 * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS
1471 spin_lock_irq(&phba
->hbalock
);
1472 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1473 spin_unlock_irq(&phba
->hbalock
);
1477 spin_lock_irq(&phba
->hbalock
);
1478 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
1479 spin_unlock_irq(&phba
->hbalock
);
1480 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1482 lpfc_printf_log(phba
, KERN_ERR
,
1483 LOG_DISCOVERY
|LOG_MBOX
,
1484 "2610 UNREG_FCFI mbox allocation failed\n");
1487 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
1488 mbox
->vport
= phba
->pport
;
1489 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
1490 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1491 if (rc
== MBX_NOT_FINISHED
) {
1492 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
1493 "2611 UNREG_FCFI issue mbox failed\n");
1494 mempool_free(mbox
, phba
->mbox_mem_pool
);
1502 * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox.
1503 * @phba: pointer to lpfc hba data structure.
1504 * @mboxq: pointer to mailbox object.
1506 * This function iterate through all the fcf records available in
1507 * HBA and choose the optimal FCF record for discovery. After finding
1508 * the FCF for discovery it register the FCF record and kick start
1510 * If FCF_IN_USE flag is set in currently used FCF, the routine try to
1511 * use a FCF record which match fabric name and mac address of the
1512 * currently used FCF record.
1513 * If the driver support only one FCF, it will try to use the FCF record
1514 * used by BOOT_BIOS.
1517 lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1520 dma_addr_t phys_addr
;
1522 struct lpfc_mbx_sge sge
;
1523 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
1524 uint32_t shdr_status
, shdr_add_status
;
1525 union lpfc_sli4_cfg_shdr
*shdr
;
1526 struct fcf_record
*new_fcf_record
;
1528 uint32_t boot_flag
, addr_mode
;
1529 uint32_t next_fcf_index
;
1530 unsigned long flags
;
1533 /* If there is pending FCoE event restart FCF table scan */
1534 if (lpfc_check_pending_fcoe_event(phba
, 0)) {
1535 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1539 /* Get the first SGE entry from the non-embedded DMA memory. This
1540 * routine only uses a single SGE.
1542 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
1543 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1544 if (unlikely(!mboxq
->sge_array
)) {
1545 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1546 "2524 Failed to get the non-embedded SGE "
1547 "virtual address\n");
1550 virt_addr
= mboxq
->sge_array
->addr
[0];
1552 shdr
= (union lpfc_sli4_cfg_shdr
*)virt_addr
;
1553 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
1554 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
1557 * The FCF Record was read and there is no reason for the driver
1558 * to maintain the FCF record data or memory. Instead, just need
1559 * to book keeping the FCFIs can be used.
1561 if (shdr_status
|| shdr_add_status
) {
1562 if (shdr_status
== STATUS_FCF_TABLE_EMPTY
) {
1563 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1564 "2726 READ_FCF_RECORD Indicates empty "
1567 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1568 "2521 READ_FCF_RECORD mailbox failed "
1569 "with status x%x add_status x%x, mbx\n",
1570 shdr_status
, shdr_add_status
);
1574 /* Interpreting the returned information of FCF records */
1575 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
1576 lpfc_sli_pcimem_bcopy(read_fcf
, read_fcf
,
1577 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1578 next_fcf_index
= bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx
, read_fcf
);
1580 new_fcf_record
= (struct fcf_record
*)(virt_addr
+
1581 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1582 lpfc_sli_pcimem_bcopy(new_fcf_record
, new_fcf_record
,
1583 sizeof(struct fcf_record
));
1584 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
1586 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
,
1587 &boot_flag
, &addr_mode
,
1590 * If the fcf record does not match with connect list entries
1591 * read the next entry.
1596 * If this is not the first FCF discovery of the HBA, use last
1597 * FCF record for the discovery.
1599 spin_lock_irqsave(&phba
->hbalock
, flags
);
1600 if (phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
1601 if (lpfc_fab_name_match(phba
->fcf
.fabric_name
,
1603 lpfc_sw_name_match(phba
->fcf
.switch_name
,
1605 lpfc_mac_addr_match(phba
, new_fcf_record
)) {
1606 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
1607 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1610 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1613 if (phba
->fcf
.fcf_flag
& FCF_AVAILABLE
) {
1615 * If the current FCF record does not have boot flag
1616 * set and new fcf record has boot flag set, use the
1619 if (boot_flag
&& !(phba
->fcf
.fcf_flag
& FCF_BOOT_ENABLE
)) {
1620 /* Use this FCF record */
1621 lpfc_copy_fcf_record(phba
, new_fcf_record
);
1622 phba
->fcf
.addr_mode
= addr_mode
;
1623 phba
->fcf
.fcf_flag
|= FCF_BOOT_ENABLE
;
1624 if (vlan_id
!= 0xFFFF) {
1625 phba
->fcf
.fcf_flag
|= FCF_VALID_VLAN
;
1626 phba
->fcf
.vlan_id
= vlan_id
;
1628 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1632 * If the current FCF record has boot flag set and the
1633 * new FCF record does not have boot flag, read the next
1636 if (!boot_flag
&& (phba
->fcf
.fcf_flag
& FCF_BOOT_ENABLE
)) {
1637 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1641 * If there is a record with lower priority value for
1642 * the current FCF, use that record.
1644 if (lpfc_fab_name_match(phba
->fcf
.fabric_name
,
1646 (new_fcf_record
->fip_priority
< phba
->fcf
.priority
)) {
1647 /* Use this FCF record */
1648 lpfc_copy_fcf_record(phba
, new_fcf_record
);
1649 phba
->fcf
.addr_mode
= addr_mode
;
1650 if (vlan_id
!= 0xFFFF) {
1651 phba
->fcf
.fcf_flag
|= FCF_VALID_VLAN
;
1652 phba
->fcf
.vlan_id
= vlan_id
;
1654 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1657 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1661 * This is the first available FCF record, use this
1664 lpfc_copy_fcf_record(phba
, new_fcf_record
);
1665 phba
->fcf
.addr_mode
= addr_mode
;
1667 phba
->fcf
.fcf_flag
|= FCF_BOOT_ENABLE
;
1668 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
1669 if (vlan_id
!= 0xFFFF) {
1670 phba
->fcf
.fcf_flag
|= FCF_VALID_VLAN
;
1671 phba
->fcf
.vlan_id
= vlan_id
;
1673 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1677 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1678 if (next_fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
|| next_fcf_index
== 0)
1679 lpfc_register_fcf(phba
);
1681 lpfc_sli4_read_fcf_record(phba
, next_fcf_index
);
1685 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1686 lpfc_register_fcf(phba
);
1692 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
1693 * @phba: pointer to lpfc hba data structure.
1694 * @mboxq: pointer to mailbox data structure.
1696 * This function handles completion of init vpi mailbox command.
1699 lpfc_init_vpi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1701 struct lpfc_vport
*vport
= mboxq
->vport
;
1702 if (mboxq
->u
.mb
.mbxStatus
) {
1703 lpfc_printf_vlog(vport
, KERN_ERR
,
1705 "2609 Init VPI mailbox failed 0x%x\n",
1706 mboxq
->u
.mb
.mbxStatus
);
1707 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1708 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1711 spin_lock_irq(&phba
->hbalock
);
1712 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
1713 spin_unlock_irq(&phba
->hbalock
);
1715 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
1716 lpfc_initial_fdisc(vport
);
1718 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
1719 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1720 "2606 No NPIV Fabric support\n");
1726 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
1727 * @phba: pointer to lpfc hba data structure.
1729 * This function loops through the list of vports on the @phba and issues an
1730 * FDISC if possible.
1733 lpfc_start_fdiscs(struct lpfc_hba
*phba
)
1735 struct lpfc_vport
**vports
;
1737 LPFC_MBOXQ_t
*mboxq
;
1740 vports
= lpfc_create_vport_work_array(phba
);
1741 if (vports
!= NULL
) {
1742 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
1743 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
1745 /* There are no vpi for this vport */
1746 if (vports
[i
]->vpi
> phba
->max_vpi
) {
1747 lpfc_vport_set_state(vports
[i
],
1751 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1752 lpfc_vport_set_state(vports
[i
],
1756 if (vports
[i
]->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
) {
1757 mboxq
= mempool_alloc(phba
->mbox_mem_pool
,
1760 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
1761 LOG_MBOX
, "2607 Failed to allocate "
1762 "init_vpi mailbox\n");
1765 lpfc_init_vpi(phba
, mboxq
, vports
[i
]->vpi
);
1766 mboxq
->vport
= vports
[i
];
1767 mboxq
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
1768 rc
= lpfc_sli_issue_mbox(phba
, mboxq
,
1770 if (rc
== MBX_NOT_FINISHED
) {
1771 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
1772 LOG_MBOX
, "2608 Failed to issue "
1773 "init_vpi mailbox\n");
1775 phba
->mbox_mem_pool
);
1779 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
1780 lpfc_initial_fdisc(vports
[i
]);
1782 lpfc_vport_set_state(vports
[i
],
1783 FC_VPORT_NO_FABRIC_SUPP
);
1784 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
1787 "Fabric support\n");
1791 lpfc_destroy_vport_work_array(phba
, vports
);
1795 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1797 struct lpfc_dmabuf
*dmabuf
= mboxq
->context1
;
1798 struct lpfc_vport
*vport
= mboxq
->vport
;
1800 if (mboxq
->u
.mb
.mbxStatus
) {
1801 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1802 "2018 REG_VFI mbxStatus error x%x "
1804 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
1805 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1806 /* FLOGI failed, use loop map to make discovery list */
1807 lpfc_disc_list_loopmap(vport
);
1808 /* Start discovery */
1809 lpfc_disc_start(vport
);
1812 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1815 /* The VPI is implicitly registered when the VFI is registered */
1816 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
1818 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
1819 lpfc_start_fdiscs(phba
);
1820 lpfc_do_scr_ns_plogi(phba
, vport
);
1824 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1825 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
1831 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1833 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1834 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
1835 struct lpfc_vport
*vport
= pmb
->vport
;
1838 /* Check for error */
1839 if (mb
->mbxStatus
) {
1840 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
1841 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1842 "0319 READ_SPARAM mbxStatus error x%x "
1844 mb
->mbxStatus
, vport
->port_state
);
1845 lpfc_linkdown(phba
);
1849 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
1850 sizeof (struct serv_parm
));
1851 if (phba
->cfg_soft_wwnn
)
1852 u64_to_wwn(phba
->cfg_soft_wwnn
,
1853 vport
->fc_sparam
.nodeName
.u
.wwn
);
1854 if (phba
->cfg_soft_wwpn
)
1855 u64_to_wwn(phba
->cfg_soft_wwpn
,
1856 vport
->fc_sparam
.portName
.u
.wwn
);
1857 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
1858 sizeof(vport
->fc_nodename
));
1859 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
1860 sizeof(vport
->fc_portname
));
1861 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
1862 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
1863 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
1866 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1868 mempool_free(pmb
, phba
->mbox_mem_pool
);
1872 pmb
->context1
= NULL
;
1873 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1875 lpfc_issue_clear_la(phba
, vport
);
1876 mempool_free(pmb
, phba
->mbox_mem_pool
);
1881 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, READ_LA_VAR
*la
)
1883 struct lpfc_vport
*vport
= phba
->pport
;
1884 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
= NULL
;
1886 struct lpfc_dmabuf
*mp
;
1888 struct fcf_record
*fcf_record
;
1890 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1892 spin_lock_irq(&phba
->hbalock
);
1893 switch (la
->UlnkSpeed
) {
1895 phba
->fc_linkspeed
= LA_1GHZ_LINK
;
1898 phba
->fc_linkspeed
= LA_2GHZ_LINK
;
1901 phba
->fc_linkspeed
= LA_4GHZ_LINK
;
1904 phba
->fc_linkspeed
= LA_8GHZ_LINK
;
1907 phba
->fc_linkspeed
= LA_10GHZ_LINK
;
1910 phba
->fc_linkspeed
= LA_UNKNW_LINK
;
1914 phba
->fc_topology
= la
->topology
;
1915 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
1917 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1918 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
1920 /* if npiv is enabled and this adapter supports npiv log
1921 * a message that npiv is not supported in this topology
1923 if (phba
->cfg_enable_npiv
&& phba
->max_vpi
)
1924 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1925 "1309 Link Up Event npiv not supported in loop "
1927 /* Get Loop Map information */
1929 vport
->fc_flag
|= FC_LBIT
;
1931 vport
->fc_myDID
= la
->granted_AL_PA
;
1932 i
= la
->un
.lilpBde64
.tus
.f
.bdeSize
;
1935 phba
->alpa_map
[0] = 0;
1937 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
1948 numalpa
= phba
->alpa_map
[0];
1950 while (j
< numalpa
) {
1951 memset(un
.pamap
, 0, 16);
1952 for (k
= 1; j
< numalpa
; k
++) {
1954 phba
->alpa_map
[j
+ 1];
1959 /* Link Up Event ALPA map */
1960 lpfc_printf_log(phba
,
1963 "1304 Link Up Event "
1964 "ALPA map Data: x%x "
1966 un
.pa
.wd1
, un
.pa
.wd2
,
1967 un
.pa
.wd3
, un
.pa
.wd4
);
1972 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
1973 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1974 (phba
->sli_rev
== 3))
1975 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
1977 vport
->fc_myDID
= phba
->fc_pref_DID
;
1978 vport
->fc_flag
|= FC_LBIT
;
1980 spin_unlock_irq(&phba
->hbalock
);
1984 lpfc_read_sparam(phba
, sparam_mbox
, 0);
1985 sparam_mbox
->vport
= vport
;
1986 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
1987 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
1988 if (rc
== MBX_NOT_FINISHED
) {
1989 mp
= (struct lpfc_dmabuf
*) sparam_mbox
->context1
;
1990 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1992 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
1997 if (!(phba
->hba_flag
& HBA_FCOE_SUPPORT
)) {
1998 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2001 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
2002 lpfc_config_link(phba
, cfglink_mbox
);
2003 cfglink_mbox
->vport
= vport
;
2004 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
2005 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
2006 if (rc
== MBX_NOT_FINISHED
) {
2007 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
2011 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
2013 * Add the driver's default FCF record at FCF index 0 now. This
2014 * is phase 1 implementation that support FCF index 0 and driver
2017 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
2018 fcf_record
= kzalloc(sizeof(struct fcf_record
),
2020 if (unlikely(!fcf_record
)) {
2021 lpfc_printf_log(phba
, KERN_ERR
,
2023 "2554 Could not allocate memmory for "
2029 lpfc_sli4_build_dflt_fcf_record(phba
, fcf_record
,
2030 LPFC_FCOE_FCF_DEF_INDEX
);
2031 rc
= lpfc_sli4_add_fcf_record(phba
, fcf_record
);
2033 lpfc_printf_log(phba
, KERN_ERR
,
2035 "2013 Could not manually add FCF "
2036 "record 0, status %d\n", rc
);
2044 * The driver is expected to do FIP/FCF. Call the port
2045 * and get the FCF Table.
2047 spin_lock_irq(&phba
->hbalock
);
2048 if (phba
->hba_flag
& FCF_DISC_INPROGRESS
) {
2049 spin_unlock_irq(&phba
->hbalock
);
2052 spin_unlock_irq(&phba
->hbalock
);
2053 rc
= lpfc_sli4_read_fcf_record(phba
,
2054 LPFC_FCOE_FCF_GET_FIRST
);
2061 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2062 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2063 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2064 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
2065 lpfc_issue_clear_la(phba
, vport
);
2070 lpfc_enable_la(struct lpfc_hba
*phba
)
2073 struct lpfc_sli
*psli
= &phba
->sli
;
2074 spin_lock_irq(&phba
->hbalock
);
2075 psli
->sli_flag
|= LPFC_PROCESS_LA
;
2076 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
2077 control
= readl(phba
->HCregaddr
);
2078 control
|= HC_LAINT_ENA
;
2079 writel(control
, phba
->HCregaddr
);
2080 readl(phba
->HCregaddr
); /* flush */
2082 spin_unlock_irq(&phba
->hbalock
);
2086 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
2088 lpfc_linkdown(phba
);
2089 lpfc_enable_la(phba
);
2090 lpfc_unregister_unused_fcf(phba
);
2091 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2096 * This routine handles processing a READ_LA mailbox
2097 * command upon completion. It is setup in the LPFC_MBOXQ
2098 * as the completion routine when the command is
2099 * handed off to the SLI layer.
2102 lpfc_mbx_cmpl_read_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2104 struct lpfc_vport
*vport
= pmb
->vport
;
2105 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2107 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2108 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2110 /* Unblock ELS traffic */
2111 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
2112 /* Check for error */
2113 if (mb
->mbxStatus
) {
2114 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
2115 "1307 READ_LA mbox error x%x state x%x\n",
2116 mb
->mbxStatus
, vport
->port_state
);
2117 lpfc_mbx_issue_link_down(phba
);
2118 phba
->link_state
= LPFC_HBA_ERROR
;
2119 goto lpfc_mbx_cmpl_read_la_free_mbuf
;
2122 la
= (READ_LA_VAR
*) &pmb
->u
.mb
.un
.varReadLA
;
2124 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
2126 spin_lock_irq(shost
->host_lock
);
2128 vport
->fc_flag
|= FC_BYPASSED_MODE
;
2130 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
2131 spin_unlock_irq(shost
->host_lock
);
2133 if ((phba
->fc_eventTag
< la
->eventTag
) ||
2134 (phba
->fc_eventTag
== la
->eventTag
)) {
2135 phba
->fc_stat
.LinkMultiEvent
++;
2136 if (la
->attType
== AT_LINK_UP
)
2137 if (phba
->fc_eventTag
!= 0)
2138 lpfc_linkdown(phba
);
2141 phba
->fc_eventTag
= la
->eventTag
;
2143 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
2145 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
2147 phba
->link_events
++;
2148 if (la
->attType
== AT_LINK_UP
&& (!la
->mm
)) {
2149 phba
->fc_stat
.LinkUp
++;
2150 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
2151 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2152 "1306 Link Up Event in loop back mode "
2153 "x%x received Data: x%x x%x x%x x%x\n",
2154 la
->eventTag
, phba
->fc_eventTag
,
2155 la
->granted_AL_PA
, la
->UlnkSpeed
,
2158 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2159 "1303 Link Up Event x%x received "
2160 "Data: x%x x%x x%x x%x x%x x%x %d\n",
2161 la
->eventTag
, phba
->fc_eventTag
,
2162 la
->granted_AL_PA
, la
->UlnkSpeed
,
2165 phba
->wait_4_mlo_maint_flg
);
2167 lpfc_mbx_process_link_up(phba
, la
);
2168 } else if (la
->attType
== AT_LINK_DOWN
) {
2169 phba
->fc_stat
.LinkDown
++;
2170 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
2171 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2172 "1308 Link Down Event in loop back mode "
2174 "Data: x%x x%x x%x\n",
2175 la
->eventTag
, phba
->fc_eventTag
,
2176 phba
->pport
->port_state
, vport
->fc_flag
);
2179 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2180 "1305 Link Down Event x%x received "
2181 "Data: x%x x%x x%x x%x x%x\n",
2182 la
->eventTag
, phba
->fc_eventTag
,
2183 phba
->pport
->port_state
, vport
->fc_flag
,
2186 lpfc_mbx_issue_link_down(phba
);
2188 if (la
->mm
&& la
->attType
== AT_LINK_UP
) {
2189 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
2190 phba
->fc_stat
.LinkDown
++;
2191 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2192 "1312 Link Down Event x%x received "
2193 "Data: x%x x%x x%x\n",
2194 la
->eventTag
, phba
->fc_eventTag
,
2195 phba
->pport
->port_state
, vport
->fc_flag
);
2196 lpfc_mbx_issue_link_down(phba
);
2198 lpfc_enable_la(phba
);
2200 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2201 "1310 Menlo Maint Mode Link up Event x%x rcvd "
2202 "Data: x%x x%x x%x\n",
2203 la
->eventTag
, phba
->fc_eventTag
,
2204 phba
->pport
->port_state
, vport
->fc_flag
);
2206 * The cmnd that triggered this will be waiting for this
2209 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
2210 if (phba
->wait_4_mlo_maint_flg
) {
2211 phba
->wait_4_mlo_maint_flg
= 0;
2212 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
2218 lpfc_issue_clear_la(phba
, vport
);
2219 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
2220 "1311 fa %d\n", la
->fa
);
2223 lpfc_mbx_cmpl_read_la_free_mbuf
:
2224 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2226 mempool_free(pmb
, phba
->mbox_mem_pool
);
2231 * This routine handles processing a REG_LOGIN mailbox
2232 * command upon completion. It is setup in the LPFC_MBOXQ
2233 * as the completion routine when the command is
2234 * handed off to the SLI layer.
2237 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2239 struct lpfc_vport
*vport
= pmb
->vport
;
2240 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2241 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2243 pmb
->context1
= NULL
;
2245 /* Good status, call state machine */
2246 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
2247 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2249 mempool_free(pmb
, phba
->mbox_mem_pool
);
2250 /* decrement the node reference count held for this callback
2259 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2261 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2262 struct lpfc_vport
*vport
= pmb
->vport
;
2263 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2265 switch (mb
->mbxStatus
) {
2269 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2270 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
2274 spin_lock_irq(&phba
->hbalock
);
2275 vport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2276 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2277 spin_unlock_irq(&phba
->hbalock
);
2278 vport
->unreg_vpi_cmpl
= VPORT_OK
;
2279 mempool_free(pmb
, phba
->mbox_mem_pool
);
2281 * This shost reference might have been taken at the beginning of
2282 * lpfc_vport_delete()
2284 if ((vport
->load_flag
& FC_UNLOADING
) && (vport
!= phba
->pport
))
2285 scsi_host_put(shost
);
2289 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
2291 struct lpfc_hba
*phba
= vport
->phba
;
2295 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2299 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
2300 mbox
->vport
= vport
;
2301 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
2302 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2303 if (rc
== MBX_NOT_FINISHED
) {
2304 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
2305 "1800 Could not issue unreg_vpi\n");
2306 mempool_free(mbox
, phba
->mbox_mem_pool
);
2307 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
2314 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2316 struct lpfc_vport
*vport
= pmb
->vport
;
2317 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2318 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2320 switch (mb
->mbxStatus
) {
2324 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2325 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
2327 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2328 spin_lock_irq(shost
->host_lock
);
2329 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2330 spin_unlock_irq(shost
->host_lock
);
2331 vport
->fc_myDID
= 0;
2335 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2336 vport
->num_disc_nodes
= 0;
2337 /* go thru NPR list and issue ELS PLOGIs */
2338 if (vport
->fc_npr_cnt
)
2339 lpfc_els_disc_plogi(vport
);
2341 if (!vport
->num_disc_nodes
) {
2342 spin_lock_irq(shost
->host_lock
);
2343 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2344 spin_unlock_irq(shost
->host_lock
);
2345 lpfc_can_disctmo(vport
);
2347 vport
->port_state
= LPFC_VPORT_READY
;
2350 mempool_free(pmb
, phba
->mbox_mem_pool
);
2355 * lpfc_create_static_vport - Read HBA config region to create static vports.
2356 * @phba: pointer to lpfc hba data structure.
2358 * This routine issue a DUMP mailbox command for config region 22 to get
2359 * the list of static vports to be created. The function create vports
2360 * based on the information returned from the HBA.
2363 lpfc_create_static_vport(struct lpfc_hba
*phba
)
2365 LPFC_MBOXQ_t
*pmb
= NULL
;
2367 struct static_vport_info
*vport_info
;
2369 struct fc_vport_identifiers vport_id
;
2370 struct fc_vport
*new_fc_vport
;
2371 struct Scsi_Host
*shost
;
2372 struct lpfc_vport
*vport
;
2373 uint16_t offset
= 0;
2374 uint8_t *vport_buff
;
2375 struct lpfc_dmabuf
*mp
;
2376 uint32_t byte_count
= 0;
2378 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2380 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2381 "0542 lpfc_create_static_vport failed to"
2382 " allocate mailbox memory\n");
2388 vport_info
= kzalloc(sizeof(struct static_vport_info
), GFP_KERNEL
);
2390 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2391 "0543 lpfc_create_static_vport failed to"
2392 " allocate vport_info\n");
2393 mempool_free(pmb
, phba
->mbox_mem_pool
);
2397 vport_buff
= (uint8_t *) vport_info
;
2399 if (lpfc_dump_static_vport(phba
, pmb
, offset
))
2402 pmb
->vport
= phba
->pport
;
2403 rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
, LPFC_MBOX_TMO
);
2405 if ((rc
!= MBX_SUCCESS
) || mb
->mbxStatus
) {
2406 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2407 "0544 lpfc_create_static_vport failed to"
2408 " issue dump mailbox command ret 0x%x "
2414 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2415 byte_count
= pmb
->u
.mqe
.un
.mb_words
[5];
2416 mp
= (struct lpfc_dmabuf
*) pmb
->context2
;
2417 if (byte_count
> sizeof(struct static_vport_info
) -
2419 byte_count
= sizeof(struct static_vport_info
)
2421 memcpy(vport_buff
+ offset
, mp
->virt
, byte_count
);
2422 offset
+= byte_count
;
2424 if (mb
->un
.varDmp
.word_cnt
>
2425 sizeof(struct static_vport_info
) - offset
)
2426 mb
->un
.varDmp
.word_cnt
=
2427 sizeof(struct static_vport_info
)
2429 byte_count
= mb
->un
.varDmp
.word_cnt
;
2430 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
2431 vport_buff
+ offset
,
2434 offset
+= byte_count
;
2437 } while (byte_count
&&
2438 offset
< sizeof(struct static_vport_info
));
2441 if ((le32_to_cpu(vport_info
->signature
) != VPORT_INFO_SIG
) ||
2442 ((le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
)
2443 != VPORT_INFO_REV
)) {
2444 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2445 "0545 lpfc_create_static_vport bad"
2446 " information header 0x%x 0x%x\n",
2447 le32_to_cpu(vport_info
->signature
),
2448 le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
);
2453 shost
= lpfc_shost_from_vport(phba
->pport
);
2455 for (i
= 0; i
< MAX_STATIC_VPORT_COUNT
; i
++) {
2456 memset(&vport_id
, 0, sizeof(vport_id
));
2457 vport_id
.port_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwpn
);
2458 vport_id
.node_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwnn
);
2459 if (!vport_id
.port_name
|| !vport_id
.node_name
)
2462 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
2463 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
2464 vport_id
.disable
= false;
2465 new_fc_vport
= fc_vport_create(shost
, 0, &vport_id
);
2467 if (!new_fc_vport
) {
2468 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2469 "0546 lpfc_create_static_vport failed to"
2474 vport
= *(struct lpfc_vport
**)new_fc_vport
->dd_data
;
2475 vport
->vport_flag
|= STATIC_VPORT
;
2480 if (rc
!= MBX_TIMEOUT
) {
2481 if (pmb
->context2
) {
2482 mp
= (struct lpfc_dmabuf
*) pmb
->context2
;
2483 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2486 mempool_free(pmb
, phba
->mbox_mem_pool
);
2493 * This routine handles processing a Fabric REG_LOGIN mailbox
2494 * command upon completion. It is setup in the LPFC_MBOXQ
2495 * as the completion routine when the command is
2496 * handed off to the SLI layer.
2499 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2501 struct lpfc_vport
*vport
= pmb
->vport
;
2502 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2503 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2504 struct lpfc_nodelist
*ndlp
;
2506 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2507 pmb
->context1
= NULL
;
2508 pmb
->context2
= NULL
;
2509 if (mb
->mbxStatus
) {
2510 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2511 "0258 Register Fabric login error: 0x%x\n",
2513 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2515 mempool_free(pmb
, phba
->mbox_mem_pool
);
2517 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2518 /* FLOGI failed, use loop map to make discovery list */
2519 lpfc_disc_list_loopmap(vport
);
2521 /* Start discovery */
2522 lpfc_disc_start(vport
);
2523 /* Decrement the reference count to ndlp after the
2524 * reference to the ndlp are done.
2530 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2531 /* Decrement the reference count to ndlp after the reference
2532 * to the ndlp are done.
2538 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2539 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
2540 ndlp
->nlp_type
|= NLP_FABRIC
;
2541 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2543 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
2544 lpfc_start_fdiscs(phba
);
2545 lpfc_do_scr_ns_plogi(phba
, vport
);
2548 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2550 mempool_free(pmb
, phba
->mbox_mem_pool
);
2552 /* Drop the reference count from the mbox at the end after
2553 * all the current reference to the ndlp have been done.
2560 * This routine handles processing a NameServer REG_LOGIN mailbox
2561 * command upon completion. It is setup in the LPFC_MBOXQ
2562 * as the completion routine when the command is
2563 * handed off to the SLI layer.
2566 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2568 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2569 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2570 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2571 struct lpfc_vport
*vport
= pmb
->vport
;
2573 if (mb
->mbxStatus
) {
2575 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2576 "0260 Register NameServer error: 0x%x\n",
2578 /* decrement the node reference count held for this
2579 * callback function.
2582 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2584 mempool_free(pmb
, phba
->mbox_mem_pool
);
2586 /* If no other thread is using the ndlp, free it */
2587 lpfc_nlp_not_used(ndlp
);
2589 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2591 * RegLogin failed, use loop map to make discovery
2594 lpfc_disc_list_loopmap(vport
);
2596 /* Start discovery */
2597 lpfc_disc_start(vport
);
2600 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2604 pmb
->context1
= NULL
;
2606 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2607 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
2608 ndlp
->nlp_type
|= NLP_FABRIC
;
2609 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2611 if (vport
->port_state
< LPFC_VPORT_READY
) {
2612 /* Link up discovery requires Fabric registration. */
2613 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, 0); /* Do this first! */
2614 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
2615 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
2616 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
2617 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
2619 /* Issue SCR just before NameServer GID_FT Query */
2620 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
2623 vport
->fc_ns_retry
= 0;
2624 /* Good status, issue CT Request to NameServer */
2625 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0)) {
2626 /* Cannot issue NameServer Query, so finish up discovery */
2630 /* decrement the node reference count held for this
2631 * callback function.
2634 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2636 mempool_free(pmb
, phba
->mbox_mem_pool
);
2642 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2644 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2645 struct fc_rport
*rport
;
2646 struct lpfc_rport_data
*rdata
;
2647 struct fc_rport_identifiers rport_ids
;
2648 struct lpfc_hba
*phba
= vport
->phba
;
2650 /* Remote port has reappeared. Re-register w/ FC transport */
2651 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
2652 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
2653 rport_ids
.port_id
= ndlp
->nlp_DID
;
2654 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2657 * We leave our node pointer in rport->dd_data when we unregister a
2658 * FCP target port. But fc_remote_port_add zeros the space to which
2659 * rport->dd_data points. So, if we're reusing a previously
2660 * registered port, drop the reference that we took the last time we
2661 * registered the port.
2663 if (ndlp
->rport
&& ndlp
->rport
->dd_data
&&
2664 ((struct lpfc_rport_data
*) ndlp
->rport
->dd_data
)->pnode
== ndlp
)
2667 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
2668 "rport add: did:x%x flg:x%x type x%x",
2669 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
2671 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
2672 if (!rport
|| !get_device(&rport
->dev
)) {
2673 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
2674 "Warning: fc_remote_port_add failed\n");
2678 /* initialize static port data */
2679 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
2680 rport
->supported_classes
= ndlp
->nlp_class_sup
;
2681 rdata
= rport
->dd_data
;
2682 rdata
->pnode
= lpfc_nlp_get(ndlp
);
2684 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
2685 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2686 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
2687 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2690 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
2691 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2693 if ((rport
->scsi_target_id
!= -1) &&
2694 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
2695 ndlp
->nlp_sid
= rport
->scsi_target_id
;
2701 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
2703 struct fc_rport
*rport
= ndlp
->rport
;
2705 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
2706 "rport delete: did:x%x flg:x%x type x%x",
2707 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
2709 fc_remote_port_delete(rport
);
2715 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
2717 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2719 spin_lock_irq(shost
->host_lock
);
2721 case NLP_STE_UNUSED_NODE
:
2722 vport
->fc_unused_cnt
+= count
;
2724 case NLP_STE_PLOGI_ISSUE
:
2725 vport
->fc_plogi_cnt
+= count
;
2727 case NLP_STE_ADISC_ISSUE
:
2728 vport
->fc_adisc_cnt
+= count
;
2730 case NLP_STE_REG_LOGIN_ISSUE
:
2731 vport
->fc_reglogin_cnt
+= count
;
2733 case NLP_STE_PRLI_ISSUE
:
2734 vport
->fc_prli_cnt
+= count
;
2736 case NLP_STE_UNMAPPED_NODE
:
2737 vport
->fc_unmap_cnt
+= count
;
2739 case NLP_STE_MAPPED_NODE
:
2740 vport
->fc_map_cnt
+= count
;
2742 case NLP_STE_NPR_NODE
:
2743 vport
->fc_npr_cnt
+= count
;
2746 spin_unlock_irq(shost
->host_lock
);
2750 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2751 int old_state
, int new_state
)
2753 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2755 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
2756 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
2757 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
2758 ndlp
->nlp_type
|= NLP_FC_NODE
;
2760 if (new_state
== NLP_STE_MAPPED_NODE
)
2761 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
2762 if (new_state
== NLP_STE_NPR_NODE
)
2763 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
2765 /* Transport interface */
2766 if (ndlp
->rport
&& (old_state
== NLP_STE_MAPPED_NODE
||
2767 old_state
== NLP_STE_UNMAPPED_NODE
)) {
2768 vport
->phba
->nport_event_cnt
++;
2769 lpfc_unregister_remote_port(ndlp
);
2772 if (new_state
== NLP_STE_MAPPED_NODE
||
2773 new_state
== NLP_STE_UNMAPPED_NODE
) {
2774 vport
->phba
->nport_event_cnt
++;
2776 * Tell the fc transport about the port, if we haven't
2777 * already. If we have, and it's a scsi entity, be
2778 * sure to unblock any attached scsi devices
2780 lpfc_register_remote_port(vport
, ndlp
);
2782 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
2783 (vport
->stat_data_enabled
)) {
2785 * A new target is discovered, if there is no buffer for
2786 * statistical data collection allocate buffer.
2788 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
2789 sizeof(struct lpfc_scsicmd_bkt
),
2792 if (!ndlp
->lat_data
)
2793 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
2794 "0286 lpfc_nlp_state_cleanup failed to "
2795 "allocate statistical data buffer DID "
2796 "0x%x\n", ndlp
->nlp_DID
);
2799 * if we added to Mapped list, but the remote port
2800 * registration failed or assigned a target id outside
2801 * our presentable range - move the node to the
2804 if (new_state
== NLP_STE_MAPPED_NODE
&&
2806 ndlp
->rport
->scsi_target_id
== -1 ||
2807 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
2808 spin_lock_irq(shost
->host_lock
);
2809 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
2810 spin_unlock_irq(shost
->host_lock
);
2811 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2816 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
2818 static char *states
[] = {
2819 [NLP_STE_UNUSED_NODE
] = "UNUSED",
2820 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
2821 [NLP_STE_ADISC_ISSUE
] = "ADISC",
2822 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
2823 [NLP_STE_PRLI_ISSUE
] = "PRLI",
2824 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
2825 [NLP_STE_MAPPED_NODE
] = "MAPPED",
2826 [NLP_STE_NPR_NODE
] = "NPR",
2829 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
2830 strlcpy(buffer
, states
[state
], size
);
2832 snprintf(buffer
, size
, "unknown (%d)", state
);
2837 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2840 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2841 int old_state
= ndlp
->nlp_state
;
2842 char name1
[16], name2
[16];
2844 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2845 "0904 NPort state transition x%06x, %s -> %s\n",
2847 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
2848 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
2850 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
2851 "node statechg did:x%x old:%d ste:%d",
2852 ndlp
->nlp_DID
, old_state
, state
);
2854 if (old_state
== NLP_STE_NPR_NODE
&&
2855 state
!= NLP_STE_NPR_NODE
)
2856 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2857 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
2858 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
2859 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
2862 if (list_empty(&ndlp
->nlp_listp
)) {
2863 spin_lock_irq(shost
->host_lock
);
2864 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
2865 spin_unlock_irq(shost
->host_lock
);
2866 } else if (old_state
)
2867 lpfc_nlp_counters(vport
, old_state
, -1);
2869 ndlp
->nlp_state
= state
;
2870 lpfc_nlp_counters(vport
, state
, 1);
2871 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
2875 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2877 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2879 if (list_empty(&ndlp
->nlp_listp
)) {
2880 spin_lock_irq(shost
->host_lock
);
2881 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
2882 spin_unlock_irq(shost
->host_lock
);
2887 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2889 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2891 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2892 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
2893 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
2894 spin_lock_irq(shost
->host_lock
);
2895 list_del_init(&ndlp
->nlp_listp
);
2896 spin_unlock_irq(shost
->host_lock
);
2897 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
2898 NLP_STE_UNUSED_NODE
);
2902 lpfc_disable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2904 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2905 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
2906 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
2907 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
2908 NLP_STE_UNUSED_NODE
);
2911 * lpfc_initialize_node - Initialize all fields of node object
2912 * @vport: Pointer to Virtual Port object.
2913 * @ndlp: Pointer to FC node object.
2914 * @did: FC_ID of the node.
2916 * This function is always called when node object need to be initialized.
2917 * It initializes all the fields of the node object. Although the reference
2918 * to phba from @ndlp can be obtained indirectly through it's reference to
2919 * @vport, a direct reference to phba is taken here by @ndlp. This is due
2920 * to the life-span of the @ndlp might go beyond the existence of @vport as
2921 * the final release of ndlp is determined by its reference count. And, the
2922 * operation on @ndlp needs the reference to phba.
2925 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2928 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
2929 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
2930 init_timer(&ndlp
->nlp_delayfunc
);
2931 ndlp
->nlp_delayfunc
.function
= lpfc_els_retry_delay
;
2932 ndlp
->nlp_delayfunc
.data
= (unsigned long)ndlp
;
2933 ndlp
->nlp_DID
= did
;
2934 ndlp
->vport
= vport
;
2935 ndlp
->phba
= vport
->phba
;
2936 ndlp
->nlp_sid
= NLP_NO_SID
;
2937 kref_init(&ndlp
->kref
);
2938 NLP_INT_NODE_ACT(ndlp
);
2939 atomic_set(&ndlp
->cmd_pending
, 0);
2940 ndlp
->cmd_qdepth
= LPFC_MAX_TGT_QDEPTH
;
2943 struct lpfc_nodelist
*
2944 lpfc_enable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2947 struct lpfc_hba
*phba
= vport
->phba
;
2949 unsigned long flags
;
2954 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
2955 /* The ndlp should not be in memory free mode */
2956 if (NLP_CHK_FREE_REQ(ndlp
)) {
2957 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
2958 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2959 "0277 lpfc_enable_node: ndlp:x%p "
2960 "usgmap:x%x refcnt:%d\n",
2961 (void *)ndlp
, ndlp
->nlp_usg_map
,
2962 atomic_read(&ndlp
->kref
.refcount
));
2965 /* The ndlp should not already be in active mode */
2966 if (NLP_CHK_NODE_ACT(ndlp
)) {
2967 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
2968 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2969 "0278 lpfc_enable_node: ndlp:x%p "
2970 "usgmap:x%x refcnt:%d\n",
2971 (void *)ndlp
, ndlp
->nlp_usg_map
,
2972 atomic_read(&ndlp
->kref
.refcount
));
2976 /* Keep the original DID */
2977 did
= ndlp
->nlp_DID
;
2979 /* re-initialize ndlp except of ndlp linked list pointer */
2980 memset((((char *)ndlp
) + sizeof (struct list_head
)), 0,
2981 sizeof (struct lpfc_nodelist
) - sizeof (struct list_head
));
2982 lpfc_initialize_node(vport
, ndlp
, did
);
2984 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
2986 if (state
!= NLP_STE_UNUSED_NODE
)
2987 lpfc_nlp_set_state(vport
, ndlp
, state
);
2989 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
2990 "node enable: did:x%x",
2991 ndlp
->nlp_DID
, 0, 0);
2996 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2999 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
3000 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
3001 * the ndlp from the vport. The ndlp marked as UNUSED on the list
3002 * until ALL other outstanding threads have completed. We check
3003 * that the ndlp not already in the UNUSED state before we proceed.
3005 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
3007 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3013 * Start / ReStart rescue timer for Discovery / RSCN handling
3016 lpfc_set_disctmo(struct lpfc_vport
*vport
)
3018 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3019 struct lpfc_hba
*phba
= vport
->phba
;
3022 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
3023 /* For FAN, timeout should be greater than edtov */
3024 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
3026 /* Normal discovery timeout should be > than ELS/CT timeout
3027 * FC spec states we need 3 * ratov for CT requests
3029 tmo
= ((phba
->fc_ratov
* 3) + 3);
3033 if (!timer_pending(&vport
->fc_disctmo
)) {
3034 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3035 "set disc timer: tmo:x%x state:x%x flg:x%x",
3036 tmo
, vport
->port_state
, vport
->fc_flag
);
3039 mod_timer(&vport
->fc_disctmo
, jiffies
+ HZ
* tmo
);
3040 spin_lock_irq(shost
->host_lock
);
3041 vport
->fc_flag
|= FC_DISC_TMO
;
3042 spin_unlock_irq(shost
->host_lock
);
3044 /* Start Discovery Timer state <hba_state> */
3045 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3046 "0247 Start Discovery Timer state x%x "
3047 "Data: x%x x%lx x%x x%x\n",
3048 vport
->port_state
, tmo
,
3049 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
3050 vport
->fc_adisc_cnt
);
3056 * Cancel rescue timer for Discovery / RSCN handling
3059 lpfc_can_disctmo(struct lpfc_vport
*vport
)
3061 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3062 unsigned long iflags
;
3064 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3065 "can disc timer: state:x%x rtry:x%x flg:x%x",
3066 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
3068 /* Turn off discovery timer if its running */
3069 if (vport
->fc_flag
& FC_DISC_TMO
) {
3070 spin_lock_irqsave(shost
->host_lock
, iflags
);
3071 vport
->fc_flag
&= ~FC_DISC_TMO
;
3072 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
3073 del_timer_sync(&vport
->fc_disctmo
);
3074 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
3075 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
3076 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
3079 /* Cancel Discovery Timer state <hba_state> */
3080 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3081 "0248 Cancel Discovery Timer state x%x "
3082 "Data: x%x x%x x%x\n",
3083 vport
->port_state
, vport
->fc_flag
,
3084 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
3089 * Check specified ring for outstanding IOCB on the SLI queue
3090 * Return true if iocb matches the specified nport
3093 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
3094 struct lpfc_sli_ring
*pring
,
3095 struct lpfc_iocbq
*iocb
,
3096 struct lpfc_nodelist
*ndlp
)
3098 struct lpfc_sli
*psli
= &phba
->sli
;
3099 IOCB_t
*icmd
= &iocb
->iocb
;
3100 struct lpfc_vport
*vport
= ndlp
->vport
;
3102 if (iocb
->vport
!= vport
)
3105 if (pring
->ringno
== LPFC_ELS_RING
) {
3106 switch (icmd
->ulpCommand
) {
3107 case CMD_GEN_REQUEST64_CR
:
3108 if (iocb
->context_un
.ndlp
== ndlp
)
3110 case CMD_ELS_REQUEST64_CR
:
3111 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
3113 case CMD_XMIT_ELS_RSP64_CX
:
3114 if (iocb
->context1
== (uint8_t *) ndlp
)
3117 } else if (pring
->ringno
== psli
->extra_ring
) {
3119 } else if (pring
->ringno
== psli
->fcp_ring
) {
3120 /* Skip match check if waiting to relogin to FCP target */
3121 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3122 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
3125 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
3128 } else if (pring
->ringno
== psli
->next_ring
) {
3135 * Free resources / clean up outstanding I/Os
3136 * associated with nlp_rpi in the LPFC_NODELIST entry.
3139 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
3141 LIST_HEAD(completions
);
3142 struct lpfc_sli
*psli
;
3143 struct lpfc_sli_ring
*pring
;
3144 struct lpfc_iocbq
*iocb
, *next_iocb
;
3147 lpfc_fabric_abort_nport(ndlp
);
3150 * Everything that matches on txcmplq will be returned
3151 * by firmware with a no rpi error.
3154 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
3155 /* Now process each ring */
3156 for (i
= 0; i
< psli
->num_rings
; i
++) {
3157 pring
= &psli
->ring
[i
];
3159 spin_lock_irq(&phba
->hbalock
);
3160 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
,
3163 * Check to see if iocb matches the nport we are
3166 if ((lpfc_check_sli_ndlp(phba
, pring
, iocb
,
3168 /* It matches, so deque and call compl
3170 list_move_tail(&iocb
->list
,
3175 spin_unlock_irq(&phba
->hbalock
);
3179 /* Cancel all the IOCBs from the completions list */
3180 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3187 * Free rpi associated with LPFC_NODELIST entry.
3188 * This routine is called from lpfc_freenode(), when we are removing
3189 * a LPFC_NODELIST entry. It is also called if the driver initiates a
3190 * LOGO that completes successfully, and we are waiting to PLOGI back
3191 * to the remote NPort. In addition, it is called after we receive
3192 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
3193 * we are waiting to PLOGI back to the remote NPort.
3196 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3198 struct lpfc_hba
*phba
= vport
->phba
;
3202 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
3203 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3205 lpfc_unreg_login(phba
, vport
->vpi
, ndlp
->nlp_rpi
, mbox
);
3206 mbox
->vport
= vport
;
3207 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3208 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3209 if (rc
== MBX_NOT_FINISHED
)
3210 mempool_free(mbox
, phba
->mbox_mem_pool
);
3212 lpfc_no_rpi(phba
, ndlp
);
3214 ndlp
->nlp_flag
&= ~NLP_RPI_VALID
;
3215 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3222 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
3224 struct lpfc_hba
*phba
= vport
->phba
;
3228 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3230 lpfc_unreg_login(phba
, vport
->vpi
, 0xffff, mbox
);
3231 mbox
->vport
= vport
;
3232 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3233 mbox
->context1
= NULL
;
3234 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
3235 if (rc
!= MBX_TIMEOUT
)
3236 mempool_free(mbox
, phba
->mbox_mem_pool
);
3238 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
3239 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3240 "1836 Could not issue "
3241 "unreg_login(all_rpis) status %d\n", rc
);
3246 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
3248 struct lpfc_hba
*phba
= vport
->phba
;
3252 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3254 lpfc_unreg_did(phba
, vport
->vpi
, 0xffffffff, mbox
);
3255 mbox
->vport
= vport
;
3256 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3257 mbox
->context1
= NULL
;
3258 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
3259 if (rc
!= MBX_TIMEOUT
)
3260 mempool_free(mbox
, phba
->mbox_mem_pool
);
3262 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
3263 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3264 "1815 Could not issue "
3265 "unreg_did (default rpis) status %d\n",
3271 * Free resources associated with LPFC_NODELIST entry
3272 * so it can be freed.
3275 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3277 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3278 struct lpfc_hba
*phba
= vport
->phba
;
3279 LPFC_MBOXQ_t
*mb
, *nextmb
;
3280 struct lpfc_dmabuf
*mp
;
3282 /* Cleanup node for NPort <nlp_DID> */
3283 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3284 "0900 Cleanup node for NPort x%x "
3285 "Data: x%x x%x x%x\n",
3286 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3287 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3288 if (NLP_CHK_FREE_REQ(ndlp
)) {
3289 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3290 "0280 lpfc_cleanup_node: ndlp:x%p "
3291 "usgmap:x%x refcnt:%d\n",
3292 (void *)ndlp
, ndlp
->nlp_usg_map
,
3293 atomic_read(&ndlp
->kref
.refcount
));
3294 lpfc_dequeue_node(vport
, ndlp
);
3296 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3297 "0281 lpfc_cleanup_node: ndlp:x%p "
3298 "usgmap:x%x refcnt:%d\n",
3299 (void *)ndlp
, ndlp
->nlp_usg_map
,
3300 atomic_read(&ndlp
->kref
.refcount
));
3301 lpfc_disable_node(vport
, ndlp
);
3304 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
3305 if ((mb
= phba
->sli
.mbox_active
)) {
3306 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
3307 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
3308 mb
->context2
= NULL
;
3309 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3313 spin_lock_irq(&phba
->hbalock
);
3314 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
3315 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
3316 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
3317 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
3319 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3322 list_del(&mb
->list
);
3323 mempool_free(mb
, phba
->mbox_mem_pool
);
3324 /* We shall not invoke the lpfc_nlp_put to decrement
3325 * the ndlp reference count as we are in the process
3326 * of lpfc_nlp_release.
3330 spin_unlock_irq(&phba
->hbalock
);
3332 lpfc_els_abort(phba
, ndlp
);
3334 spin_lock_irq(shost
->host_lock
);
3335 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
3336 spin_unlock_irq(shost
->host_lock
);
3338 ndlp
->nlp_last_elscmd
= 0;
3339 del_timer_sync(&ndlp
->nlp_delayfunc
);
3341 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
3342 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
3344 lpfc_unreg_rpi(vport
, ndlp
);
3350 * Check to see if we can free the nlp back to the freelist.
3351 * If we are in the middle of using the nlp in the discovery state
3352 * machine, defer the free till we reach the end of the state machine.
3355 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3357 struct lpfc_hba
*phba
= vport
->phba
;
3358 struct lpfc_rport_data
*rdata
;
3362 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3363 if ((ndlp
->nlp_flag
& NLP_DEFER_RM
) &&
3364 !(ndlp
->nlp_flag
& NLP_RPI_VALID
)) {
3365 /* For this case we need to cleanup the default rpi
3366 * allocated by the firmware.
3368 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
))
3370 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, ndlp
->nlp_DID
,
3371 (uint8_t *) &vport
->fc_sparam
, mbox
, 0);
3373 mempool_free(mbox
, phba
->mbox_mem_pool
);
3376 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3377 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3378 mbox
->vport
= vport
;
3379 mbox
->context2
= NULL
;
3380 rc
=lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3381 if (rc
== MBX_NOT_FINISHED
) {
3382 mempool_free(mbox
, phba
->mbox_mem_pool
);
3387 lpfc_cleanup_node(vport
, ndlp
);
3390 * We can get here with a non-NULL ndlp->rport because when we
3391 * unregister a rport we don't break the rport/node linkage. So if we
3392 * do, make sure we don't leaving any dangling pointers behind.
3395 rdata
= ndlp
->rport
->dd_data
;
3396 rdata
->pnode
= NULL
;
3402 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3405 D_ID mydid
, ndlpdid
, matchdid
;
3407 if (did
== Bcast_DID
)
3410 /* First check for Direct match */
3411 if (ndlp
->nlp_DID
== did
)
3414 /* Next check for area/domain identically equals 0 match */
3415 mydid
.un
.word
= vport
->fc_myDID
;
3416 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
3420 matchdid
.un
.word
= did
;
3421 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
3422 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
3423 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
3424 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
3425 if ((ndlpdid
.un
.b
.domain
== 0) &&
3426 (ndlpdid
.un
.b
.area
== 0)) {
3427 if (ndlpdid
.un
.b
.id
)
3433 matchdid
.un
.word
= ndlp
->nlp_DID
;
3434 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
3435 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
3436 if ((matchdid
.un
.b
.domain
== 0) &&
3437 (matchdid
.un
.b
.area
== 0)) {
3438 if (matchdid
.un
.b
.id
)
3446 /* Search for a nodelist entry */
3447 static struct lpfc_nodelist
*
3448 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
3450 struct lpfc_nodelist
*ndlp
;
3453 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3454 if (lpfc_matchdid(vport
, ndlp
, did
)) {
3455 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
3456 ((uint32_t) ndlp
->nlp_xri
<< 16) |
3457 ((uint32_t) ndlp
->nlp_type
<< 8) |
3458 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
3459 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3460 "0929 FIND node DID "
3461 "Data: x%p x%x x%x x%x\n",
3462 ndlp
, ndlp
->nlp_DID
,
3463 ndlp
->nlp_flag
, data1
);
3468 /* FIND node did <did> NOT FOUND */
3469 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3470 "0932 FIND node did x%x NOT FOUND.\n", did
);
3474 struct lpfc_nodelist
*
3475 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
3477 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3478 struct lpfc_nodelist
*ndlp
;
3480 spin_lock_irq(shost
->host_lock
);
3481 ndlp
= __lpfc_findnode_did(vport
, did
);
3482 spin_unlock_irq(shost
->host_lock
);
3486 struct lpfc_nodelist
*
3487 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
3489 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3490 struct lpfc_nodelist
*ndlp
;
3492 ndlp
= lpfc_findnode_did(vport
, did
);
3494 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
3495 lpfc_rscn_payload_check(vport
, did
) == 0)
3497 ndlp
= (struct lpfc_nodelist
*)
3498 mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
3501 lpfc_nlp_init(vport
, ndlp
, did
);
3502 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
3503 spin_lock_irq(shost
->host_lock
);
3504 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3505 spin_unlock_irq(shost
->host_lock
);
3507 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
3508 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
3511 spin_lock_irq(shost
->host_lock
);
3512 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3513 spin_unlock_irq(shost
->host_lock
);
3517 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
3518 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
3519 if (lpfc_rscn_payload_check(vport
, did
)) {
3520 /* If we've already recieved a PLOGI from this NPort
3521 * we don't need to try to discover it again.
3523 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
3526 /* Since this node is marked for discovery,
3527 * delay timeout is not needed.
3529 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3530 spin_lock_irq(shost
->host_lock
);
3531 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3532 spin_unlock_irq(shost
->host_lock
);
3536 /* If we've already recieved a PLOGI from this NPort,
3537 * or we are already in the process of discovery on it,
3538 * we don't need to try to discover it again.
3540 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
3541 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
3542 ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
3544 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
3545 spin_lock_irq(shost
->host_lock
);
3546 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3547 spin_unlock_irq(shost
->host_lock
);
3552 /* Build a list of nodes to discover based on the loopmap */
3554 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
3556 struct lpfc_hba
*phba
= vport
->phba
;
3558 uint32_t alpa
, index
;
3560 if (!lpfc_is_link_up(phba
))
3563 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
3566 /* Check for loop map present or not */
3567 if (phba
->alpa_map
[0]) {
3568 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
3569 alpa
= phba
->alpa_map
[j
];
3570 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
3572 lpfc_setup_disc_node(vport
, alpa
);
3575 /* No alpamap, so try all alpa's */
3576 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
3577 /* If cfg_scan_down is set, start from highest
3578 * ALPA (0xef) to lowest (0x1).
3580 if (vport
->cfg_scan_down
)
3583 index
= FC_MAXLOOP
- j
- 1;
3584 alpa
= lpfcAlpaArray
[index
];
3585 if ((vport
->fc_myDID
& 0xff) == alpa
)
3587 lpfc_setup_disc_node(vport
, alpa
);
3594 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
3597 struct lpfc_sli
*psli
= &phba
->sli
;
3598 struct lpfc_sli_ring
*extra_ring
= &psli
->ring
[psli
->extra_ring
];
3599 struct lpfc_sli_ring
*fcp_ring
= &psli
->ring
[psli
->fcp_ring
];
3600 struct lpfc_sli_ring
*next_ring
= &psli
->ring
[psli
->next_ring
];
3604 * if it's not a physical port or if we already send
3605 * clear_la then don't send it.
3607 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
3608 (vport
->port_type
!= LPFC_PHYSICAL_PORT
) ||
3609 (phba
->sli_rev
== LPFC_SLI_REV4
))
3612 /* Link up discovery */
3613 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
3614 phba
->link_state
= LPFC_CLEAR_LA
;
3615 lpfc_clear_la(phba
, mbox
);
3616 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
3617 mbox
->vport
= vport
;
3618 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3619 if (rc
== MBX_NOT_FINISHED
) {
3620 mempool_free(mbox
, phba
->mbox_mem_pool
);
3621 lpfc_disc_flush_list(vport
);
3622 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3623 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3624 next_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3625 phba
->link_state
= LPFC_HBA_ERROR
;
3630 /* Reg_vpi to tell firmware to resume normal operations */
3632 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
3634 LPFC_MBOXQ_t
*regvpimbox
;
3636 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3638 lpfc_reg_vpi(vport
, regvpimbox
);
3639 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
3640 regvpimbox
->vport
= vport
;
3641 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
3642 == MBX_NOT_FINISHED
) {
3643 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
3648 /* Start Link up / RSCN discovery on NPR nodes */
3650 lpfc_disc_start(struct lpfc_vport
*vport
)
3652 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3653 struct lpfc_hba
*phba
= vport
->phba
;
3655 uint32_t clear_la_pending
;
3658 if (!lpfc_is_link_up(phba
))
3661 if (phba
->link_state
== LPFC_CLEAR_LA
)
3662 clear_la_pending
= 1;
3664 clear_la_pending
= 0;
3666 if (vport
->port_state
< LPFC_VPORT_READY
)
3667 vport
->port_state
= LPFC_DISC_AUTH
;
3669 lpfc_set_disctmo(vport
);
3671 if (vport
->fc_prevDID
== vport
->fc_myDID
)
3676 vport
->fc_prevDID
= vport
->fc_myDID
;
3677 vport
->num_disc_nodes
= 0;
3679 /* Start Discovery state <hba_state> */
3680 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3681 "0202 Start Discovery hba state x%x "
3682 "Data: x%x x%x x%x\n",
3683 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
3684 vport
->fc_adisc_cnt
);
3686 /* First do ADISCs - if any */
3687 num_sent
= lpfc_els_disc_adisc(vport
);
3693 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
3694 * continue discovery.
3696 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3697 !(vport
->fc_flag
& FC_PT2PT
) &&
3698 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
3699 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
3700 lpfc_issue_reg_vpi(phba
, vport
);
3705 * For SLI2, we need to set port_state to READY and continue
3708 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
3709 /* If we get here, there is nothing to ADISC */
3710 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
3711 lpfc_issue_clear_la(phba
, vport
);
3713 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
3714 vport
->num_disc_nodes
= 0;
3715 /* go thru NPR nodes and issue ELS PLOGIs */
3716 if (vport
->fc_npr_cnt
)
3717 lpfc_els_disc_plogi(vport
);
3719 if (!vport
->num_disc_nodes
) {
3720 spin_lock_irq(shost
->host_lock
);
3721 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
3722 spin_unlock_irq(shost
->host_lock
);
3723 lpfc_can_disctmo(vport
);
3726 vport
->port_state
= LPFC_VPORT_READY
;
3728 /* Next do PLOGIs - if any */
3729 num_sent
= lpfc_els_disc_plogi(vport
);
3734 if (vport
->fc_flag
& FC_RSCN_MODE
) {
3735 /* Check to see if more RSCNs came in while we
3736 * were processing this one.
3738 if ((vport
->fc_rscn_id_cnt
== 0) &&
3739 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
3740 spin_lock_irq(shost
->host_lock
);
3741 vport
->fc_flag
&= ~FC_RSCN_MODE
;
3742 spin_unlock_irq(shost
->host_lock
);
3743 lpfc_can_disctmo(vport
);
3745 lpfc_els_handle_rscn(vport
);
3752 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
3753 * ring the match the sppecified nodelist.
3756 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
3758 LIST_HEAD(completions
);
3759 struct lpfc_sli
*psli
;
3761 struct lpfc_iocbq
*iocb
, *next_iocb
;
3762 struct lpfc_sli_ring
*pring
;
3765 pring
= &psli
->ring
[LPFC_ELS_RING
];
3767 /* Error matching iocb on txq or txcmplq
3768 * First check the txq.
3770 spin_lock_irq(&phba
->hbalock
);
3771 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
3772 if (iocb
->context1
!= ndlp
) {
3776 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
3777 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
3779 list_move_tail(&iocb
->list
, &completions
);
3784 /* Next check the txcmplq */
3785 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
3786 if (iocb
->context1
!= ndlp
) {
3790 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
3791 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
3792 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3795 spin_unlock_irq(&phba
->hbalock
);
3797 /* Cancel all the IOCBs from the completions list */
3798 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3803 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
3805 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3806 struct lpfc_hba
*phba
= vport
->phba
;
3808 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
3809 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
3811 if (!NLP_CHK_NODE_ACT(ndlp
))
3813 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
3814 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
3815 lpfc_free_tx(phba
, ndlp
);
3822 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
3824 lpfc_els_flush_rscn(vport
);
3825 lpfc_els_flush_cmd(vport
);
3826 lpfc_disc_flush_list(vport
);
3829 /*****************************************************************************/
3831 * NAME: lpfc_disc_timeout
3833 * FUNCTION: Fibre Channel driver discovery timeout routine.
3835 * EXECUTION ENVIRONMENT: interrupt only
3843 /*****************************************************************************/
3845 lpfc_disc_timeout(unsigned long ptr
)
3847 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
3848 struct lpfc_hba
*phba
= vport
->phba
;
3849 uint32_t tmo_posted
;
3850 unsigned long flags
= 0;
3852 if (unlikely(!phba
))
3855 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
3856 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
3858 vport
->work_port_events
|= WORKER_DISC_TMO
;
3859 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
3862 lpfc_worker_wake_up(phba
);
3867 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
3869 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3870 struct lpfc_hba
*phba
= vport
->phba
;
3871 struct lpfc_sli
*psli
= &phba
->sli
;
3872 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3873 LPFC_MBOXQ_t
*initlinkmbox
;
3874 int rc
, clrlaerr
= 0;
3876 if (!(vport
->fc_flag
& FC_DISC_TMO
))
3879 spin_lock_irq(shost
->host_lock
);
3880 vport
->fc_flag
&= ~FC_DISC_TMO
;
3881 spin_unlock_irq(shost
->host_lock
);
3883 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3884 "disc timeout: state:x%x rtry:x%x flg:x%x",
3885 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
3887 switch (vport
->port_state
) {
3889 case LPFC_LOCAL_CFG_LINK
:
3890 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
3894 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
3895 "0221 FAN timeout\n");
3896 /* Start discovery by sending FLOGI, clean up old rpis */
3897 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
3899 if (!NLP_CHK_NODE_ACT(ndlp
))
3901 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
3903 if (ndlp
->nlp_type
& NLP_FABRIC
) {
3904 /* Clean up the ndlp on Fabric connections */
3905 lpfc_drop_node(vport
, ndlp
);
3907 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
3908 /* Fail outstanding IO now since device
3909 * is marked for PLOGI.
3911 lpfc_unreg_rpi(vport
, ndlp
);
3914 if (vport
->port_state
!= LPFC_FLOGI
) {
3915 lpfc_initial_flogi(vport
);
3922 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
3923 /* Initial FLOGI timeout */
3924 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3925 "0222 Initial %s timeout\n",
3926 vport
->vpi
? "FDISC" : "FLOGI");
3928 /* Assume no Fabric and go on with discovery.
3929 * Check for outstanding ELS FLOGI to abort.
3932 /* FLOGI failed, so just use loop map to make discovery list */
3933 lpfc_disc_list_loopmap(vport
);
3935 /* Start discovery */
3936 lpfc_disc_start(vport
);
3939 case LPFC_FABRIC_CFG_LINK
:
3940 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
3942 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3943 "0223 Timeout while waiting for "
3944 "NameServer login\n");
3945 /* Next look for NameServer ndlp */
3946 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
3947 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
3948 lpfc_els_abort(phba
, ndlp
);
3950 /* ReStart discovery */
3954 /* Check for wait for NameServer Rsp timeout */
3955 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3956 "0224 NameServer Query timeout "
3958 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
3960 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
3961 /* Try it one more time */
3962 vport
->fc_ns_retry
++;
3963 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
,
3964 vport
->fc_ns_retry
, 0);
3968 vport
->fc_ns_retry
= 0;
3972 * Discovery is over.
3973 * set port_state to PORT_READY if SLI2.
3974 * cmpl_reg_vpi will set port_state to READY for SLI3.
3976 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3977 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
3978 lpfc_issue_reg_vpi(phba
, vport
);
3979 else { /* NPIV Not enabled */
3980 lpfc_issue_clear_la(phba
, vport
);
3981 vport
->port_state
= LPFC_VPORT_READY
;
3985 /* Setup and issue mailbox INITIALIZE LINK command */
3986 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3987 if (!initlinkmbox
) {
3988 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3989 "0206 Device Discovery "
3990 "completion error\n");
3991 phba
->link_state
= LPFC_HBA_ERROR
;
3995 lpfc_linkdown(phba
);
3996 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
3997 phba
->cfg_link_speed
);
3998 initlinkmbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
3999 initlinkmbox
->vport
= vport
;
4000 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4001 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
4002 lpfc_set_loopback_flag(phba
);
4003 if (rc
== MBX_NOT_FINISHED
)
4004 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
4008 case LPFC_DISC_AUTH
:
4009 /* Node Authentication timeout */
4010 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4011 "0227 Node Authentication timeout\n");
4012 lpfc_disc_flush_list(vport
);
4015 * set port_state to PORT_READY if SLI2.
4016 * cmpl_reg_vpi will set port_state to READY for SLI3.
4018 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
4019 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
4020 lpfc_issue_reg_vpi(phba
, vport
);
4021 else { /* NPIV Not enabled */
4022 lpfc_issue_clear_la(phba
, vport
);
4023 vport
->port_state
= LPFC_VPORT_READY
;
4028 case LPFC_VPORT_READY
:
4029 if (vport
->fc_flag
& FC_RSCN_MODE
) {
4030 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4031 "0231 RSCN timeout Data: x%x "
4033 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
4035 /* Cleanup any outstanding ELS commands */
4036 lpfc_els_flush_cmd(vport
);
4038 lpfc_els_flush_rscn(vport
);
4039 lpfc_disc_flush_list(vport
);
4044 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4045 "0273 Unexpected discovery timeout, "
4046 "vport State x%x\n", vport
->port_state
);
4050 switch (phba
->link_state
) {
4052 /* CLEAR LA timeout */
4053 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4054 "0228 CLEAR LA timeout\n");
4059 lpfc_issue_clear_la(phba
, vport
);
4061 case LPFC_LINK_UNKNOWN
:
4062 case LPFC_WARM_START
:
4063 case LPFC_INIT_START
:
4064 case LPFC_INIT_MBX_CMDS
:
4065 case LPFC_LINK_DOWN
:
4066 case LPFC_HBA_ERROR
:
4067 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4068 "0230 Unexpected timeout, hba link "
4069 "state x%x\n", phba
->link_state
);
4073 case LPFC_HBA_READY
:
4078 lpfc_disc_flush_list(vport
);
4079 psli
->ring
[(psli
->extra_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4080 psli
->ring
[(psli
->fcp_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4081 psli
->ring
[(psli
->next_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4082 vport
->port_state
= LPFC_VPORT_READY
;
4089 * This routine handles processing a NameServer REG_LOGIN mailbox
4090 * command upon completion. It is setup in the LPFC_MBOXQ
4091 * as the completion routine when the command is
4092 * handed off to the SLI layer.
4095 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4097 MAILBOX_t
*mb
= &pmb
->u
.mb
;
4098 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
4099 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4100 struct lpfc_vport
*vport
= pmb
->vport
;
4102 pmb
->context1
= NULL
;
4104 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
4105 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
4106 ndlp
->nlp_type
|= NLP_FABRIC
;
4107 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4110 * Start issuing Fabric-Device Management Interface (FDMI) command to
4111 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
4112 * fdmi-on=2 (supporting RPA/hostnmae)
4115 if (vport
->cfg_fdmi_on
== 1)
4116 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
);
4118 mod_timer(&vport
->fc_fdmitmo
, jiffies
+ HZ
* 60);
4120 /* decrement the node reference count held for this callback
4124 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4126 mempool_free(pmb
, phba
->mbox_mem_pool
);
4132 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
4134 uint16_t *rpi
= param
;
4136 return ndlp
->nlp_rpi
== *rpi
;
4140 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
4142 return memcmp(&ndlp
->nlp_portname
, param
,
4143 sizeof(ndlp
->nlp_portname
)) == 0;
4146 static struct lpfc_nodelist
*
4147 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
4149 struct lpfc_nodelist
*ndlp
;
4151 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4152 if (filter(ndlp
, param
))
4159 * This routine looks up the ndlp lists for the given RPI. If rpi found it
4160 * returns the node list element pointer else return NULL.
4162 struct lpfc_nodelist
*
4163 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
4165 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
4169 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
4170 * returns the node element list pointer else return NULL.
4172 struct lpfc_nodelist
*
4173 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
4175 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4176 struct lpfc_nodelist
*ndlp
;
4178 spin_lock_irq(shost
->host_lock
);
4179 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
4180 spin_unlock_irq(shost
->host_lock
);
4185 lpfc_nlp_init(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4188 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
4190 lpfc_initialize_node(vport
, ndlp
, did
);
4191 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
4193 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
4194 "node init: did:x%x",
4195 ndlp
->nlp_DID
, 0, 0);
4200 /* This routine releases all resources associated with a specifc NPort's ndlp
4201 * and mempool_free's the nodelist.
4204 lpfc_nlp_release(struct kref
*kref
)
4206 struct lpfc_hba
*phba
;
4207 unsigned long flags
;
4208 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
4211 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4212 "node release: did:x%x flg:x%x type:x%x",
4213 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4215 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
4216 "0279 lpfc_nlp_release: ndlp:x%p "
4217 "usgmap:x%x refcnt:%d\n",
4218 (void *)ndlp
, ndlp
->nlp_usg_map
,
4219 atomic_read(&ndlp
->kref
.refcount
));
4221 /* remove ndlp from action. */
4222 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
4224 /* clear the ndlp active flag for all release cases */
4226 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4227 NLP_CLR_NODE_ACT(ndlp
);
4228 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4230 /* free ndlp memory for final ndlp release */
4231 if (NLP_CHK_FREE_REQ(ndlp
)) {
4232 kfree(ndlp
->lat_data
);
4233 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
4237 /* This routine bumps the reference count for a ndlp structure to ensure
4238 * that one discovery thread won't free a ndlp while another discovery thread
4241 struct lpfc_nodelist
*
4242 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
4244 struct lpfc_hba
*phba
;
4245 unsigned long flags
;
4248 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4249 "node get: did:x%x flg:x%x refcnt:x%x",
4250 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4251 atomic_read(&ndlp
->kref
.refcount
));
4252 /* The check of ndlp usage to prevent incrementing the
4253 * ndlp reference count that is in the process of being
4257 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4258 if (!NLP_CHK_NODE_ACT(ndlp
) || NLP_CHK_FREE_ACK(ndlp
)) {
4259 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4260 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4261 "0276 lpfc_nlp_get: ndlp:x%p "
4262 "usgmap:x%x refcnt:%d\n",
4263 (void *)ndlp
, ndlp
->nlp_usg_map
,
4264 atomic_read(&ndlp
->kref
.refcount
));
4267 kref_get(&ndlp
->kref
);
4268 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4273 /* This routine decrements the reference count for a ndlp structure. If the
4274 * count goes to 0, this indicates the the associated nodelist should be
4275 * freed. Returning 1 indicates the ndlp resource has been released; on the
4276 * other hand, returning 0 indicates the ndlp resource has not been released
4280 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
4282 struct lpfc_hba
*phba
;
4283 unsigned long flags
;
4288 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4289 "node put: did:x%x flg:x%x refcnt:x%x",
4290 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4291 atomic_read(&ndlp
->kref
.refcount
));
4293 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4294 /* Check the ndlp memory free acknowledge flag to avoid the
4295 * possible race condition that kref_put got invoked again
4296 * after previous one has done ndlp memory free.
4298 if (NLP_CHK_FREE_ACK(ndlp
)) {
4299 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4300 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4301 "0274 lpfc_nlp_put: ndlp:x%p "
4302 "usgmap:x%x refcnt:%d\n",
4303 (void *)ndlp
, ndlp
->nlp_usg_map
,
4304 atomic_read(&ndlp
->kref
.refcount
));
4307 /* Check the ndlp inactivate log flag to avoid the possible
4308 * race condition that kref_put got invoked again after ndlp
4309 * is already in inactivating state.
4311 if (NLP_CHK_IACT_REQ(ndlp
)) {
4312 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4313 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4314 "0275 lpfc_nlp_put: ndlp:x%p "
4315 "usgmap:x%x refcnt:%d\n",
4316 (void *)ndlp
, ndlp
->nlp_usg_map
,
4317 atomic_read(&ndlp
->kref
.refcount
));
4320 /* For last put, mark the ndlp usage flags to make sure no
4321 * other kref_get and kref_put on the same ndlp shall get
4322 * in between the process when the final kref_put has been
4323 * invoked on this ndlp.
4325 if (atomic_read(&ndlp
->kref
.refcount
) == 1) {
4326 /* Indicate ndlp is put to inactive state. */
4327 NLP_SET_IACT_REQ(ndlp
);
4328 /* Acknowledge ndlp memory free has been seen. */
4329 if (NLP_CHK_FREE_REQ(ndlp
))
4330 NLP_SET_FREE_ACK(ndlp
);
4332 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4333 /* Note, the kref_put returns 1 when decrementing a reference
4334 * count that was 1, it invokes the release callback function,
4335 * but it still left the reference count as 1 (not actually
4336 * performs the last decrementation). Otherwise, it actually
4337 * decrements the reference count and returns 0.
4339 return kref_put(&ndlp
->kref
, lpfc_nlp_release
);
4342 /* This routine free's the specified nodelist if it is not in use
4343 * by any other discovery thread. This routine returns 1 if the
4344 * ndlp has been freed. A return value of 0 indicates the ndlp is
4345 * not yet been released.
4348 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
4350 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4351 "node not used: did:x%x flg:x%x refcnt:x%x",
4352 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4353 atomic_read(&ndlp
->kref
.refcount
));
4354 if (atomic_read(&ndlp
->kref
.refcount
) == 1)
4355 if (lpfc_nlp_put(ndlp
))
4361 * lpfc_fcf_inuse - Check if FCF can be unregistered.
4362 * @phba: Pointer to hba context object.
4364 * This function iterate through all FC nodes associated
4365 * will all vports to check if there is any node with
4366 * fc_rports associated with it. If there is an fc_rport
4367 * associated with the node, then the node is either in
4368 * discovered state or its devloss_timer is pending.
4371 lpfc_fcf_inuse(struct lpfc_hba
*phba
)
4373 struct lpfc_vport
**vports
;
4375 struct lpfc_nodelist
*ndlp
;
4376 struct Scsi_Host
*shost
;
4378 vports
= lpfc_create_vport_work_array(phba
);
4380 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4381 shost
= lpfc_shost_from_vport(vports
[i
]);
4382 spin_lock_irq(shost
->host_lock
);
4383 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
4384 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
&&
4385 (ndlp
->rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
4387 spin_unlock_irq(shost
->host_lock
);
4390 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
4391 "2624 RPI %x DID %x flg %x still "
4393 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4395 if (ndlp
->nlp_flag
& NLP_RPI_VALID
)
4399 spin_unlock_irq(shost
->host_lock
);
4402 lpfc_destroy_vport_work_array(phba
, vports
);
4407 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
4408 * @phba: Pointer to hba context object.
4409 * @mboxq: Pointer to mailbox object.
4411 * This function frees memory associated with the mailbox command.
4414 lpfc_unregister_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
4416 struct lpfc_vport
*vport
= mboxq
->vport
;
4418 if (mboxq
->u
.mb
.mbxStatus
) {
4419 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4420 "2555 UNREG_VFI mbxStatus error x%x "
4422 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
4424 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4429 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
4430 * @phba: Pointer to hba context object.
4431 * @mboxq: Pointer to mailbox object.
4433 * This function frees memory associated with the mailbox command.
4436 lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
4438 struct lpfc_vport
*vport
= mboxq
->vport
;
4440 if (mboxq
->u
.mb
.mbxStatus
) {
4441 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4442 "2550 UNREG_FCFI mbxStatus error x%x "
4444 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
4446 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4451 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
4452 * @phba: Pointer to hba context object.
4454 * This function check if there are any connected remote port for the FCF and
4455 * if all the devices are disconnected, this function unregister FCFI.
4456 * This function also tries to use another FCF for discovery.
4459 lpfc_unregister_unused_fcf(struct lpfc_hba
*phba
)
4463 struct lpfc_vport
**vports
;
4466 spin_lock_irq(&phba
->hbalock
);
4468 * If HBA is not running in FIP mode or
4469 * If HBA does not support FCoE or
4470 * If FCF is not registered.
4473 if (!(phba
->hba_flag
& HBA_FCOE_SUPPORT
) ||
4474 !(phba
->fcf
.fcf_flag
& FCF_REGISTERED
) ||
4475 (!(phba
->hba_flag
& HBA_FIP_SUPPORT
))) {
4476 spin_unlock_irq(&phba
->hbalock
);
4479 spin_unlock_irq(&phba
->hbalock
);
4481 if (lpfc_fcf_inuse(phba
))
4484 /* At this point, all discovery is aborted */
4485 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4487 /* Unregister VPIs */
4488 vports
= lpfc_create_vport_work_array(phba
);
4490 (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))
4491 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4492 lpfc_mbx_unreg_vpi(vports
[i
]);
4493 spin_lock_irq(&phba
->hbalock
);
4494 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
4495 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
4496 spin_unlock_irq(&phba
->hbalock
);
4498 lpfc_destroy_vport_work_array(phba
, vports
);
4500 /* Unregister VFI */
4501 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4503 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4504 "2556 UNREG_VFI mbox allocation failed"
4506 phba
->pport
->port_state
);
4510 lpfc_unreg_vfi(mbox
, phba
->pport
);
4511 mbox
->vport
= phba
->pport
;
4512 mbox
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
4514 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4515 if (rc
== MBX_NOT_FINISHED
) {
4516 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4517 "2557 UNREG_VFI issue mbox failed rc x%x "
4519 rc
, phba
->pport
->port_state
);
4520 mempool_free(mbox
, phba
->mbox_mem_pool
);
4524 /* Unregister FCF */
4525 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4527 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4528 "2551 UNREG_FCFI mbox allocation failed"
4530 phba
->pport
->port_state
);
4534 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
4535 mbox
->vport
= phba
->pport
;
4536 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
4537 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4539 if (rc
== MBX_NOT_FINISHED
) {
4540 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4541 "2552 UNREG_FCFI issue mbox failed rc x%x "
4543 rc
, phba
->pport
->port_state
);
4544 mempool_free(mbox
, phba
->mbox_mem_pool
);
4548 spin_lock_irq(&phba
->hbalock
);
4549 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_REGISTERED
|
4550 FCF_DISCOVERED
| FCF_BOOT_ENABLE
| FCF_IN_USE
|
4552 spin_unlock_irq(&phba
->hbalock
);
4555 * If driver is not unloading, check if there is any other
4556 * FCF record that can be used for discovery.
4558 if ((phba
->pport
->load_flag
& FC_UNLOADING
) ||
4559 (phba
->link_state
< LPFC_LINK_UP
))
4562 rc
= lpfc_sli4_read_fcf_record(phba
, LPFC_FCOE_FCF_GET_FIRST
);
4565 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4566 "2553 lpfc_unregister_unused_fcf failed to read FCF"
4567 " record HBA state x%x\n",
4568 phba
->pport
->port_state
);
4572 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
4573 * @phba: Pointer to hba context object.
4574 * @buff: Buffer containing the FCF connection table as in the config
4576 * This function create driver data structure for the FCF connection
4577 * record table read from config region 23.
4580 lpfc_read_fcf_conn_tbl(struct lpfc_hba
*phba
,
4583 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
4584 struct lpfc_fcf_conn_hdr
*conn_hdr
;
4585 struct lpfc_fcf_conn_rec
*conn_rec
;
4586 uint32_t record_count
;
4589 /* Free the current connect table */
4590 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
4591 &phba
->fcf_conn_rec_list
, list
) {
4592 list_del_init(&conn_entry
->list
);
4596 conn_hdr
= (struct lpfc_fcf_conn_hdr
*) buff
;
4597 record_count
= conn_hdr
->length
* sizeof(uint32_t)/
4598 sizeof(struct lpfc_fcf_conn_rec
);
4600 conn_rec
= (struct lpfc_fcf_conn_rec
*)
4601 (buff
+ sizeof(struct lpfc_fcf_conn_hdr
));
4603 for (i
= 0; i
< record_count
; i
++) {
4604 if (!(conn_rec
[i
].flags
& FCFCNCT_VALID
))
4606 conn_entry
= kzalloc(sizeof(struct lpfc_fcf_conn_entry
),
4609 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4610 "2566 Failed to allocate connection"
4615 memcpy(&conn_entry
->conn_rec
, &conn_rec
[i
],
4616 sizeof(struct lpfc_fcf_conn_rec
));
4617 conn_entry
->conn_rec
.vlan_tag
=
4618 le16_to_cpu(conn_entry
->conn_rec
.vlan_tag
) & 0xFFF;
4619 conn_entry
->conn_rec
.flags
=
4620 le16_to_cpu(conn_entry
->conn_rec
.flags
);
4621 list_add_tail(&conn_entry
->list
,
4622 &phba
->fcf_conn_rec_list
);
4627 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
4628 * @phba: Pointer to hba context object.
4629 * @buff: Buffer containing the FCoE parameter data structure.
4631 * This function update driver data structure with config
4632 * parameters read from config region 23.
4635 lpfc_read_fcoe_param(struct lpfc_hba
*phba
,
4638 struct lpfc_fip_param_hdr
*fcoe_param_hdr
;
4639 struct lpfc_fcoe_params
*fcoe_param
;
4641 fcoe_param_hdr
= (struct lpfc_fip_param_hdr
*)
4643 fcoe_param
= (struct lpfc_fcoe_params
*)
4644 (buff
+ sizeof(struct lpfc_fip_param_hdr
));
4646 if ((fcoe_param_hdr
->parm_version
!= FIPP_VERSION
) ||
4647 (fcoe_param_hdr
->length
!= FCOE_PARAM_LENGTH
))
4650 if (fcoe_param_hdr
->parm_flags
& FIPP_VLAN_VALID
) {
4651 phba
->valid_vlan
= 1;
4652 phba
->vlan_id
= le16_to_cpu(fcoe_param
->vlan_tag
) &
4656 phba
->fc_map
[0] = fcoe_param
->fc_map
[0];
4657 phba
->fc_map
[1] = fcoe_param
->fc_map
[1];
4658 phba
->fc_map
[2] = fcoe_param
->fc_map
[2];
4663 * lpfc_get_rec_conf23 - Get a record type in config region data.
4664 * @buff: Buffer containing config region 23 data.
4665 * @size: Size of the data buffer.
4666 * @rec_type: Record type to be searched.
4668 * This function searches config region data to find the begining
4669 * of the record specified by record_type. If record found, this
4670 * function return pointer to the record else return NULL.
4673 lpfc_get_rec_conf23(uint8_t *buff
, uint32_t size
, uint8_t rec_type
)
4675 uint32_t offset
= 0, rec_length
;
4677 if ((buff
[0] == LPFC_REGION23_LAST_REC
) ||
4678 (size
< sizeof(uint32_t)))
4681 rec_length
= buff
[offset
+ 1];
4684 * One TLV record has one word header and number of data words
4685 * specified in the rec_length field of the record header.
4687 while ((offset
+ rec_length
* sizeof(uint32_t) + sizeof(uint32_t))
4689 if (buff
[offset
] == rec_type
)
4690 return &buff
[offset
];
4692 if (buff
[offset
] == LPFC_REGION23_LAST_REC
)
4695 offset
+= rec_length
* sizeof(uint32_t) + sizeof(uint32_t);
4696 rec_length
= buff
[offset
+ 1];
4702 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
4703 * @phba: Pointer to lpfc_hba data structure.
4704 * @buff: Buffer containing config region 23 data.
4705 * @size: Size of the data buffer.
4707 * This fuction parse the FCoE config parameters in config region 23 and
4708 * populate driver data structure with the parameters.
4711 lpfc_parse_fcoe_conf(struct lpfc_hba
*phba
,
4715 uint32_t offset
= 0, rec_length
;
4719 * If data size is less than 2 words signature and version cannot be
4722 if (size
< 2*sizeof(uint32_t))
4725 /* Check the region signature first */
4726 if (memcmp(buff
, LPFC_REGION23_SIGNATURE
, 4)) {
4727 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4728 "2567 Config region 23 has bad signature\n");
4734 /* Check the data structure version */
4735 if (buff
[offset
] != LPFC_REGION23_VERSION
) {
4736 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4737 "2568 Config region 23 has bad version\n");
4742 rec_length
= buff
[offset
+ 1];
4744 /* Read FCoE param record */
4745 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
4746 size
- offset
, FCOE_PARAM_TYPE
);
4748 lpfc_read_fcoe_param(phba
, rec_ptr
);
4750 /* Read FCF connection table */
4751 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
4752 size
- offset
, FCOE_CONN_TBL_TYPE
);
4754 lpfc_read_fcf_conn_tbl(phba
, rec_ptr
);