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
)
750 spin_lock_irq(&phba
->hbalock
);
751 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_DISCOVERED
);
752 if (phba
->link_state
> LPFC_LINK_DOWN
) {
753 phba
->link_state
= LPFC_LINK_DOWN
;
754 phba
->pport
->fc_flag
&= ~FC_LBIT
;
756 spin_unlock_irq(&phba
->hbalock
);
757 vports
= lpfc_create_vport_work_array(phba
);
759 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
760 /* Issue a LINK DOWN event to all nodes */
761 lpfc_linkdown_port(vports
[i
]);
763 lpfc_destroy_vport_work_array(phba
, vports
);
764 /* Clean up any firmware default rpi's */
765 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
767 lpfc_unreg_did(phba
, 0xffff, 0xffffffff, mb
);
769 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
770 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
771 == MBX_NOT_FINISHED
) {
772 mempool_free(mb
, phba
->mbox_mem_pool
);
776 /* Setup myDID for link up if we are in pt2pt mode */
777 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
778 phba
->pport
->fc_myDID
= 0;
779 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
781 lpfc_config_link(phba
, mb
);
782 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
784 if (lpfc_sli_issue_mbox(phba
, mb
, MBX_NOWAIT
)
785 == MBX_NOT_FINISHED
) {
786 mempool_free(mb
, phba
->mbox_mem_pool
);
789 spin_lock_irq(shost
->host_lock
);
790 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
791 spin_unlock_irq(shost
->host_lock
);
798 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
800 struct lpfc_nodelist
*ndlp
;
802 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
803 if (!NLP_CHK_NODE_ACT(ndlp
))
805 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
807 if (ndlp
->nlp_type
& NLP_FABRIC
) {
808 /* On Linkup its safe to clean up the ndlp
809 * from Fabric connections.
811 if (ndlp
->nlp_DID
!= Fabric_DID
)
812 lpfc_unreg_rpi(vport
, ndlp
);
813 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
814 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
815 /* Fail outstanding IO now since device is
818 lpfc_unreg_rpi(vport
, ndlp
);
824 lpfc_linkup_port(struct lpfc_vport
*vport
)
826 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
827 struct lpfc_hba
*phba
= vport
->phba
;
829 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
832 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
833 "Link Up: top:x%x speed:x%x flg:x%x",
834 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
836 /* If NPIV is not enabled, only bring the physical port up */
837 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
838 (vport
!= phba
->pport
))
841 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKUP
, 0);
843 spin_lock_irq(shost
->host_lock
);
844 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
845 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
846 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
847 vport
->fc_ns_retry
= 0;
848 spin_unlock_irq(shost
->host_lock
);
850 if (vport
->fc_flag
& FC_LBIT
)
851 lpfc_linkup_cleanup_nodes(vport
);
856 lpfc_linkup(struct lpfc_hba
*phba
)
858 struct lpfc_vport
**vports
;
861 phba
->link_state
= LPFC_LINK_UP
;
863 /* Unblock fabric iocbs if they are blocked */
864 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
865 del_timer_sync(&phba
->fabric_block_timer
);
867 vports
= lpfc_create_vport_work_array(phba
);
869 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
870 lpfc_linkup_port(vports
[i
]);
871 lpfc_destroy_vport_work_array(phba
, vports
);
872 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
873 (phba
->sli_rev
< LPFC_SLI_REV4
))
874 lpfc_issue_clear_la(phba
, phba
->pport
);
880 * This routine handles processing a CLEAR_LA mailbox
881 * command upon completion. It is setup in the LPFC_MBOXQ
882 * as the completion routine when the command is
883 * handed off to the SLI layer.
886 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
888 struct lpfc_vport
*vport
= pmb
->vport
;
889 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
890 struct lpfc_sli
*psli
= &phba
->sli
;
891 MAILBOX_t
*mb
= &pmb
->u
.mb
;
894 /* Since we don't do discovery right now, turn these off here */
895 psli
->ring
[psli
->extra_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
896 psli
->ring
[psli
->fcp_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
897 psli
->ring
[psli
->next_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
899 /* Check for error */
900 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
901 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
902 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
903 "0320 CLEAR_LA mbxStatus error x%x hba "
905 mb
->mbxStatus
, vport
->port_state
);
906 phba
->link_state
= LPFC_HBA_ERROR
;
910 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
911 phba
->link_state
= LPFC_HBA_READY
;
913 spin_lock_irq(&phba
->hbalock
);
914 psli
->sli_flag
|= LPFC_PROCESS_LA
;
915 control
= readl(phba
->HCregaddr
);
916 control
|= HC_LAINT_ENA
;
917 writel(control
, phba
->HCregaddr
);
918 readl(phba
->HCregaddr
); /* flush */
919 spin_unlock_irq(&phba
->hbalock
);
920 mempool_free(pmb
, phba
->mbox_mem_pool
);
924 /* Device Discovery completes */
925 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
926 "0225 Device Discovery completes\n");
927 mempool_free(pmb
, phba
->mbox_mem_pool
);
929 spin_lock_irq(shost
->host_lock
);
930 vport
->fc_flag
&= ~FC_ABORT_DISCOVERY
;
931 spin_unlock_irq(shost
->host_lock
);
933 lpfc_can_disctmo(vport
);
935 /* turn on Link Attention interrupts */
937 spin_lock_irq(&phba
->hbalock
);
938 psli
->sli_flag
|= LPFC_PROCESS_LA
;
939 control
= readl(phba
->HCregaddr
);
940 control
|= HC_LAINT_ENA
;
941 writel(control
, phba
->HCregaddr
);
942 readl(phba
->HCregaddr
); /* flush */
943 spin_unlock_irq(&phba
->hbalock
);
950 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
952 struct lpfc_vport
*vport
= pmb
->vport
;
954 if (pmb
->u
.mb
.mbxStatus
)
957 mempool_free(pmb
, phba
->mbox_mem_pool
);
959 if (phba
->fc_topology
== TOPOLOGY_LOOP
&&
960 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
961 !(vport
->fc_flag
& FC_LBIT
)) {
962 /* Need to wait for FAN - use discovery timer
963 * for timeout. port_state is identically
964 * LPFC_LOCAL_CFG_LINK while waiting for FAN
966 lpfc_set_disctmo(vport
);
970 /* Start discovery by sending a FLOGI. port_state is identically
971 * LPFC_FLOGI while waiting for FLOGI cmpl
973 if (vport
->port_state
!= LPFC_FLOGI
) {
974 lpfc_initial_flogi(vport
);
979 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
980 "0306 CONFIG_LINK mbxStatus error x%x "
982 pmb
->u
.mb
.mbxStatus
, vport
->port_state
);
983 mempool_free(pmb
, phba
->mbox_mem_pool
);
987 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
988 "0200 CONFIG_LINK bad hba state x%x\n",
991 lpfc_issue_clear_la(phba
, vport
);
996 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
998 struct lpfc_vport
*vport
= mboxq
->vport
;
1001 if (mboxq
->u
.mb
.mbxStatus
) {
1002 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1003 "2017 REG_FCFI mbxStatus error x%x "
1005 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
1006 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1010 /* Start FCoE discovery by sending a FLOGI. */
1011 phba
->fcf
.fcfi
= bf_get(lpfc_reg_fcfi_fcfi
, &mboxq
->u
.mqe
.un
.reg_fcfi
);
1012 /* Set the FCFI registered flag */
1013 spin_lock_irqsave(&phba
->hbalock
, flags
);
1014 phba
->fcf
.fcf_flag
|= FCF_REGISTERED
;
1015 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1016 /* If there is a pending FCoE event, restart FCF table scan. */
1017 if (lpfc_check_pending_fcoe_event(phba
, 1)) {
1018 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1021 spin_lock_irqsave(&phba
->hbalock
, flags
);
1022 phba
->fcf
.fcf_flag
|= (FCF_DISCOVERED
| FCF_IN_USE
);
1023 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1024 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1025 if (vport
->port_state
!= LPFC_FLOGI
)
1026 lpfc_initial_flogi(vport
);
1028 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1033 * lpfc_fab_name_match - Check if the fcf fabric name match.
1034 * @fab_name: pointer to fabric name.
1035 * @new_fcf_record: pointer to fcf record.
1037 * This routine compare the fcf record's fabric name with provided
1038 * fabric name. If the fabric name are identical this function
1039 * returns 1 else return 0.
1042 lpfc_fab_name_match(uint8_t *fab_name
, struct fcf_record
*new_fcf_record
)
1045 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
)) &&
1047 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
)) &&
1049 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
)) &&
1051 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
)) &&
1053 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
)) &&
1055 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
)) &&
1057 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
)) &&
1059 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
)))
1066 * lpfc_sw_name_match - Check if the fcf switch name match.
1067 * @fab_name: pointer to fabric name.
1068 * @new_fcf_record: pointer to fcf record.
1070 * This routine compare the fcf record's switch name with provided
1071 * switch name. If the switch name are identical this function
1072 * returns 1 else return 0.
1075 lpfc_sw_name_match(uint8_t *sw_name
, struct fcf_record
*new_fcf_record
)
1078 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
)) &&
1080 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
)) &&
1082 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
)) &&
1084 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
)) &&
1086 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
)) &&
1088 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
)) &&
1090 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
)) &&
1092 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
)))
1099 * lpfc_mac_addr_match - Check if the fcf mac address match.
1100 * @phba: pointer to lpfc hba data structure.
1101 * @new_fcf_record: pointer to fcf record.
1103 * This routine compare the fcf record's mac address with HBA's
1104 * FCF mac address. If the mac addresses are identical this function
1105 * returns 1 else return 0.
1108 lpfc_mac_addr_match(struct lpfc_hba
*phba
, struct fcf_record
*new_fcf_record
)
1110 if ((phba
->fcf
.mac_addr
[0] ==
1111 bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
)) &&
1112 (phba
->fcf
.mac_addr
[1] ==
1113 bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
)) &&
1114 (phba
->fcf
.mac_addr
[2] ==
1115 bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
)) &&
1116 (phba
->fcf
.mac_addr
[3] ==
1117 bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
)) &&
1118 (phba
->fcf
.mac_addr
[4] ==
1119 bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
)) &&
1120 (phba
->fcf
.mac_addr
[5] ==
1121 bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
)))
1128 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1129 * @phba: pointer to lpfc hba data structure.
1130 * @new_fcf_record: pointer to fcf record.
1132 * This routine copies the FCF information from the FCF
1133 * record to lpfc_hba data structure.
1136 lpfc_copy_fcf_record(struct lpfc_hba
*phba
, struct fcf_record
*new_fcf_record
)
1138 phba
->fcf
.fabric_name
[0] =
1139 bf_get(lpfc_fcf_record_fab_name_0
, new_fcf_record
);
1140 phba
->fcf
.fabric_name
[1] =
1141 bf_get(lpfc_fcf_record_fab_name_1
, new_fcf_record
);
1142 phba
->fcf
.fabric_name
[2] =
1143 bf_get(lpfc_fcf_record_fab_name_2
, new_fcf_record
);
1144 phba
->fcf
.fabric_name
[3] =
1145 bf_get(lpfc_fcf_record_fab_name_3
, new_fcf_record
);
1146 phba
->fcf
.fabric_name
[4] =
1147 bf_get(lpfc_fcf_record_fab_name_4
, new_fcf_record
);
1148 phba
->fcf
.fabric_name
[5] =
1149 bf_get(lpfc_fcf_record_fab_name_5
, new_fcf_record
);
1150 phba
->fcf
.fabric_name
[6] =
1151 bf_get(lpfc_fcf_record_fab_name_6
, new_fcf_record
);
1152 phba
->fcf
.fabric_name
[7] =
1153 bf_get(lpfc_fcf_record_fab_name_7
, new_fcf_record
);
1154 phba
->fcf
.mac_addr
[0] =
1155 bf_get(lpfc_fcf_record_mac_0
, new_fcf_record
);
1156 phba
->fcf
.mac_addr
[1] =
1157 bf_get(lpfc_fcf_record_mac_1
, new_fcf_record
);
1158 phba
->fcf
.mac_addr
[2] =
1159 bf_get(lpfc_fcf_record_mac_2
, new_fcf_record
);
1160 phba
->fcf
.mac_addr
[3] =
1161 bf_get(lpfc_fcf_record_mac_3
, new_fcf_record
);
1162 phba
->fcf
.mac_addr
[4] =
1163 bf_get(lpfc_fcf_record_mac_4
, new_fcf_record
);
1164 phba
->fcf
.mac_addr
[5] =
1165 bf_get(lpfc_fcf_record_mac_5
, new_fcf_record
);
1166 phba
->fcf
.fcf_indx
= bf_get(lpfc_fcf_record_fcf_index
, new_fcf_record
);
1167 phba
->fcf
.priority
= new_fcf_record
->fip_priority
;
1168 phba
->fcf
.switch_name
[0] =
1169 bf_get(lpfc_fcf_record_switch_name_0
, new_fcf_record
);
1170 phba
->fcf
.switch_name
[1] =
1171 bf_get(lpfc_fcf_record_switch_name_1
, new_fcf_record
);
1172 phba
->fcf
.switch_name
[2] =
1173 bf_get(lpfc_fcf_record_switch_name_2
, new_fcf_record
);
1174 phba
->fcf
.switch_name
[3] =
1175 bf_get(lpfc_fcf_record_switch_name_3
, new_fcf_record
);
1176 phba
->fcf
.switch_name
[4] =
1177 bf_get(lpfc_fcf_record_switch_name_4
, new_fcf_record
);
1178 phba
->fcf
.switch_name
[5] =
1179 bf_get(lpfc_fcf_record_switch_name_5
, new_fcf_record
);
1180 phba
->fcf
.switch_name
[6] =
1181 bf_get(lpfc_fcf_record_switch_name_6
, new_fcf_record
);
1182 phba
->fcf
.switch_name
[7] =
1183 bf_get(lpfc_fcf_record_switch_name_7
, new_fcf_record
);
1187 * lpfc_register_fcf - Register the FCF with hba.
1188 * @phba: pointer to lpfc hba data structure.
1190 * This routine issues a register fcfi mailbox command to register
1194 lpfc_register_fcf(struct lpfc_hba
*phba
)
1196 LPFC_MBOXQ_t
*fcf_mbxq
;
1198 unsigned long flags
;
1200 spin_lock_irqsave(&phba
->hbalock
, flags
);
1202 /* If the FCF is not availabe do nothing. */
1203 if (!(phba
->fcf
.fcf_flag
& FCF_AVAILABLE
)) {
1204 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1205 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1209 /* The FCF is already registered, start discovery */
1210 if (phba
->fcf
.fcf_flag
& FCF_REGISTERED
) {
1211 phba
->fcf
.fcf_flag
|= (FCF_DISCOVERED
| FCF_IN_USE
);
1212 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1213 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1214 if (phba
->pport
->port_state
!= LPFC_FLOGI
)
1215 lpfc_initial_flogi(phba
->pport
);
1218 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1220 fcf_mbxq
= mempool_alloc(phba
->mbox_mem_pool
,
1223 spin_lock_irqsave(&phba
->hbalock
, flags
);
1224 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1225 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1229 lpfc_reg_fcfi(phba
, fcf_mbxq
);
1230 fcf_mbxq
->vport
= phba
->pport
;
1231 fcf_mbxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_fcfi
;
1232 rc
= lpfc_sli_issue_mbox(phba
, fcf_mbxq
, MBX_NOWAIT
);
1233 if (rc
== MBX_NOT_FINISHED
) {
1234 spin_lock_irqsave(&phba
->hbalock
, flags
);
1235 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1236 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1237 mempool_free(fcf_mbxq
, phba
->mbox_mem_pool
);
1244 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1245 * @phba: pointer to lpfc hba data structure.
1246 * @new_fcf_record: pointer to fcf record.
1247 * @boot_flag: Indicates if this record used by boot bios.
1248 * @addr_mode: The address mode to be used by this FCF
1250 * This routine compare the fcf record with connect list obtained from the
1251 * config region to decide if this FCF can be used for SAN discovery. It returns
1252 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1253 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1254 * is used by boot bios and addr_mode will indicate the addressing mode to be
1255 * used for this FCF when the function returns.
1256 * If the FCF record need to be used with a particular vlan id, the vlan is
1257 * set in the vlan_id on return of the function. If not VLAN tagging need to
1258 * be used with the FCF vlan_id will be set to 0xFFFF;
1261 lpfc_match_fcf_conn_list(struct lpfc_hba
*phba
,
1262 struct fcf_record
*new_fcf_record
,
1263 uint32_t *boot_flag
, uint32_t *addr_mode
,
1266 struct lpfc_fcf_conn_entry
*conn_entry
;
1267 int i
, j
, fcf_vlan_id
= 0;
1269 /* Find the lowest VLAN id in the FCF record */
1270 for (i
= 0; i
< 512; i
++) {
1271 if (new_fcf_record
->vlan_bitmap
[i
]) {
1272 fcf_vlan_id
= i
* 8;
1274 while (!((new_fcf_record
->vlan_bitmap
[i
] >> j
) & 1)) {
1282 /* If FCF not available return 0 */
1283 if (!bf_get(lpfc_fcf_record_fcf_avail
, new_fcf_record
) ||
1284 !bf_get(lpfc_fcf_record_fcf_valid
, new_fcf_record
))
1287 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
1289 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1291 if (phba
->valid_vlan
)
1292 *vlan_id
= phba
->vlan_id
;
1299 * If there are no FCF connection table entry, driver connect to all
1302 if (list_empty(&phba
->fcf_conn_rec_list
)) {
1304 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1308 * When there are no FCF connect entries, use driver's default
1309 * addressing mode - FPMA.
1311 if (*addr_mode
& LPFC_FCF_FPMA
)
1312 *addr_mode
= LPFC_FCF_FPMA
;
1314 /* If FCF record report a vlan id use that vlan id */
1316 *vlan_id
= fcf_vlan_id
;
1322 list_for_each_entry(conn_entry
, &phba
->fcf_conn_rec_list
, list
) {
1323 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_VALID
))
1326 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_FBNM_VALID
) &&
1327 !lpfc_fab_name_match(conn_entry
->conn_rec
.fabric_name
,
1330 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_SWNM_VALID
) &&
1331 !lpfc_sw_name_match(conn_entry
->conn_rec
.switch_name
,
1334 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
) {
1336 * If the vlan bit map does not have the bit set for the
1337 * vlan id to be used, then it is not a match.
1339 if (!(new_fcf_record
->vlan_bitmap
1340 [conn_entry
->conn_rec
.vlan_tag
/ 8] &
1341 (1 << (conn_entry
->conn_rec
.vlan_tag
% 8))))
1346 * If connection record does not support any addressing mode,
1347 * skip the FCF record.
1349 if (!(bf_get(lpfc_fcf_record_mac_addr_prov
, new_fcf_record
)
1350 & (LPFC_FCF_FPMA
| LPFC_FCF_SPMA
)))
1354 * Check if the connection record specifies a required
1357 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1358 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)) {
1361 * If SPMA required but FCF not support this continue.
1363 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1364 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1365 new_fcf_record
) & LPFC_FCF_SPMA
))
1369 * If FPMA required but FCF not support this continue.
1371 if (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1372 !(bf_get(lpfc_fcf_record_mac_addr_prov
,
1373 new_fcf_record
) & LPFC_FCF_FPMA
))
1378 * This fcf record matches filtering criteria.
1380 if (conn_entry
->conn_rec
.flags
& FCFCNCT_BOOT
)
1386 * If user did not specify any addressing mode, or if the
1387 * prefered addressing mode specified by user is not supported
1388 * by FCF, allow fabric to pick the addressing mode.
1390 *addr_mode
= bf_get(lpfc_fcf_record_mac_addr_prov
,
1393 * If the user specified a required address mode, assign that
1396 if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1397 (!(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
)))
1398 *addr_mode
= (conn_entry
->conn_rec
.flags
&
1400 LPFC_FCF_SPMA
: LPFC_FCF_FPMA
;
1402 * If the user specified a prefered address mode, use the
1403 * addr mode only if FCF support the addr_mode.
1405 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1406 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1407 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1408 (*addr_mode
& LPFC_FCF_SPMA
))
1409 *addr_mode
= LPFC_FCF_SPMA
;
1410 else if ((conn_entry
->conn_rec
.flags
& FCFCNCT_AM_VALID
) &&
1411 (conn_entry
->conn_rec
.flags
& FCFCNCT_AM_PREFERRED
) &&
1412 !(conn_entry
->conn_rec
.flags
& FCFCNCT_AM_SPMA
) &&
1413 (*addr_mode
& LPFC_FCF_FPMA
))
1414 *addr_mode
= LPFC_FCF_FPMA
;
1416 /* If matching connect list has a vlan id, use it */
1417 if (conn_entry
->conn_rec
.flags
& FCFCNCT_VLAN_VALID
)
1418 *vlan_id
= conn_entry
->conn_rec
.vlan_tag
;
1420 * If no vlan id is specified in connect list, use the vlan id
1423 else if (fcf_vlan_id
)
1424 *vlan_id
= fcf_vlan_id
;
1435 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1436 * @phba: pointer to lpfc hba data structure.
1437 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1439 * This function check if there is any fcoe event pending while driver
1440 * scan FCF entries. If there is any pending event, it will restart the
1441 * FCF saning and return 1 else return 0.
1444 lpfc_check_pending_fcoe_event(struct lpfc_hba
*phba
, uint8_t unreg_fcf
)
1449 * If the Link is up and no FCoE events while in the
1450 * FCF discovery, no need to restart FCF discovery.
1452 if ((phba
->link_state
>= LPFC_LINK_UP
) &&
1453 (phba
->fcoe_eventtag
== phba
->fcoe_eventtag_at_fcf_scan
))
1456 spin_lock_irq(&phba
->hbalock
);
1457 phba
->fcf
.fcf_flag
&= ~FCF_AVAILABLE
;
1458 spin_unlock_irq(&phba
->hbalock
);
1460 if (phba
->link_state
>= LPFC_LINK_UP
)
1461 lpfc_sli4_read_fcf_record(phba
, LPFC_FCOE_FCF_GET_FIRST
);
1464 * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS
1467 spin_lock_irq(&phba
->hbalock
);
1468 phba
->hba_flag
&= ~FCF_DISC_INPROGRESS
;
1469 spin_unlock_irq(&phba
->hbalock
);
1473 spin_lock_irq(&phba
->hbalock
);
1474 phba
->fcf
.fcf_flag
&= ~FCF_REGISTERED
;
1475 spin_unlock_irq(&phba
->hbalock
);
1476 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1478 lpfc_printf_log(phba
, KERN_ERR
,
1479 LOG_DISCOVERY
|LOG_MBOX
,
1480 "2610 UNREG_FCFI mbox allocation failed\n");
1483 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
1484 mbox
->vport
= phba
->pport
;
1485 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
1486 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1487 if (rc
== MBX_NOT_FINISHED
) {
1488 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
1489 "2611 UNREG_FCFI issue mbox failed\n");
1490 mempool_free(mbox
, phba
->mbox_mem_pool
);
1498 * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox.
1499 * @phba: pointer to lpfc hba data structure.
1500 * @mboxq: pointer to mailbox object.
1502 * This function iterate through all the fcf records available in
1503 * HBA and choose the optimal FCF record for discovery. After finding
1504 * the FCF for discovery it register the FCF record and kick start
1506 * If FCF_IN_USE flag is set in currently used FCF, the routine try to
1507 * use a FCF record which match fabric name and mac address of the
1508 * currently used FCF record.
1509 * If the driver support only one FCF, it will try to use the FCF record
1510 * used by BOOT_BIOS.
1513 lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1516 dma_addr_t phys_addr
;
1518 struct lpfc_mbx_sge sge
;
1519 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
1520 uint32_t shdr_status
, shdr_add_status
;
1521 union lpfc_sli4_cfg_shdr
*shdr
;
1522 struct fcf_record
*new_fcf_record
;
1524 uint32_t boot_flag
, addr_mode
;
1525 uint32_t next_fcf_index
;
1526 unsigned long flags
;
1529 /* If there is pending FCoE event restart FCF table scan */
1530 if (lpfc_check_pending_fcoe_event(phba
, 0)) {
1531 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1535 /* Get the first SGE entry from the non-embedded DMA memory. This
1536 * routine only uses a single SGE.
1538 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
1539 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1540 if (unlikely(!mboxq
->sge_array
)) {
1541 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1542 "2524 Failed to get the non-embedded SGE "
1543 "virtual address\n");
1546 virt_addr
= mboxq
->sge_array
->addr
[0];
1548 shdr
= (union lpfc_sli4_cfg_shdr
*)virt_addr
;
1549 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
1550 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
1553 * The FCF Record was read and there is no reason for the driver
1554 * to maintain the FCF record data or memory. Instead, just need
1555 * to book keeping the FCFIs can be used.
1557 if (shdr_status
|| shdr_add_status
) {
1558 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1559 "2521 READ_FCF_RECORD mailbox failed "
1560 "with status x%x add_status x%x, mbx\n",
1561 shdr_status
, shdr_add_status
);
1564 /* Interpreting the returned information of FCF records */
1565 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
1566 lpfc_sli_pcimem_bcopy(read_fcf
, read_fcf
,
1567 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1568 next_fcf_index
= bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx
, read_fcf
);
1570 new_fcf_record
= (struct fcf_record
*)(virt_addr
+
1571 sizeof(struct lpfc_mbx_read_fcf_tbl
));
1572 lpfc_sli_pcimem_bcopy(new_fcf_record
, new_fcf_record
,
1573 sizeof(struct fcf_record
));
1574 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
1576 rc
= lpfc_match_fcf_conn_list(phba
, new_fcf_record
,
1577 &boot_flag
, &addr_mode
,
1580 * If the fcf record does not match with connect list entries
1581 * read the next entry.
1586 * If this is not the first FCF discovery of the HBA, use last
1587 * FCF record for the discovery.
1589 spin_lock_irqsave(&phba
->hbalock
, flags
);
1590 if (phba
->fcf
.fcf_flag
& FCF_IN_USE
) {
1591 if (lpfc_fab_name_match(phba
->fcf
.fabric_name
,
1593 lpfc_sw_name_match(phba
->fcf
.switch_name
,
1595 lpfc_mac_addr_match(phba
, new_fcf_record
)) {
1596 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
1597 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1600 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1603 if (phba
->fcf
.fcf_flag
& FCF_AVAILABLE
) {
1605 * If the current FCF record does not have boot flag
1606 * set and new fcf record has boot flag set, use the
1609 if (boot_flag
&& !(phba
->fcf
.fcf_flag
& FCF_BOOT_ENABLE
)) {
1610 /* Use this FCF record */
1611 lpfc_copy_fcf_record(phba
, new_fcf_record
);
1612 phba
->fcf
.addr_mode
= addr_mode
;
1613 phba
->fcf
.fcf_flag
|= FCF_BOOT_ENABLE
;
1614 if (vlan_id
!= 0xFFFF) {
1615 phba
->fcf
.fcf_flag
|= FCF_VALID_VLAN
;
1616 phba
->fcf
.vlan_id
= vlan_id
;
1618 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1622 * If the current FCF record has boot flag set and the
1623 * new FCF record does not have boot flag, read the next
1626 if (!boot_flag
&& (phba
->fcf
.fcf_flag
& FCF_BOOT_ENABLE
)) {
1627 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1631 * If there is a record with lower priority value for
1632 * the current FCF, use that record.
1634 if (lpfc_fab_name_match(phba
->fcf
.fabric_name
,
1636 (new_fcf_record
->fip_priority
< phba
->fcf
.priority
)) {
1637 /* Use this FCF record */
1638 lpfc_copy_fcf_record(phba
, new_fcf_record
);
1639 phba
->fcf
.addr_mode
= addr_mode
;
1640 if (vlan_id
!= 0xFFFF) {
1641 phba
->fcf
.fcf_flag
|= FCF_VALID_VLAN
;
1642 phba
->fcf
.vlan_id
= vlan_id
;
1644 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1647 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1651 * This is the first available FCF record, use this
1654 lpfc_copy_fcf_record(phba
, new_fcf_record
);
1655 phba
->fcf
.addr_mode
= addr_mode
;
1657 phba
->fcf
.fcf_flag
|= FCF_BOOT_ENABLE
;
1658 phba
->fcf
.fcf_flag
|= FCF_AVAILABLE
;
1659 if (vlan_id
!= 0xFFFF) {
1660 phba
->fcf
.fcf_flag
|= FCF_VALID_VLAN
;
1661 phba
->fcf
.vlan_id
= vlan_id
;
1663 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1667 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1668 if (next_fcf_index
== LPFC_FCOE_FCF_NEXT_NONE
|| next_fcf_index
== 0)
1669 lpfc_register_fcf(phba
);
1671 lpfc_sli4_read_fcf_record(phba
, next_fcf_index
);
1675 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
1676 lpfc_register_fcf(phba
);
1682 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
1683 * @phba: pointer to lpfc hba data structure.
1684 * @mboxq: pointer to mailbox data structure.
1686 * This function handles completion of init vpi mailbox command.
1689 lpfc_init_vpi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1691 struct lpfc_vport
*vport
= mboxq
->vport
;
1692 if (mboxq
->u
.mb
.mbxStatus
) {
1693 lpfc_printf_vlog(vport
, KERN_ERR
,
1695 "2609 Init VPI mailbox failed 0x%x\n",
1696 mboxq
->u
.mb
.mbxStatus
);
1697 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1698 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1701 vport
->fc_flag
&= ~FC_VPORT_NEEDS_INIT_VPI
;
1703 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
1704 lpfc_initial_fdisc(vport
);
1706 lpfc_vport_set_state(vport
, FC_VPORT_NO_FABRIC_SUPP
);
1707 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1708 "2606 No NPIV Fabric support\n");
1714 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
1715 * @phba: pointer to lpfc hba data structure.
1717 * This function loops through the list of vports on the @phba and issues an
1718 * FDISC if possible.
1721 lpfc_start_fdiscs(struct lpfc_hba
*phba
)
1723 struct lpfc_vport
**vports
;
1725 LPFC_MBOXQ_t
*mboxq
;
1728 vports
= lpfc_create_vport_work_array(phba
);
1729 if (vports
!= NULL
) {
1730 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
1731 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
1733 /* There are no vpi for this vport */
1734 if (vports
[i
]->vpi
> phba
->max_vpi
) {
1735 lpfc_vport_set_state(vports
[i
],
1739 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1740 lpfc_vport_set_state(vports
[i
],
1744 if (vports
[i
]->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
) {
1745 mboxq
= mempool_alloc(phba
->mbox_mem_pool
,
1748 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
1749 LOG_MBOX
, "2607 Failed to allocate "
1750 "init_vpi mailbox\n");
1753 lpfc_init_vpi(phba
, mboxq
, vports
[i
]->vpi
);
1754 mboxq
->vport
= vports
[i
];
1755 mboxq
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
1756 rc
= lpfc_sli_issue_mbox(phba
, mboxq
,
1758 if (rc
== MBX_NOT_FINISHED
) {
1759 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
1760 LOG_MBOX
, "2608 Failed to issue "
1761 "init_vpi mailbox\n");
1763 phba
->mbox_mem_pool
);
1767 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
1768 lpfc_initial_fdisc(vports
[i
]);
1770 lpfc_vport_set_state(vports
[i
],
1771 FC_VPORT_NO_FABRIC_SUPP
);
1772 lpfc_printf_vlog(vports
[i
], KERN_ERR
,
1775 "Fabric support\n");
1779 lpfc_destroy_vport_work_array(phba
, vports
);
1783 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1785 struct lpfc_dmabuf
*dmabuf
= mboxq
->context1
;
1786 struct lpfc_vport
*vport
= mboxq
->vport
;
1788 if (mboxq
->u
.mb
.mbxStatus
) {
1789 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1790 "2018 REG_VFI mbxStatus error x%x "
1792 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
1793 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1794 /* FLOGI failed, use loop map to make discovery list */
1795 lpfc_disc_list_loopmap(vport
);
1796 /* Start discovery */
1797 lpfc_disc_start(vport
);
1800 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1803 /* The VPI is implicitly registered when the VFI is registered */
1804 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
1806 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
1807 lpfc_start_fdiscs(phba
);
1808 lpfc_do_scr_ns_plogi(phba
, vport
);
1812 mempool_free(mboxq
, phba
->mbox_mem_pool
);
1813 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
1819 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1821 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1822 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
1823 struct lpfc_vport
*vport
= pmb
->vport
;
1826 /* Check for error */
1827 if (mb
->mbxStatus
) {
1828 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
1829 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1830 "0319 READ_SPARAM mbxStatus error x%x "
1832 mb
->mbxStatus
, vport
->port_state
);
1833 lpfc_linkdown(phba
);
1837 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
1838 sizeof (struct serv_parm
));
1839 if (phba
->cfg_soft_wwnn
)
1840 u64_to_wwn(phba
->cfg_soft_wwnn
,
1841 vport
->fc_sparam
.nodeName
.u
.wwn
);
1842 if (phba
->cfg_soft_wwpn
)
1843 u64_to_wwn(phba
->cfg_soft_wwpn
,
1844 vport
->fc_sparam
.portName
.u
.wwn
);
1845 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
1846 sizeof(vport
->fc_nodename
));
1847 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
1848 sizeof(vport
->fc_portname
));
1849 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
1850 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
1851 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
1854 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1856 mempool_free(pmb
, phba
->mbox_mem_pool
);
1860 pmb
->context1
= NULL
;
1861 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1863 lpfc_issue_clear_la(phba
, vport
);
1864 mempool_free(pmb
, phba
->mbox_mem_pool
);
1869 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, READ_LA_VAR
*la
)
1871 struct lpfc_vport
*vport
= phba
->pport
;
1872 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
= NULL
;
1874 struct lpfc_dmabuf
*mp
;
1876 struct fcf_record
*fcf_record
;
1878 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1880 spin_lock_irq(&phba
->hbalock
);
1881 switch (la
->UlnkSpeed
) {
1883 phba
->fc_linkspeed
= LA_1GHZ_LINK
;
1886 phba
->fc_linkspeed
= LA_2GHZ_LINK
;
1889 phba
->fc_linkspeed
= LA_4GHZ_LINK
;
1892 phba
->fc_linkspeed
= LA_8GHZ_LINK
;
1895 phba
->fc_linkspeed
= LA_10GHZ_LINK
;
1898 phba
->fc_linkspeed
= LA_UNKNW_LINK
;
1902 phba
->fc_topology
= la
->topology
;
1903 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
1905 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1906 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
1908 /* if npiv is enabled and this adapter supports npiv log
1909 * a message that npiv is not supported in this topology
1911 if (phba
->cfg_enable_npiv
&& phba
->max_vpi
)
1912 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1913 "1309 Link Up Event npiv not supported in loop "
1915 /* Get Loop Map information */
1917 vport
->fc_flag
|= FC_LBIT
;
1919 vport
->fc_myDID
= la
->granted_AL_PA
;
1920 i
= la
->un
.lilpBde64
.tus
.f
.bdeSize
;
1923 phba
->alpa_map
[0] = 0;
1925 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
1936 numalpa
= phba
->alpa_map
[0];
1938 while (j
< numalpa
) {
1939 memset(un
.pamap
, 0, 16);
1940 for (k
= 1; j
< numalpa
; k
++) {
1942 phba
->alpa_map
[j
+ 1];
1947 /* Link Up Event ALPA map */
1948 lpfc_printf_log(phba
,
1951 "1304 Link Up Event "
1952 "ALPA map Data: x%x "
1954 un
.pa
.wd1
, un
.pa
.wd2
,
1955 un
.pa
.wd3
, un
.pa
.wd4
);
1960 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
1961 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1962 (phba
->sli_rev
== 3))
1963 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
1965 vport
->fc_myDID
= phba
->fc_pref_DID
;
1966 vport
->fc_flag
|= FC_LBIT
;
1968 spin_unlock_irq(&phba
->hbalock
);
1972 lpfc_read_sparam(phba
, sparam_mbox
, 0);
1973 sparam_mbox
->vport
= vport
;
1974 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
1975 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
, MBX_NOWAIT
);
1976 if (rc
== MBX_NOT_FINISHED
) {
1977 mp
= (struct lpfc_dmabuf
*) sparam_mbox
->context1
;
1978 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1980 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
1985 if (!(phba
->hba_flag
& HBA_FCOE_SUPPORT
)) {
1986 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1989 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
1990 lpfc_config_link(phba
, cfglink_mbox
);
1991 cfglink_mbox
->vport
= vport
;
1992 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
1993 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
, MBX_NOWAIT
);
1994 if (rc
== MBX_NOT_FINISHED
) {
1995 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
1999 vport
->port_state
= LPFC_VPORT_UNKNOWN
;
2001 * Add the driver's default FCF record at FCF index 0 now. This
2002 * is phase 1 implementation that support FCF index 0 and driver
2005 if (!(phba
->hba_flag
& HBA_FIP_SUPPORT
)) {
2006 fcf_record
= kzalloc(sizeof(struct fcf_record
),
2008 if (unlikely(!fcf_record
)) {
2009 lpfc_printf_log(phba
, KERN_ERR
,
2011 "2554 Could not allocate memmory for "
2017 lpfc_sli4_build_dflt_fcf_record(phba
, fcf_record
,
2018 LPFC_FCOE_FCF_DEF_INDEX
);
2019 rc
= lpfc_sli4_add_fcf_record(phba
, fcf_record
);
2021 lpfc_printf_log(phba
, KERN_ERR
,
2023 "2013 Could not manually add FCF "
2024 "record 0, status %d\n", rc
);
2032 * The driver is expected to do FIP/FCF. Call the port
2033 * and get the FCF Table.
2035 spin_lock_irq(&phba
->hbalock
);
2036 if (phba
->hba_flag
& FCF_DISC_INPROGRESS
) {
2037 spin_unlock_irq(&phba
->hbalock
);
2040 spin_unlock_irq(&phba
->hbalock
);
2041 rc
= lpfc_sli4_read_fcf_record(phba
,
2042 LPFC_FCOE_FCF_GET_FIRST
);
2049 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2050 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2051 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2052 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
2053 lpfc_issue_clear_la(phba
, vport
);
2058 lpfc_enable_la(struct lpfc_hba
*phba
)
2061 struct lpfc_sli
*psli
= &phba
->sli
;
2062 spin_lock_irq(&phba
->hbalock
);
2063 psli
->sli_flag
|= LPFC_PROCESS_LA
;
2064 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
2065 control
= readl(phba
->HCregaddr
);
2066 control
|= HC_LAINT_ENA
;
2067 writel(control
, phba
->HCregaddr
);
2068 readl(phba
->HCregaddr
); /* flush */
2070 spin_unlock_irq(&phba
->hbalock
);
2074 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
2076 lpfc_linkdown(phba
);
2077 lpfc_enable_la(phba
);
2078 lpfc_unregister_unused_fcf(phba
);
2079 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2084 * This routine handles processing a READ_LA mailbox
2085 * command upon completion. It is setup in the LPFC_MBOXQ
2086 * as the completion routine when the command is
2087 * handed off to the SLI layer.
2090 lpfc_mbx_cmpl_read_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2092 struct lpfc_vport
*vport
= pmb
->vport
;
2093 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2095 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2096 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2098 /* Unblock ELS traffic */
2099 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
2100 /* Check for error */
2101 if (mb
->mbxStatus
) {
2102 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
2103 "1307 READ_LA mbox error x%x state x%x\n",
2104 mb
->mbxStatus
, vport
->port_state
);
2105 lpfc_mbx_issue_link_down(phba
);
2106 phba
->link_state
= LPFC_HBA_ERROR
;
2107 goto lpfc_mbx_cmpl_read_la_free_mbuf
;
2110 la
= (READ_LA_VAR
*) &pmb
->u
.mb
.un
.varReadLA
;
2112 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
2114 spin_lock_irq(shost
->host_lock
);
2116 vport
->fc_flag
|= FC_BYPASSED_MODE
;
2118 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
2119 spin_unlock_irq(shost
->host_lock
);
2121 if ((phba
->fc_eventTag
< la
->eventTag
) ||
2122 (phba
->fc_eventTag
== la
->eventTag
)) {
2123 phba
->fc_stat
.LinkMultiEvent
++;
2124 if (la
->attType
== AT_LINK_UP
)
2125 if (phba
->fc_eventTag
!= 0)
2126 lpfc_linkdown(phba
);
2129 phba
->fc_eventTag
= la
->eventTag
;
2131 phba
->sli
.sli_flag
|= LPFC_MENLO_MAINT
;
2133 phba
->sli
.sli_flag
&= ~LPFC_MENLO_MAINT
;
2135 phba
->link_events
++;
2136 if (la
->attType
== AT_LINK_UP
&& (!la
->mm
)) {
2137 phba
->fc_stat
.LinkUp
++;
2138 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
2139 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2140 "1306 Link Up Event in loop back mode "
2141 "x%x received Data: x%x x%x x%x x%x\n",
2142 la
->eventTag
, phba
->fc_eventTag
,
2143 la
->granted_AL_PA
, la
->UlnkSpeed
,
2146 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2147 "1303 Link Up Event x%x received "
2148 "Data: x%x x%x x%x x%x x%x x%x %d\n",
2149 la
->eventTag
, phba
->fc_eventTag
,
2150 la
->granted_AL_PA
, la
->UlnkSpeed
,
2153 phba
->wait_4_mlo_maint_flg
);
2155 lpfc_mbx_process_link_up(phba
, la
);
2156 } else if (la
->attType
== AT_LINK_DOWN
) {
2157 phba
->fc_stat
.LinkDown
++;
2158 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
2159 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2160 "1308 Link Down Event in loop back mode "
2162 "Data: x%x x%x x%x\n",
2163 la
->eventTag
, phba
->fc_eventTag
,
2164 phba
->pport
->port_state
, vport
->fc_flag
);
2167 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2168 "1305 Link Down Event x%x received "
2169 "Data: x%x x%x x%x x%x x%x\n",
2170 la
->eventTag
, phba
->fc_eventTag
,
2171 phba
->pport
->port_state
, vport
->fc_flag
,
2174 lpfc_mbx_issue_link_down(phba
);
2176 if (la
->mm
&& la
->attType
== AT_LINK_UP
) {
2177 if (phba
->link_state
!= LPFC_LINK_DOWN
) {
2178 phba
->fc_stat
.LinkDown
++;
2179 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2180 "1312 Link Down Event x%x received "
2181 "Data: x%x x%x x%x\n",
2182 la
->eventTag
, phba
->fc_eventTag
,
2183 phba
->pport
->port_state
, vport
->fc_flag
);
2184 lpfc_mbx_issue_link_down(phba
);
2186 lpfc_enable_la(phba
);
2188 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
2189 "1310 Menlo Maint Mode Link up Event x%x rcvd "
2190 "Data: x%x x%x x%x\n",
2191 la
->eventTag
, phba
->fc_eventTag
,
2192 phba
->pport
->port_state
, vport
->fc_flag
);
2194 * The cmnd that triggered this will be waiting for this
2197 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
2198 if (phba
->wait_4_mlo_maint_flg
) {
2199 phba
->wait_4_mlo_maint_flg
= 0;
2200 wake_up_interruptible(&phba
->wait_4_mlo_m_q
);
2206 lpfc_issue_clear_la(phba
, vport
);
2207 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
2208 "1311 fa %d\n", la
->fa
);
2211 lpfc_mbx_cmpl_read_la_free_mbuf
:
2212 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2214 mempool_free(pmb
, phba
->mbox_mem_pool
);
2219 * This routine handles processing a REG_LOGIN mailbox
2220 * command upon completion. It is setup in the LPFC_MBOXQ
2221 * as the completion routine when the command is
2222 * handed off to the SLI layer.
2225 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2227 struct lpfc_vport
*vport
= pmb
->vport
;
2228 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2229 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2231 pmb
->context1
= NULL
;
2233 /* Good status, call state machine */
2234 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
2235 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2237 mempool_free(pmb
, phba
->mbox_mem_pool
);
2238 /* decrement the node reference count held for this callback
2247 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2249 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2250 struct lpfc_vport
*vport
= pmb
->vport
;
2251 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2253 switch (mb
->mbxStatus
) {
2257 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2258 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
2262 vport
->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2263 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2264 vport
->unreg_vpi_cmpl
= VPORT_OK
;
2265 mempool_free(pmb
, phba
->mbox_mem_pool
);
2267 * This shost reference might have been taken at the beginning of
2268 * lpfc_vport_delete()
2270 if ((vport
->load_flag
& FC_UNLOADING
) && (vport
!= phba
->pport
))
2271 scsi_host_put(shost
);
2275 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
2277 struct lpfc_hba
*phba
= vport
->phba
;
2281 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2285 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
2286 mbox
->vport
= vport
;
2287 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
2288 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2289 if (rc
== MBX_NOT_FINISHED
) {
2290 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
2291 "1800 Could not issue unreg_vpi\n");
2292 mempool_free(mbox
, phba
->mbox_mem_pool
);
2293 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
2300 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2302 struct lpfc_vport
*vport
= pmb
->vport
;
2303 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2304 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2306 switch (mb
->mbxStatus
) {
2310 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2311 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
2313 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2314 spin_lock_irq(shost
->host_lock
);
2315 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2316 spin_unlock_irq(shost
->host_lock
);
2317 vport
->fc_myDID
= 0;
2321 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
2322 vport
->num_disc_nodes
= 0;
2323 /* go thru NPR list and issue ELS PLOGIs */
2324 if (vport
->fc_npr_cnt
)
2325 lpfc_els_disc_plogi(vport
);
2327 if (!vport
->num_disc_nodes
) {
2328 spin_lock_irq(shost
->host_lock
);
2329 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2330 spin_unlock_irq(shost
->host_lock
);
2331 lpfc_can_disctmo(vport
);
2333 vport
->port_state
= LPFC_VPORT_READY
;
2336 mempool_free(pmb
, phba
->mbox_mem_pool
);
2341 * lpfc_create_static_vport - Read HBA config region to create static vports.
2342 * @phba: pointer to lpfc hba data structure.
2344 * This routine issue a DUMP mailbox command for config region 22 to get
2345 * the list of static vports to be created. The function create vports
2346 * based on the information returned from the HBA.
2349 lpfc_create_static_vport(struct lpfc_hba
*phba
)
2351 LPFC_MBOXQ_t
*pmb
= NULL
;
2353 struct static_vport_info
*vport_info
;
2355 struct fc_vport_identifiers vport_id
;
2356 struct fc_vport
*new_fc_vport
;
2357 struct Scsi_Host
*shost
;
2358 struct lpfc_vport
*vport
;
2359 uint16_t offset
= 0;
2360 uint8_t *vport_buff
;
2361 struct lpfc_dmabuf
*mp
;
2362 uint32_t byte_count
= 0;
2364 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2366 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2367 "0542 lpfc_create_static_vport failed to"
2368 " allocate mailbox memory\n");
2374 vport_info
= kzalloc(sizeof(struct static_vport_info
), GFP_KERNEL
);
2376 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2377 "0543 lpfc_create_static_vport failed to"
2378 " allocate vport_info\n");
2379 mempool_free(pmb
, phba
->mbox_mem_pool
);
2383 vport_buff
= (uint8_t *) vport_info
;
2385 if (lpfc_dump_static_vport(phba
, pmb
, offset
))
2388 pmb
->vport
= phba
->pport
;
2389 rc
= lpfc_sli_issue_mbox_wait(phba
, pmb
, LPFC_MBOX_TMO
);
2391 if ((rc
!= MBX_SUCCESS
) || mb
->mbxStatus
) {
2392 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2393 "0544 lpfc_create_static_vport failed to"
2394 " issue dump mailbox command ret 0x%x "
2400 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2401 byte_count
= pmb
->u
.mqe
.un
.mb_words
[5];
2402 mp
= (struct lpfc_dmabuf
*) pmb
->context2
;
2403 if (byte_count
> sizeof(struct static_vport_info
) -
2405 byte_count
= sizeof(struct static_vport_info
)
2407 memcpy(vport_buff
+ offset
, mp
->virt
, byte_count
);
2408 offset
+= byte_count
;
2410 if (mb
->un
.varDmp
.word_cnt
>
2411 sizeof(struct static_vport_info
) - offset
)
2412 mb
->un
.varDmp
.word_cnt
=
2413 sizeof(struct static_vport_info
)
2415 byte_count
= mb
->un
.varDmp
.word_cnt
;
2416 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
2417 vport_buff
+ offset
,
2420 offset
+= byte_count
;
2423 } while (byte_count
&&
2424 offset
< sizeof(struct static_vport_info
));
2427 if ((le32_to_cpu(vport_info
->signature
) != VPORT_INFO_SIG
) ||
2428 ((le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
)
2429 != VPORT_INFO_REV
)) {
2430 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2431 "0545 lpfc_create_static_vport bad"
2432 " information header 0x%x 0x%x\n",
2433 le32_to_cpu(vport_info
->signature
),
2434 le32_to_cpu(vport_info
->rev
) & VPORT_INFO_REV_MASK
);
2439 shost
= lpfc_shost_from_vport(phba
->pport
);
2441 for (i
= 0; i
< MAX_STATIC_VPORT_COUNT
; i
++) {
2442 memset(&vport_id
, 0, sizeof(vport_id
));
2443 vport_id
.port_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwpn
);
2444 vport_id
.node_name
= wwn_to_u64(vport_info
->vport_list
[i
].wwnn
);
2445 if (!vport_id
.port_name
|| !vport_id
.node_name
)
2448 vport_id
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
2449 vport_id
.vport_type
= FC_PORTTYPE_NPIV
;
2450 vport_id
.disable
= false;
2451 new_fc_vport
= fc_vport_create(shost
, 0, &vport_id
);
2453 if (!new_fc_vport
) {
2454 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2455 "0546 lpfc_create_static_vport failed to"
2460 vport
= *(struct lpfc_vport
**)new_fc_vport
->dd_data
;
2461 vport
->vport_flag
|= STATIC_VPORT
;
2466 if (rc
!= MBX_TIMEOUT
) {
2467 if (pmb
->context2
) {
2468 mp
= (struct lpfc_dmabuf
*) pmb
->context2
;
2469 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2472 mempool_free(pmb
, phba
->mbox_mem_pool
);
2479 * This routine handles processing a Fabric REG_LOGIN mailbox
2480 * command upon completion. It is setup in the LPFC_MBOXQ
2481 * as the completion routine when the command is
2482 * handed off to the SLI layer.
2485 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2487 struct lpfc_vport
*vport
= pmb
->vport
;
2488 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2489 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2490 struct lpfc_nodelist
*ndlp
;
2492 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2493 pmb
->context1
= NULL
;
2494 pmb
->context2
= NULL
;
2495 if (mb
->mbxStatus
) {
2496 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
2497 "0258 Register Fabric login error: 0x%x\n",
2499 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2501 mempool_free(pmb
, phba
->mbox_mem_pool
);
2503 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2504 /* FLOGI failed, use loop map to make discovery list */
2505 lpfc_disc_list_loopmap(vport
);
2507 /* Start discovery */
2508 lpfc_disc_start(vport
);
2509 /* Decrement the reference count to ndlp after the
2510 * reference to the ndlp are done.
2516 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2517 /* Decrement the reference count to ndlp after the reference
2518 * to the ndlp are done.
2524 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2525 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
2526 ndlp
->nlp_type
|= NLP_FABRIC
;
2527 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2529 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
2530 lpfc_start_fdiscs(phba
);
2531 lpfc_do_scr_ns_plogi(phba
, vport
);
2534 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2536 mempool_free(pmb
, phba
->mbox_mem_pool
);
2538 /* Drop the reference count from the mbox at the end after
2539 * all the current reference to the ndlp have been done.
2546 * This routine handles processing a NameServer REG_LOGIN mailbox
2547 * command upon completion. It is setup in the LPFC_MBOXQ
2548 * as the completion routine when the command is
2549 * handed off to the SLI layer.
2552 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2554 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2555 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2556 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2557 struct lpfc_vport
*vport
= pmb
->vport
;
2559 if (mb
->mbxStatus
) {
2561 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2562 "0260 Register NameServer error: 0x%x\n",
2564 /* decrement the node reference count held for this
2565 * callback function.
2568 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2570 mempool_free(pmb
, phba
->mbox_mem_pool
);
2572 /* If no other thread is using the ndlp, free it */
2573 lpfc_nlp_not_used(ndlp
);
2575 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2577 * RegLogin failed, use loop map to make discovery
2580 lpfc_disc_list_loopmap(vport
);
2582 /* Start discovery */
2583 lpfc_disc_start(vport
);
2586 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
2590 pmb
->context1
= NULL
;
2592 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2593 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
2594 ndlp
->nlp_type
|= NLP_FABRIC
;
2595 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2597 if (vport
->port_state
< LPFC_VPORT_READY
) {
2598 /* Link up discovery requires Fabric registration. */
2599 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, 0); /* Do this first! */
2600 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
2601 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
2602 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
2603 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
2605 /* Issue SCR just before NameServer GID_FT Query */
2606 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
2609 vport
->fc_ns_retry
= 0;
2610 /* Good status, issue CT Request to NameServer */
2611 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0)) {
2612 /* Cannot issue NameServer Query, so finish up discovery */
2616 /* decrement the node reference count held for this
2617 * callback function.
2620 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2622 mempool_free(pmb
, phba
->mbox_mem_pool
);
2628 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2630 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2631 struct fc_rport
*rport
;
2632 struct lpfc_rport_data
*rdata
;
2633 struct fc_rport_identifiers rport_ids
;
2634 struct lpfc_hba
*phba
= vport
->phba
;
2636 /* Remote port has reappeared. Re-register w/ FC transport */
2637 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
2638 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
2639 rport_ids
.port_id
= ndlp
->nlp_DID
;
2640 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2643 * We leave our node pointer in rport->dd_data when we unregister a
2644 * FCP target port. But fc_remote_port_add zeros the space to which
2645 * rport->dd_data points. So, if we're reusing a previously
2646 * registered port, drop the reference that we took the last time we
2647 * registered the port.
2649 if (ndlp
->rport
&& ndlp
->rport
->dd_data
&&
2650 ((struct lpfc_rport_data
*) ndlp
->rport
->dd_data
)->pnode
== ndlp
)
2653 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
2654 "rport add: did:x%x flg:x%x type x%x",
2655 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
2657 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
2658 if (!rport
|| !get_device(&rport
->dev
)) {
2659 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
2660 "Warning: fc_remote_port_add failed\n");
2664 /* initialize static port data */
2665 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
2666 rport
->supported_classes
= ndlp
->nlp_class_sup
;
2667 rdata
= rport
->dd_data
;
2668 rdata
->pnode
= lpfc_nlp_get(ndlp
);
2670 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
2671 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2672 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
2673 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2676 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
2677 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2679 if ((rport
->scsi_target_id
!= -1) &&
2680 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
2681 ndlp
->nlp_sid
= rport
->scsi_target_id
;
2687 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
2689 struct fc_rport
*rport
= ndlp
->rport
;
2691 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
2692 "rport delete: did:x%x flg:x%x type x%x",
2693 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
2695 fc_remote_port_delete(rport
);
2701 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
2703 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2705 spin_lock_irq(shost
->host_lock
);
2707 case NLP_STE_UNUSED_NODE
:
2708 vport
->fc_unused_cnt
+= count
;
2710 case NLP_STE_PLOGI_ISSUE
:
2711 vport
->fc_plogi_cnt
+= count
;
2713 case NLP_STE_ADISC_ISSUE
:
2714 vport
->fc_adisc_cnt
+= count
;
2716 case NLP_STE_REG_LOGIN_ISSUE
:
2717 vport
->fc_reglogin_cnt
+= count
;
2719 case NLP_STE_PRLI_ISSUE
:
2720 vport
->fc_prli_cnt
+= count
;
2722 case NLP_STE_UNMAPPED_NODE
:
2723 vport
->fc_unmap_cnt
+= count
;
2725 case NLP_STE_MAPPED_NODE
:
2726 vport
->fc_map_cnt
+= count
;
2728 case NLP_STE_NPR_NODE
:
2729 vport
->fc_npr_cnt
+= count
;
2732 spin_unlock_irq(shost
->host_lock
);
2736 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2737 int old_state
, int new_state
)
2739 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2741 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
2742 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
2743 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
2744 ndlp
->nlp_type
|= NLP_FC_NODE
;
2746 if (new_state
== NLP_STE_MAPPED_NODE
)
2747 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
2748 if (new_state
== NLP_STE_NPR_NODE
)
2749 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
2751 /* Transport interface */
2752 if (ndlp
->rport
&& (old_state
== NLP_STE_MAPPED_NODE
||
2753 old_state
== NLP_STE_UNMAPPED_NODE
)) {
2754 vport
->phba
->nport_event_cnt
++;
2755 lpfc_unregister_remote_port(ndlp
);
2758 if (new_state
== NLP_STE_MAPPED_NODE
||
2759 new_state
== NLP_STE_UNMAPPED_NODE
) {
2760 vport
->phba
->nport_event_cnt
++;
2762 * Tell the fc transport about the port, if we haven't
2763 * already. If we have, and it's a scsi entity, be
2764 * sure to unblock any attached scsi devices
2766 lpfc_register_remote_port(vport
, ndlp
);
2768 if ((new_state
== NLP_STE_MAPPED_NODE
) &&
2769 (vport
->stat_data_enabled
)) {
2771 * A new target is discovered, if there is no buffer for
2772 * statistical data collection allocate buffer.
2774 ndlp
->lat_data
= kcalloc(LPFC_MAX_BUCKET_COUNT
,
2775 sizeof(struct lpfc_scsicmd_bkt
),
2778 if (!ndlp
->lat_data
)
2779 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
2780 "0286 lpfc_nlp_state_cleanup failed to "
2781 "allocate statistical data buffer DID "
2782 "0x%x\n", ndlp
->nlp_DID
);
2785 * if we added to Mapped list, but the remote port
2786 * registration failed or assigned a target id outside
2787 * our presentable range - move the node to the
2790 if (new_state
== NLP_STE_MAPPED_NODE
&&
2792 ndlp
->rport
->scsi_target_id
== -1 ||
2793 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
2794 spin_lock_irq(shost
->host_lock
);
2795 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
2796 spin_unlock_irq(shost
->host_lock
);
2797 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2802 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
2804 static char *states
[] = {
2805 [NLP_STE_UNUSED_NODE
] = "UNUSED",
2806 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
2807 [NLP_STE_ADISC_ISSUE
] = "ADISC",
2808 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
2809 [NLP_STE_PRLI_ISSUE
] = "PRLI",
2810 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
2811 [NLP_STE_MAPPED_NODE
] = "MAPPED",
2812 [NLP_STE_NPR_NODE
] = "NPR",
2815 if (state
< NLP_STE_MAX_STATE
&& states
[state
])
2816 strlcpy(buffer
, states
[state
], size
);
2818 snprintf(buffer
, size
, "unknown (%d)", state
);
2823 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2826 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2827 int old_state
= ndlp
->nlp_state
;
2828 char name1
[16], name2
[16];
2830 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2831 "0904 NPort state transition x%06x, %s -> %s\n",
2833 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
2834 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
2836 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
2837 "node statechg did:x%x old:%d ste:%d",
2838 ndlp
->nlp_DID
, old_state
, state
);
2840 if (old_state
== NLP_STE_NPR_NODE
&&
2841 state
!= NLP_STE_NPR_NODE
)
2842 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2843 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
2844 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
2845 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
2848 if (list_empty(&ndlp
->nlp_listp
)) {
2849 spin_lock_irq(shost
->host_lock
);
2850 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
2851 spin_unlock_irq(shost
->host_lock
);
2852 } else if (old_state
)
2853 lpfc_nlp_counters(vport
, old_state
, -1);
2855 ndlp
->nlp_state
= state
;
2856 lpfc_nlp_counters(vport
, state
, 1);
2857 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
2861 lpfc_enqueue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2863 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2865 if (list_empty(&ndlp
->nlp_listp
)) {
2866 spin_lock_irq(shost
->host_lock
);
2867 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
2868 spin_unlock_irq(shost
->host_lock
);
2873 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2875 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2877 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2878 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
2879 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
2880 spin_lock_irq(shost
->host_lock
);
2881 list_del_init(&ndlp
->nlp_listp
);
2882 spin_unlock_irq(shost
->host_lock
);
2883 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
2884 NLP_STE_UNUSED_NODE
);
2888 lpfc_disable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2890 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2891 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
2892 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
2893 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
2894 NLP_STE_UNUSED_NODE
);
2897 * lpfc_initialize_node - Initialize all fields of node object
2898 * @vport: Pointer to Virtual Port object.
2899 * @ndlp: Pointer to FC node object.
2900 * @did: FC_ID of the node.
2902 * This function is always called when node object need to be initialized.
2903 * It initializes all the fields of the node object. Although the reference
2904 * to phba from @ndlp can be obtained indirectly through it's reference to
2905 * @vport, a direct reference to phba is taken here by @ndlp. This is due
2906 * to the life-span of the @ndlp might go beyond the existence of @vport as
2907 * the final release of ndlp is determined by its reference count. And, the
2908 * operation on @ndlp needs the reference to phba.
2911 lpfc_initialize_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2914 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
2915 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
2916 init_timer(&ndlp
->nlp_delayfunc
);
2917 ndlp
->nlp_delayfunc
.function
= lpfc_els_retry_delay
;
2918 ndlp
->nlp_delayfunc
.data
= (unsigned long)ndlp
;
2919 ndlp
->nlp_DID
= did
;
2920 ndlp
->vport
= vport
;
2921 ndlp
->phba
= vport
->phba
;
2922 ndlp
->nlp_sid
= NLP_NO_SID
;
2923 kref_init(&ndlp
->kref
);
2924 NLP_INT_NODE_ACT(ndlp
);
2925 atomic_set(&ndlp
->cmd_pending
, 0);
2926 ndlp
->cmd_qdepth
= LPFC_MAX_TGT_QDEPTH
;
2929 struct lpfc_nodelist
*
2930 lpfc_enable_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2933 struct lpfc_hba
*phba
= vport
->phba
;
2935 unsigned long flags
;
2940 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
2941 /* The ndlp should not be in memory free mode */
2942 if (NLP_CHK_FREE_REQ(ndlp
)) {
2943 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
2944 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2945 "0277 lpfc_enable_node: ndlp:x%p "
2946 "usgmap:x%x refcnt:%d\n",
2947 (void *)ndlp
, ndlp
->nlp_usg_map
,
2948 atomic_read(&ndlp
->kref
.refcount
));
2951 /* The ndlp should not already be in active mode */
2952 if (NLP_CHK_NODE_ACT(ndlp
)) {
2953 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
2954 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2955 "0278 lpfc_enable_node: ndlp:x%p "
2956 "usgmap:x%x refcnt:%d\n",
2957 (void *)ndlp
, ndlp
->nlp_usg_map
,
2958 atomic_read(&ndlp
->kref
.refcount
));
2962 /* Keep the original DID */
2963 did
= ndlp
->nlp_DID
;
2965 /* re-initialize ndlp except of ndlp linked list pointer */
2966 memset((((char *)ndlp
) + sizeof (struct list_head
)), 0,
2967 sizeof (struct lpfc_nodelist
) - sizeof (struct list_head
));
2968 lpfc_initialize_node(vport
, ndlp
, did
);
2970 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
2972 if (state
!= NLP_STE_UNUSED_NODE
)
2973 lpfc_nlp_set_state(vport
, ndlp
, state
);
2975 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
2976 "node enable: did:x%x",
2977 ndlp
->nlp_DID
, 0, 0);
2982 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
2985 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
2986 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
2987 * the ndlp from the vport. The ndlp marked as UNUSED on the list
2988 * until ALL other outstanding threads have completed. We check
2989 * that the ndlp not already in the UNUSED state before we proceed.
2991 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
2993 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2999 * Start / ReStart rescue timer for Discovery / RSCN handling
3002 lpfc_set_disctmo(struct lpfc_vport
*vport
)
3004 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3005 struct lpfc_hba
*phba
= vport
->phba
;
3008 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
3009 /* For FAN, timeout should be greater than edtov */
3010 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
3012 /* Normal discovery timeout should be > than ELS/CT timeout
3013 * FC spec states we need 3 * ratov for CT requests
3015 tmo
= ((phba
->fc_ratov
* 3) + 3);
3019 if (!timer_pending(&vport
->fc_disctmo
)) {
3020 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3021 "set disc timer: tmo:x%x state:x%x flg:x%x",
3022 tmo
, vport
->port_state
, vport
->fc_flag
);
3025 mod_timer(&vport
->fc_disctmo
, jiffies
+ HZ
* tmo
);
3026 spin_lock_irq(shost
->host_lock
);
3027 vport
->fc_flag
|= FC_DISC_TMO
;
3028 spin_unlock_irq(shost
->host_lock
);
3030 /* Start Discovery Timer state <hba_state> */
3031 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3032 "0247 Start Discovery Timer state x%x "
3033 "Data: x%x x%lx x%x x%x\n",
3034 vport
->port_state
, tmo
,
3035 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
3036 vport
->fc_adisc_cnt
);
3042 * Cancel rescue timer for Discovery / RSCN handling
3045 lpfc_can_disctmo(struct lpfc_vport
*vport
)
3047 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3048 unsigned long iflags
;
3050 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3051 "can disc timer: state:x%x rtry:x%x flg:x%x",
3052 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
3054 /* Turn off discovery timer if its running */
3055 if (vport
->fc_flag
& FC_DISC_TMO
) {
3056 spin_lock_irqsave(shost
->host_lock
, iflags
);
3057 vport
->fc_flag
&= ~FC_DISC_TMO
;
3058 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
3059 del_timer_sync(&vport
->fc_disctmo
);
3060 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
3061 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
3062 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
3065 /* Cancel Discovery Timer state <hba_state> */
3066 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3067 "0248 Cancel Discovery Timer state x%x "
3068 "Data: x%x x%x x%x\n",
3069 vport
->port_state
, vport
->fc_flag
,
3070 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
3075 * Check specified ring for outstanding IOCB on the SLI queue
3076 * Return true if iocb matches the specified nport
3079 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
3080 struct lpfc_sli_ring
*pring
,
3081 struct lpfc_iocbq
*iocb
,
3082 struct lpfc_nodelist
*ndlp
)
3084 struct lpfc_sli
*psli
= &phba
->sli
;
3085 IOCB_t
*icmd
= &iocb
->iocb
;
3086 struct lpfc_vport
*vport
= ndlp
->vport
;
3088 if (iocb
->vport
!= vport
)
3091 if (pring
->ringno
== LPFC_ELS_RING
) {
3092 switch (icmd
->ulpCommand
) {
3093 case CMD_GEN_REQUEST64_CR
:
3094 if (iocb
->context_un
.ndlp
== ndlp
)
3096 case CMD_ELS_REQUEST64_CR
:
3097 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
3099 case CMD_XMIT_ELS_RSP64_CX
:
3100 if (iocb
->context1
== (uint8_t *) ndlp
)
3103 } else if (pring
->ringno
== psli
->extra_ring
) {
3105 } else if (pring
->ringno
== psli
->fcp_ring
) {
3106 /* Skip match check if waiting to relogin to FCP target */
3107 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3108 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
3111 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
3114 } else if (pring
->ringno
== psli
->next_ring
) {
3121 * Free resources / clean up outstanding I/Os
3122 * associated with nlp_rpi in the LPFC_NODELIST entry.
3125 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
3127 LIST_HEAD(completions
);
3128 struct lpfc_sli
*psli
;
3129 struct lpfc_sli_ring
*pring
;
3130 struct lpfc_iocbq
*iocb
, *next_iocb
;
3133 lpfc_fabric_abort_nport(ndlp
);
3136 * Everything that matches on txcmplq will be returned
3137 * by firmware with a no rpi error.
3140 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
3141 /* Now process each ring */
3142 for (i
= 0; i
< psli
->num_rings
; i
++) {
3143 pring
= &psli
->ring
[i
];
3145 spin_lock_irq(&phba
->hbalock
);
3146 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
,
3149 * Check to see if iocb matches the nport we are
3152 if ((lpfc_check_sli_ndlp(phba
, pring
, iocb
,
3154 /* It matches, so deque and call compl
3156 list_move_tail(&iocb
->list
,
3161 spin_unlock_irq(&phba
->hbalock
);
3165 /* Cancel all the IOCBs from the completions list */
3166 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3173 * Free rpi associated with LPFC_NODELIST entry.
3174 * This routine is called from lpfc_freenode(), when we are removing
3175 * a LPFC_NODELIST entry. It is also called if the driver initiates a
3176 * LOGO that completes successfully, and we are waiting to PLOGI back
3177 * to the remote NPort. In addition, it is called after we receive
3178 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
3179 * we are waiting to PLOGI back to the remote NPort.
3182 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3184 struct lpfc_hba
*phba
= vport
->phba
;
3188 if (ndlp
->nlp_flag
& NLP_RPI_VALID
) {
3189 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3191 lpfc_unreg_login(phba
, vport
->vpi
, ndlp
->nlp_rpi
, mbox
);
3192 mbox
->vport
= vport
;
3193 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3194 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3195 if (rc
== MBX_NOT_FINISHED
)
3196 mempool_free(mbox
, phba
->mbox_mem_pool
);
3198 lpfc_no_rpi(phba
, ndlp
);
3200 ndlp
->nlp_flag
&= ~NLP_RPI_VALID
;
3201 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
3208 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
3210 struct lpfc_hba
*phba
= vport
->phba
;
3214 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3216 lpfc_unreg_login(phba
, vport
->vpi
, 0xffff, mbox
);
3217 mbox
->vport
= vport
;
3218 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3219 mbox
->context1
= NULL
;
3220 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
3221 if (rc
!= MBX_TIMEOUT
)
3222 mempool_free(mbox
, phba
->mbox_mem_pool
);
3224 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
3225 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3226 "1836 Could not issue "
3227 "unreg_login(all_rpis) status %d\n", rc
);
3232 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
3234 struct lpfc_hba
*phba
= vport
->phba
;
3238 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3240 lpfc_unreg_did(phba
, vport
->vpi
, 0xffffffff, mbox
);
3241 mbox
->vport
= vport
;
3242 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3243 mbox
->context1
= NULL
;
3244 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_TMO
);
3245 if (rc
!= MBX_TIMEOUT
)
3246 mempool_free(mbox
, phba
->mbox_mem_pool
);
3248 if ((rc
== MBX_TIMEOUT
) || (rc
== MBX_NOT_FINISHED
))
3249 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
3250 "1815 Could not issue "
3251 "unreg_did (default rpis) status %d\n",
3257 * Free resources associated with LPFC_NODELIST entry
3258 * so it can be freed.
3261 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3263 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3264 struct lpfc_hba
*phba
= vport
->phba
;
3265 LPFC_MBOXQ_t
*mb
, *nextmb
;
3266 struct lpfc_dmabuf
*mp
;
3268 /* Cleanup node for NPort <nlp_DID> */
3269 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3270 "0900 Cleanup node for NPort x%x "
3271 "Data: x%x x%x x%x\n",
3272 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3273 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3274 if (NLP_CHK_FREE_REQ(ndlp
)) {
3275 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3276 "0280 lpfc_cleanup_node: ndlp:x%p "
3277 "usgmap:x%x refcnt:%d\n",
3278 (void *)ndlp
, ndlp
->nlp_usg_map
,
3279 atomic_read(&ndlp
->kref
.refcount
));
3280 lpfc_dequeue_node(vport
, ndlp
);
3282 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
3283 "0281 lpfc_cleanup_node: ndlp:x%p "
3284 "usgmap:x%x refcnt:%d\n",
3285 (void *)ndlp
, ndlp
->nlp_usg_map
,
3286 atomic_read(&ndlp
->kref
.refcount
));
3287 lpfc_disable_node(vport
, ndlp
);
3290 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
3291 if ((mb
= phba
->sli
.mbox_active
)) {
3292 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
3293 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
3294 mb
->context2
= NULL
;
3295 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3299 spin_lock_irq(&phba
->hbalock
);
3300 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
3301 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
3302 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
3303 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
3305 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3308 list_del(&mb
->list
);
3309 mempool_free(mb
, phba
->mbox_mem_pool
);
3310 /* We shall not invoke the lpfc_nlp_put to decrement
3311 * the ndlp reference count as we are in the process
3312 * of lpfc_nlp_release.
3316 spin_unlock_irq(&phba
->hbalock
);
3318 lpfc_els_abort(phba
, ndlp
);
3320 spin_lock_irq(shost
->host_lock
);
3321 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
3322 spin_unlock_irq(shost
->host_lock
);
3324 ndlp
->nlp_last_elscmd
= 0;
3325 del_timer_sync(&ndlp
->nlp_delayfunc
);
3327 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
3328 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
3330 lpfc_unreg_rpi(vport
, ndlp
);
3336 * Check to see if we can free the nlp back to the freelist.
3337 * If we are in the middle of using the nlp in the discovery state
3338 * machine, defer the free till we reach the end of the state machine.
3341 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
3343 struct lpfc_hba
*phba
= vport
->phba
;
3344 struct lpfc_rport_data
*rdata
;
3348 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3349 if ((ndlp
->nlp_flag
& NLP_DEFER_RM
) &&
3350 !(ndlp
->nlp_flag
& NLP_RPI_VALID
)) {
3351 /* For this case we need to cleanup the default rpi
3352 * allocated by the firmware.
3354 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
))
3356 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, ndlp
->nlp_DID
,
3357 (uint8_t *) &vport
->fc_sparam
, mbox
, 0);
3359 mempool_free(mbox
, phba
->mbox_mem_pool
);
3362 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3363 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3364 mbox
->vport
= vport
;
3365 mbox
->context2
= NULL
;
3366 rc
=lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3367 if (rc
== MBX_NOT_FINISHED
) {
3368 mempool_free(mbox
, phba
->mbox_mem_pool
);
3373 lpfc_cleanup_node(vport
, ndlp
);
3376 * We can get here with a non-NULL ndlp->rport because when we
3377 * unregister a rport we don't break the rport/node linkage. So if we
3378 * do, make sure we don't leaving any dangling pointers behind.
3381 rdata
= ndlp
->rport
->dd_data
;
3382 rdata
->pnode
= NULL
;
3388 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3391 D_ID mydid
, ndlpdid
, matchdid
;
3393 if (did
== Bcast_DID
)
3396 /* First check for Direct match */
3397 if (ndlp
->nlp_DID
== did
)
3400 /* Next check for area/domain identically equals 0 match */
3401 mydid
.un
.word
= vport
->fc_myDID
;
3402 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
3406 matchdid
.un
.word
= did
;
3407 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
3408 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
3409 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
3410 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
3411 if ((ndlpdid
.un
.b
.domain
== 0) &&
3412 (ndlpdid
.un
.b
.area
== 0)) {
3413 if (ndlpdid
.un
.b
.id
)
3419 matchdid
.un
.word
= ndlp
->nlp_DID
;
3420 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
3421 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
3422 if ((matchdid
.un
.b
.domain
== 0) &&
3423 (matchdid
.un
.b
.area
== 0)) {
3424 if (matchdid
.un
.b
.id
)
3432 /* Search for a nodelist entry */
3433 static struct lpfc_nodelist
*
3434 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
3436 struct lpfc_nodelist
*ndlp
;
3439 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3440 if (lpfc_matchdid(vport
, ndlp
, did
)) {
3441 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
3442 ((uint32_t) ndlp
->nlp_xri
<< 16) |
3443 ((uint32_t) ndlp
->nlp_type
<< 8) |
3444 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
3445 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3446 "0929 FIND node DID "
3447 "Data: x%p x%x x%x x%x\n",
3448 ndlp
, ndlp
->nlp_DID
,
3449 ndlp
->nlp_flag
, data1
);
3454 /* FIND node did <did> NOT FOUND */
3455 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3456 "0932 FIND node did x%x NOT FOUND.\n", did
);
3460 struct lpfc_nodelist
*
3461 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
3463 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3464 struct lpfc_nodelist
*ndlp
;
3466 spin_lock_irq(shost
->host_lock
);
3467 ndlp
= __lpfc_findnode_did(vport
, did
);
3468 spin_unlock_irq(shost
->host_lock
);
3472 struct lpfc_nodelist
*
3473 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
3475 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3476 struct lpfc_nodelist
*ndlp
;
3478 ndlp
= lpfc_findnode_did(vport
, did
);
3480 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
3481 lpfc_rscn_payload_check(vport
, did
) == 0)
3483 ndlp
= (struct lpfc_nodelist
*)
3484 mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
3487 lpfc_nlp_init(vport
, ndlp
, did
);
3488 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
3489 spin_lock_irq(shost
->host_lock
);
3490 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3491 spin_unlock_irq(shost
->host_lock
);
3493 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
3494 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
3497 spin_lock_irq(shost
->host_lock
);
3498 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3499 spin_unlock_irq(shost
->host_lock
);
3503 if ((vport
->fc_flag
& FC_RSCN_MODE
) &&
3504 !(vport
->fc_flag
& FC_NDISC_ACTIVE
)) {
3505 if (lpfc_rscn_payload_check(vport
, did
)) {
3506 /* If we've already recieved a PLOGI from this NPort
3507 * we don't need to try to discover it again.
3509 if (ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
3512 /* Since this node is marked for discovery,
3513 * delay timeout is not needed.
3515 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3516 spin_lock_irq(shost
->host_lock
);
3517 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3518 spin_unlock_irq(shost
->host_lock
);
3522 /* If we've already recieved a PLOGI from this NPort,
3523 * or we are already in the process of discovery on it,
3524 * we don't need to try to discover it again.
3526 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
3527 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
3528 ndlp
->nlp_flag
& NLP_RCV_PLOGI
)
3530 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
3531 spin_lock_irq(shost
->host_lock
);
3532 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3533 spin_unlock_irq(shost
->host_lock
);
3538 /* Build a list of nodes to discover based on the loopmap */
3540 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
3542 struct lpfc_hba
*phba
= vport
->phba
;
3544 uint32_t alpa
, index
;
3546 if (!lpfc_is_link_up(phba
))
3549 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
3552 /* Check for loop map present or not */
3553 if (phba
->alpa_map
[0]) {
3554 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
3555 alpa
= phba
->alpa_map
[j
];
3556 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
3558 lpfc_setup_disc_node(vport
, alpa
);
3561 /* No alpamap, so try all alpa's */
3562 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
3563 /* If cfg_scan_down is set, start from highest
3564 * ALPA (0xef) to lowest (0x1).
3566 if (vport
->cfg_scan_down
)
3569 index
= FC_MAXLOOP
- j
- 1;
3570 alpa
= lpfcAlpaArray
[index
];
3571 if ((vport
->fc_myDID
& 0xff) == alpa
)
3573 lpfc_setup_disc_node(vport
, alpa
);
3580 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
3583 struct lpfc_sli
*psli
= &phba
->sli
;
3584 struct lpfc_sli_ring
*extra_ring
= &psli
->ring
[psli
->extra_ring
];
3585 struct lpfc_sli_ring
*fcp_ring
= &psli
->ring
[psli
->fcp_ring
];
3586 struct lpfc_sli_ring
*next_ring
= &psli
->ring
[psli
->next_ring
];
3590 * if it's not a physical port or if we already send
3591 * clear_la then don't send it.
3593 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
3594 (vport
->port_type
!= LPFC_PHYSICAL_PORT
) ||
3595 (phba
->sli_rev
== LPFC_SLI_REV4
))
3598 /* Link up discovery */
3599 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
3600 phba
->link_state
= LPFC_CLEAR_LA
;
3601 lpfc_clear_la(phba
, mbox
);
3602 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
3603 mbox
->vport
= vport
;
3604 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3605 if (rc
== MBX_NOT_FINISHED
) {
3606 mempool_free(mbox
, phba
->mbox_mem_pool
);
3607 lpfc_disc_flush_list(vport
);
3608 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3609 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3610 next_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
3611 phba
->link_state
= LPFC_HBA_ERROR
;
3616 /* Reg_vpi to tell firmware to resume normal operations */
3618 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
3620 LPFC_MBOXQ_t
*regvpimbox
;
3622 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3624 lpfc_reg_vpi(vport
, regvpimbox
);
3625 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
3626 regvpimbox
->vport
= vport
;
3627 if (lpfc_sli_issue_mbox(phba
, regvpimbox
, MBX_NOWAIT
)
3628 == MBX_NOT_FINISHED
) {
3629 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
3634 /* Start Link up / RSCN discovery on NPR nodes */
3636 lpfc_disc_start(struct lpfc_vport
*vport
)
3638 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3639 struct lpfc_hba
*phba
= vport
->phba
;
3641 uint32_t clear_la_pending
;
3644 if (!lpfc_is_link_up(phba
))
3647 if (phba
->link_state
== LPFC_CLEAR_LA
)
3648 clear_la_pending
= 1;
3650 clear_la_pending
= 0;
3652 if (vport
->port_state
< LPFC_VPORT_READY
)
3653 vport
->port_state
= LPFC_DISC_AUTH
;
3655 lpfc_set_disctmo(vport
);
3657 if (vport
->fc_prevDID
== vport
->fc_myDID
)
3662 vport
->fc_prevDID
= vport
->fc_myDID
;
3663 vport
->num_disc_nodes
= 0;
3665 /* Start Discovery state <hba_state> */
3666 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3667 "0202 Start Discovery hba state x%x "
3668 "Data: x%x x%x x%x\n",
3669 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
3670 vport
->fc_adisc_cnt
);
3672 /* First do ADISCs - if any */
3673 num_sent
= lpfc_els_disc_adisc(vport
);
3679 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
3680 * continue discovery.
3682 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3683 !(vport
->fc_flag
& FC_PT2PT
) &&
3684 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
3685 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
3686 lpfc_issue_reg_vpi(phba
, vport
);
3691 * For SLI2, we need to set port_state to READY and continue
3694 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
3695 /* If we get here, there is nothing to ADISC */
3696 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
3697 lpfc_issue_clear_la(phba
, vport
);
3699 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
3700 vport
->num_disc_nodes
= 0;
3701 /* go thru NPR nodes and issue ELS PLOGIs */
3702 if (vport
->fc_npr_cnt
)
3703 lpfc_els_disc_plogi(vport
);
3705 if (!vport
->num_disc_nodes
) {
3706 spin_lock_irq(shost
->host_lock
);
3707 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
3708 spin_unlock_irq(shost
->host_lock
);
3709 lpfc_can_disctmo(vport
);
3712 vport
->port_state
= LPFC_VPORT_READY
;
3714 /* Next do PLOGIs - if any */
3715 num_sent
= lpfc_els_disc_plogi(vport
);
3720 if (vport
->fc_flag
& FC_RSCN_MODE
) {
3721 /* Check to see if more RSCNs came in while we
3722 * were processing this one.
3724 if ((vport
->fc_rscn_id_cnt
== 0) &&
3725 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
3726 spin_lock_irq(shost
->host_lock
);
3727 vport
->fc_flag
&= ~FC_RSCN_MODE
;
3728 spin_unlock_irq(shost
->host_lock
);
3729 lpfc_can_disctmo(vport
);
3731 lpfc_els_handle_rscn(vport
);
3738 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
3739 * ring the match the sppecified nodelist.
3742 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
3744 LIST_HEAD(completions
);
3745 struct lpfc_sli
*psli
;
3747 struct lpfc_iocbq
*iocb
, *next_iocb
;
3748 struct lpfc_sli_ring
*pring
;
3751 pring
= &psli
->ring
[LPFC_ELS_RING
];
3753 /* Error matching iocb on txq or txcmplq
3754 * First check the txq.
3756 spin_lock_irq(&phba
->hbalock
);
3757 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
3758 if (iocb
->context1
!= ndlp
) {
3762 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
3763 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
3765 list_move_tail(&iocb
->list
, &completions
);
3770 /* Next check the txcmplq */
3771 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
3772 if (iocb
->context1
!= ndlp
) {
3776 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
3777 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
3778 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
3781 spin_unlock_irq(&phba
->hbalock
);
3783 /* Cancel all the IOCBs from the completions list */
3784 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
3789 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
3791 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3792 struct lpfc_hba
*phba
= vport
->phba
;
3794 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
3795 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
3797 if (!NLP_CHK_NODE_ACT(ndlp
))
3799 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
3800 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
3801 lpfc_free_tx(phba
, ndlp
);
3808 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
3810 lpfc_els_flush_rscn(vport
);
3811 lpfc_els_flush_cmd(vport
);
3812 lpfc_disc_flush_list(vport
);
3815 /*****************************************************************************/
3817 * NAME: lpfc_disc_timeout
3819 * FUNCTION: Fibre Channel driver discovery timeout routine.
3821 * EXECUTION ENVIRONMENT: interrupt only
3829 /*****************************************************************************/
3831 lpfc_disc_timeout(unsigned long ptr
)
3833 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
3834 struct lpfc_hba
*phba
= vport
->phba
;
3835 uint32_t tmo_posted
;
3836 unsigned long flags
= 0;
3838 if (unlikely(!phba
))
3841 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
3842 tmo_posted
= vport
->work_port_events
& WORKER_DISC_TMO
;
3844 vport
->work_port_events
|= WORKER_DISC_TMO
;
3845 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
3848 lpfc_worker_wake_up(phba
);
3853 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
3855 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3856 struct lpfc_hba
*phba
= vport
->phba
;
3857 struct lpfc_sli
*psli
= &phba
->sli
;
3858 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3859 LPFC_MBOXQ_t
*initlinkmbox
;
3860 int rc
, clrlaerr
= 0;
3862 if (!(vport
->fc_flag
& FC_DISC_TMO
))
3865 spin_lock_irq(shost
->host_lock
);
3866 vport
->fc_flag
&= ~FC_DISC_TMO
;
3867 spin_unlock_irq(shost
->host_lock
);
3869 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3870 "disc timeout: state:x%x rtry:x%x flg:x%x",
3871 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
3873 switch (vport
->port_state
) {
3875 case LPFC_LOCAL_CFG_LINK
:
3876 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
3880 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
3881 "0221 FAN timeout\n");
3882 /* Start discovery by sending FLOGI, clean up old rpis */
3883 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
3885 if (!NLP_CHK_NODE_ACT(ndlp
))
3887 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
3889 if (ndlp
->nlp_type
& NLP_FABRIC
) {
3890 /* Clean up the ndlp on Fabric connections */
3891 lpfc_drop_node(vport
, ndlp
);
3893 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
3894 /* Fail outstanding IO now since device
3895 * is marked for PLOGI.
3897 lpfc_unreg_rpi(vport
, ndlp
);
3900 if (vport
->port_state
!= LPFC_FLOGI
) {
3901 lpfc_initial_flogi(vport
);
3908 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
3909 /* Initial FLOGI timeout */
3910 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3911 "0222 Initial %s timeout\n",
3912 vport
->vpi
? "FDISC" : "FLOGI");
3914 /* Assume no Fabric and go on with discovery.
3915 * Check for outstanding ELS FLOGI to abort.
3918 /* FLOGI failed, so just use loop map to make discovery list */
3919 lpfc_disc_list_loopmap(vport
);
3921 /* Start discovery */
3922 lpfc_disc_start(vport
);
3925 case LPFC_FABRIC_CFG_LINK
:
3926 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
3928 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3929 "0223 Timeout while waiting for "
3930 "NameServer login\n");
3931 /* Next look for NameServer ndlp */
3932 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
3933 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
3934 lpfc_els_abort(phba
, ndlp
);
3936 /* ReStart discovery */
3940 /* Check for wait for NameServer Rsp timeout */
3941 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3942 "0224 NameServer Query timeout "
3944 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
3946 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
3947 /* Try it one more time */
3948 vport
->fc_ns_retry
++;
3949 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
,
3950 vport
->fc_ns_retry
, 0);
3954 vport
->fc_ns_retry
= 0;
3958 * Discovery is over.
3959 * set port_state to PORT_READY if SLI2.
3960 * cmpl_reg_vpi will set port_state to READY for SLI3.
3962 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
3963 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
3964 lpfc_issue_reg_vpi(phba
, vport
);
3965 else { /* NPIV Not enabled */
3966 lpfc_issue_clear_la(phba
, vport
);
3967 vport
->port_state
= LPFC_VPORT_READY
;
3971 /* Setup and issue mailbox INITIALIZE LINK command */
3972 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3973 if (!initlinkmbox
) {
3974 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3975 "0206 Device Discovery "
3976 "completion error\n");
3977 phba
->link_state
= LPFC_HBA_ERROR
;
3981 lpfc_linkdown(phba
);
3982 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
3983 phba
->cfg_link_speed
);
3984 initlinkmbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
3985 initlinkmbox
->vport
= vport
;
3986 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3987 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
, MBX_NOWAIT
);
3988 lpfc_set_loopback_flag(phba
);
3989 if (rc
== MBX_NOT_FINISHED
)
3990 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
3994 case LPFC_DISC_AUTH
:
3995 /* Node Authentication timeout */
3996 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3997 "0227 Node Authentication timeout\n");
3998 lpfc_disc_flush_list(vport
);
4001 * set port_state to PORT_READY if SLI2.
4002 * cmpl_reg_vpi will set port_state to READY for SLI3.
4004 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
4005 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
4006 lpfc_issue_reg_vpi(phba
, vport
);
4007 else { /* NPIV Not enabled */
4008 lpfc_issue_clear_la(phba
, vport
);
4009 vport
->port_state
= LPFC_VPORT_READY
;
4014 case LPFC_VPORT_READY
:
4015 if (vport
->fc_flag
& FC_RSCN_MODE
) {
4016 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4017 "0231 RSCN timeout Data: x%x "
4019 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
4021 /* Cleanup any outstanding ELS commands */
4022 lpfc_els_flush_cmd(vport
);
4024 lpfc_els_flush_rscn(vport
);
4025 lpfc_disc_flush_list(vport
);
4030 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4031 "0273 Unexpected discovery timeout, "
4032 "vport State x%x\n", vport
->port_state
);
4036 switch (phba
->link_state
) {
4038 /* CLEAR LA timeout */
4039 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4040 "0228 CLEAR LA timeout\n");
4045 lpfc_issue_clear_la(phba
, vport
);
4047 case LPFC_LINK_UNKNOWN
:
4048 case LPFC_WARM_START
:
4049 case LPFC_INIT_START
:
4050 case LPFC_INIT_MBX_CMDS
:
4051 case LPFC_LINK_DOWN
:
4052 case LPFC_HBA_ERROR
:
4053 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
4054 "0230 Unexpected timeout, hba link "
4055 "state x%x\n", phba
->link_state
);
4059 case LPFC_HBA_READY
:
4064 lpfc_disc_flush_list(vport
);
4065 psli
->ring
[(psli
->extra_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4066 psli
->ring
[(psli
->fcp_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4067 psli
->ring
[(psli
->next_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
4068 vport
->port_state
= LPFC_VPORT_READY
;
4075 * This routine handles processing a NameServer REG_LOGIN mailbox
4076 * command upon completion. It is setup in the LPFC_MBOXQ
4077 * as the completion routine when the command is
4078 * handed off to the SLI layer.
4081 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4083 MAILBOX_t
*mb
= &pmb
->u
.mb
;
4084 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
4085 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4086 struct lpfc_vport
*vport
= pmb
->vport
;
4088 pmb
->context1
= NULL
;
4090 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
4091 ndlp
->nlp_flag
|= NLP_RPI_VALID
;
4092 ndlp
->nlp_type
|= NLP_FABRIC
;
4093 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
4096 * Start issuing Fabric-Device Management Interface (FDMI) command to
4097 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
4098 * fdmi-on=2 (supporting RPA/hostnmae)
4101 if (vport
->cfg_fdmi_on
== 1)
4102 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
);
4104 mod_timer(&vport
->fc_fdmitmo
, jiffies
+ HZ
* 60);
4106 /* decrement the node reference count held for this callback
4110 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4112 mempool_free(pmb
, phba
->mbox_mem_pool
);
4118 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
4120 uint16_t *rpi
= param
;
4122 return ndlp
->nlp_rpi
== *rpi
;
4126 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
4128 return memcmp(&ndlp
->nlp_portname
, param
,
4129 sizeof(ndlp
->nlp_portname
)) == 0;
4132 static struct lpfc_nodelist
*
4133 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
4135 struct lpfc_nodelist
*ndlp
;
4137 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4138 if (filter(ndlp
, param
))
4145 * This routine looks up the ndlp lists for the given RPI. If rpi found it
4146 * returns the node list element pointer else return NULL.
4148 struct lpfc_nodelist
*
4149 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
4151 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
4155 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
4156 * returns the node element list pointer else return NULL.
4158 struct lpfc_nodelist
*
4159 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
4161 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4162 struct lpfc_nodelist
*ndlp
;
4164 spin_lock_irq(shost
->host_lock
);
4165 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
4166 spin_unlock_irq(shost
->host_lock
);
4171 lpfc_nlp_init(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4174 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
4176 lpfc_initialize_node(vport
, ndlp
, did
);
4177 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
4179 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
4180 "node init: did:x%x",
4181 ndlp
->nlp_DID
, 0, 0);
4186 /* This routine releases all resources associated with a specifc NPort's ndlp
4187 * and mempool_free's the nodelist.
4190 lpfc_nlp_release(struct kref
*kref
)
4192 struct lpfc_hba
*phba
;
4193 unsigned long flags
;
4194 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
4197 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4198 "node release: did:x%x flg:x%x type:x%x",
4199 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
4201 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
4202 "0279 lpfc_nlp_release: ndlp:x%p "
4203 "usgmap:x%x refcnt:%d\n",
4204 (void *)ndlp
, ndlp
->nlp_usg_map
,
4205 atomic_read(&ndlp
->kref
.refcount
));
4207 /* remove ndlp from action. */
4208 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
4210 /* clear the ndlp active flag for all release cases */
4212 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4213 NLP_CLR_NODE_ACT(ndlp
);
4214 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4216 /* free ndlp memory for final ndlp release */
4217 if (NLP_CHK_FREE_REQ(ndlp
)) {
4218 kfree(ndlp
->lat_data
);
4219 mempool_free(ndlp
, ndlp
->phba
->nlp_mem_pool
);
4223 /* This routine bumps the reference count for a ndlp structure to ensure
4224 * that one discovery thread won't free a ndlp while another discovery thread
4227 struct lpfc_nodelist
*
4228 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
4230 struct lpfc_hba
*phba
;
4231 unsigned long flags
;
4234 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4235 "node get: did:x%x flg:x%x refcnt:x%x",
4236 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4237 atomic_read(&ndlp
->kref
.refcount
));
4238 /* The check of ndlp usage to prevent incrementing the
4239 * ndlp reference count that is in the process of being
4243 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4244 if (!NLP_CHK_NODE_ACT(ndlp
) || NLP_CHK_FREE_ACK(ndlp
)) {
4245 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4246 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4247 "0276 lpfc_nlp_get: ndlp:x%p "
4248 "usgmap:x%x refcnt:%d\n",
4249 (void *)ndlp
, ndlp
->nlp_usg_map
,
4250 atomic_read(&ndlp
->kref
.refcount
));
4253 kref_get(&ndlp
->kref
);
4254 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4259 /* This routine decrements the reference count for a ndlp structure. If the
4260 * count goes to 0, this indicates the the associated nodelist should be
4261 * freed. Returning 1 indicates the ndlp resource has been released; on the
4262 * other hand, returning 0 indicates the ndlp resource has not been released
4266 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
4268 struct lpfc_hba
*phba
;
4269 unsigned long flags
;
4274 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4275 "node put: did:x%x flg:x%x refcnt:x%x",
4276 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4277 atomic_read(&ndlp
->kref
.refcount
));
4279 spin_lock_irqsave(&phba
->ndlp_lock
, flags
);
4280 /* Check the ndlp memory free acknowledge flag to avoid the
4281 * possible race condition that kref_put got invoked again
4282 * after previous one has done ndlp memory free.
4284 if (NLP_CHK_FREE_ACK(ndlp
)) {
4285 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4286 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4287 "0274 lpfc_nlp_put: ndlp:x%p "
4288 "usgmap:x%x refcnt:%d\n",
4289 (void *)ndlp
, ndlp
->nlp_usg_map
,
4290 atomic_read(&ndlp
->kref
.refcount
));
4293 /* Check the ndlp inactivate log flag to avoid the possible
4294 * race condition that kref_put got invoked again after ndlp
4295 * is already in inactivating state.
4297 if (NLP_CHK_IACT_REQ(ndlp
)) {
4298 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4299 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_NODE
,
4300 "0275 lpfc_nlp_put: ndlp:x%p "
4301 "usgmap:x%x refcnt:%d\n",
4302 (void *)ndlp
, ndlp
->nlp_usg_map
,
4303 atomic_read(&ndlp
->kref
.refcount
));
4306 /* For last put, mark the ndlp usage flags to make sure no
4307 * other kref_get and kref_put on the same ndlp shall get
4308 * in between the process when the final kref_put has been
4309 * invoked on this ndlp.
4311 if (atomic_read(&ndlp
->kref
.refcount
) == 1) {
4312 /* Indicate ndlp is put to inactive state. */
4313 NLP_SET_IACT_REQ(ndlp
);
4314 /* Acknowledge ndlp memory free has been seen. */
4315 if (NLP_CHK_FREE_REQ(ndlp
))
4316 NLP_SET_FREE_ACK(ndlp
);
4318 spin_unlock_irqrestore(&phba
->ndlp_lock
, flags
);
4319 /* Note, the kref_put returns 1 when decrementing a reference
4320 * count that was 1, it invokes the release callback function,
4321 * but it still left the reference count as 1 (not actually
4322 * performs the last decrementation). Otherwise, it actually
4323 * decrements the reference count and returns 0.
4325 return kref_put(&ndlp
->kref
, lpfc_nlp_release
);
4328 /* This routine free's the specified nodelist if it is not in use
4329 * by any other discovery thread. This routine returns 1 if the
4330 * ndlp has been freed. A return value of 0 indicates the ndlp is
4331 * not yet been released.
4334 lpfc_nlp_not_used(struct lpfc_nodelist
*ndlp
)
4336 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
4337 "node not used: did:x%x flg:x%x refcnt:x%x",
4338 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
4339 atomic_read(&ndlp
->kref
.refcount
));
4340 if (atomic_read(&ndlp
->kref
.refcount
) == 1)
4341 if (lpfc_nlp_put(ndlp
))
4347 * lpfc_fcf_inuse - Check if FCF can be unregistered.
4348 * @phba: Pointer to hba context object.
4350 * This function iterate through all FC nodes associated
4351 * will all vports to check if there is any node with
4352 * fc_rports associated with it. If there is an fc_rport
4353 * associated with the node, then the node is either in
4354 * discovered state or its devloss_timer is pending.
4357 lpfc_fcf_inuse(struct lpfc_hba
*phba
)
4359 struct lpfc_vport
**vports
;
4361 struct lpfc_nodelist
*ndlp
;
4362 struct Scsi_Host
*shost
;
4364 vports
= lpfc_create_vport_work_array(phba
);
4366 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4367 shost
= lpfc_shost_from_vport(vports
[i
]);
4368 spin_lock_irq(shost
->host_lock
);
4369 list_for_each_entry(ndlp
, &vports
[i
]->fc_nodes
, nlp_listp
) {
4370 if (NLP_CHK_NODE_ACT(ndlp
) && ndlp
->rport
&&
4371 (ndlp
->rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)) {
4373 spin_unlock_irq(shost
->host_lock
);
4376 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
4377 "2624 RPI %x DID %x flg %x still "
4379 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
4381 if (ndlp
->nlp_flag
& NLP_RPI_VALID
)
4385 spin_unlock_irq(shost
->host_lock
);
4388 lpfc_destroy_vport_work_array(phba
, vports
);
4393 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
4394 * @phba: Pointer to hba context object.
4395 * @mboxq: Pointer to mailbox object.
4397 * This function frees memory associated with the mailbox command.
4400 lpfc_unregister_vfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
4402 struct lpfc_vport
*vport
= mboxq
->vport
;
4404 if (mboxq
->u
.mb
.mbxStatus
) {
4405 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4406 "2555 UNREG_VFI mbxStatus error x%x "
4408 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
4410 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4415 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
4416 * @phba: Pointer to hba context object.
4417 * @mboxq: Pointer to mailbox object.
4419 * This function frees memory associated with the mailbox command.
4422 lpfc_unregister_fcfi_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
4424 struct lpfc_vport
*vport
= mboxq
->vport
;
4426 if (mboxq
->u
.mb
.mbxStatus
) {
4427 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4428 "2550 UNREG_FCFI mbxStatus error x%x "
4430 mboxq
->u
.mb
.mbxStatus
, vport
->port_state
);
4432 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4437 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
4438 * @phba: Pointer to hba context object.
4440 * This function check if there are any connected remote port for the FCF and
4441 * if all the devices are disconnected, this function unregister FCFI.
4442 * This function also tries to use another FCF for discovery.
4445 lpfc_unregister_unused_fcf(struct lpfc_hba
*phba
)
4449 struct lpfc_vport
**vports
;
4452 spin_lock_irq(&phba
->hbalock
);
4454 * If HBA is not running in FIP mode or
4455 * If HBA does not support FCoE or
4456 * If FCF is not registered.
4459 if (!(phba
->hba_flag
& HBA_FCOE_SUPPORT
) ||
4460 !(phba
->fcf
.fcf_flag
& FCF_REGISTERED
) ||
4461 (!(phba
->hba_flag
& HBA_FIP_SUPPORT
))) {
4462 spin_unlock_irq(&phba
->hbalock
);
4465 spin_unlock_irq(&phba
->hbalock
);
4467 if (lpfc_fcf_inuse(phba
))
4470 /* At this point, all discovery is aborted */
4471 phba
->pport
->port_state
= LPFC_VPORT_UNKNOWN
;
4473 /* Unregister VPIs */
4474 vports
= lpfc_create_vport_work_array(phba
);
4476 (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
))
4477 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
4478 lpfc_mbx_unreg_vpi(vports
[i
]);
4479 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
4480 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
4482 lpfc_destroy_vport_work_array(phba
, vports
);
4484 /* Unregister VFI */
4485 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4487 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4488 "2556 UNREG_VFI mbox allocation failed"
4490 phba
->pport
->port_state
);
4494 lpfc_unreg_vfi(mbox
, phba
->pport
);
4495 mbox
->vport
= phba
->pport
;
4496 mbox
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
4498 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4499 if (rc
== MBX_NOT_FINISHED
) {
4500 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4501 "2557 UNREG_VFI issue mbox failed rc x%x "
4503 rc
, phba
->pport
->port_state
);
4504 mempool_free(mbox
, phba
->mbox_mem_pool
);
4508 /* Unregister FCF */
4509 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4511 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4512 "2551 UNREG_FCFI mbox allocation failed"
4514 phba
->pport
->port_state
);
4518 lpfc_unreg_fcfi(mbox
, phba
->fcf
.fcfi
);
4519 mbox
->vport
= phba
->pport
;
4520 mbox
->mbox_cmpl
= lpfc_unregister_fcfi_cmpl
;
4521 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4523 if (rc
== MBX_NOT_FINISHED
) {
4524 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4525 "2552 UNREG_FCFI issue mbox failed rc x%x "
4527 rc
, phba
->pport
->port_state
);
4528 mempool_free(mbox
, phba
->mbox_mem_pool
);
4532 spin_lock_irq(&phba
->hbalock
);
4533 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_REGISTERED
|
4534 FCF_DISCOVERED
| FCF_BOOT_ENABLE
| FCF_IN_USE
|
4536 spin_unlock_irq(&phba
->hbalock
);
4539 * If driver is not unloading, check if there is any other
4540 * FCF record that can be used for discovery.
4542 if ((phba
->pport
->load_flag
& FC_UNLOADING
) ||
4543 (phba
->link_state
< LPFC_LINK_UP
))
4546 rc
= lpfc_sli4_read_fcf_record(phba
, LPFC_FCOE_FCF_GET_FIRST
);
4549 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
4550 "2553 lpfc_unregister_unused_fcf failed to read FCF"
4551 " record HBA state x%x\n",
4552 phba
->pport
->port_state
);
4556 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
4557 * @phba: Pointer to hba context object.
4558 * @buff: Buffer containing the FCF connection table as in the config
4560 * This function create driver data structure for the FCF connection
4561 * record table read from config region 23.
4564 lpfc_read_fcf_conn_tbl(struct lpfc_hba
*phba
,
4567 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
4568 struct lpfc_fcf_conn_hdr
*conn_hdr
;
4569 struct lpfc_fcf_conn_rec
*conn_rec
;
4570 uint32_t record_count
;
4573 /* Free the current connect table */
4574 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
4575 &phba
->fcf_conn_rec_list
, list
) {
4576 list_del_init(&conn_entry
->list
);
4580 conn_hdr
= (struct lpfc_fcf_conn_hdr
*) buff
;
4581 record_count
= conn_hdr
->length
* sizeof(uint32_t)/
4582 sizeof(struct lpfc_fcf_conn_rec
);
4584 conn_rec
= (struct lpfc_fcf_conn_rec
*)
4585 (buff
+ sizeof(struct lpfc_fcf_conn_hdr
));
4587 for (i
= 0; i
< record_count
; i
++) {
4588 if (!(conn_rec
[i
].flags
& FCFCNCT_VALID
))
4590 conn_entry
= kzalloc(sizeof(struct lpfc_fcf_conn_entry
),
4593 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4594 "2566 Failed to allocate connection"
4599 memcpy(&conn_entry
->conn_rec
, &conn_rec
[i
],
4600 sizeof(struct lpfc_fcf_conn_rec
));
4601 conn_entry
->conn_rec
.vlan_tag
=
4602 le16_to_cpu(conn_entry
->conn_rec
.vlan_tag
) & 0xFFF;
4603 conn_entry
->conn_rec
.flags
=
4604 le16_to_cpu(conn_entry
->conn_rec
.flags
);
4605 list_add_tail(&conn_entry
->list
,
4606 &phba
->fcf_conn_rec_list
);
4611 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
4612 * @phba: Pointer to hba context object.
4613 * @buff: Buffer containing the FCoE parameter data structure.
4615 * This function update driver data structure with config
4616 * parameters read from config region 23.
4619 lpfc_read_fcoe_param(struct lpfc_hba
*phba
,
4622 struct lpfc_fip_param_hdr
*fcoe_param_hdr
;
4623 struct lpfc_fcoe_params
*fcoe_param
;
4625 fcoe_param_hdr
= (struct lpfc_fip_param_hdr
*)
4627 fcoe_param
= (struct lpfc_fcoe_params
*)
4628 (buff
+ sizeof(struct lpfc_fip_param_hdr
));
4630 if ((fcoe_param_hdr
->parm_version
!= FIPP_VERSION
) ||
4631 (fcoe_param_hdr
->length
!= FCOE_PARAM_LENGTH
))
4634 if (fcoe_param_hdr
->parm_flags
& FIPP_VLAN_VALID
) {
4635 phba
->valid_vlan
= 1;
4636 phba
->vlan_id
= le16_to_cpu(fcoe_param
->vlan_tag
) &
4640 phba
->fc_map
[0] = fcoe_param
->fc_map
[0];
4641 phba
->fc_map
[1] = fcoe_param
->fc_map
[1];
4642 phba
->fc_map
[2] = fcoe_param
->fc_map
[2];
4647 * lpfc_get_rec_conf23 - Get a record type in config region data.
4648 * @buff: Buffer containing config region 23 data.
4649 * @size: Size of the data buffer.
4650 * @rec_type: Record type to be searched.
4652 * This function searches config region data to find the begining
4653 * of the record specified by record_type. If record found, this
4654 * function return pointer to the record else return NULL.
4657 lpfc_get_rec_conf23(uint8_t *buff
, uint32_t size
, uint8_t rec_type
)
4659 uint32_t offset
= 0, rec_length
;
4661 if ((buff
[0] == LPFC_REGION23_LAST_REC
) ||
4662 (size
< sizeof(uint32_t)))
4665 rec_length
= buff
[offset
+ 1];
4668 * One TLV record has one word header and number of data words
4669 * specified in the rec_length field of the record header.
4671 while ((offset
+ rec_length
* sizeof(uint32_t) + sizeof(uint32_t))
4673 if (buff
[offset
] == rec_type
)
4674 return &buff
[offset
];
4676 if (buff
[offset
] == LPFC_REGION23_LAST_REC
)
4679 offset
+= rec_length
* sizeof(uint32_t) + sizeof(uint32_t);
4680 rec_length
= buff
[offset
+ 1];
4686 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
4687 * @phba: Pointer to lpfc_hba data structure.
4688 * @buff: Buffer containing config region 23 data.
4689 * @size: Size of the data buffer.
4691 * This fuction parse the FCoE config parameters in config region 23 and
4692 * populate driver data structure with the parameters.
4695 lpfc_parse_fcoe_conf(struct lpfc_hba
*phba
,
4699 uint32_t offset
= 0, rec_length
;
4703 * If data size is less than 2 words signature and version cannot be
4706 if (size
< 2*sizeof(uint32_t))
4709 /* Check the region signature first */
4710 if (memcmp(buff
, LPFC_REGION23_SIGNATURE
, 4)) {
4711 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4712 "2567 Config region 23 has bad signature\n");
4718 /* Check the data structure version */
4719 if (buff
[offset
] != LPFC_REGION23_VERSION
) {
4720 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4721 "2568 Config region 23 has bad version\n");
4726 rec_length
= buff
[offset
+ 1];
4728 /* Read FCoE param record */
4729 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
4730 size
- offset
, FCOE_PARAM_TYPE
);
4732 lpfc_read_fcoe_param(phba
, rec_ptr
);
4734 /* Read FCF connection table */
4735 rec_ptr
= lpfc_get_rec_conf23(&buff
[offset
],
4736 size
- offset
, FCOE_CONN_TBL_TYPE
);
4738 lpfc_read_fcf_conn_tbl(phba
, rec_ptr
);