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);
528 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
529 lpfc_sli4_fcf_redisc_event_proc(phba);
532 vports = lpfc_create_vport_work_array(phba);
534 for (i = 0; i <= phba->max_vports; i++) {
536 * We could have no vports in array if unloading, so if
537 * this happens then just use the pport
539 if (vports[i] == NULL && i == 0)
545 spin_lock_irq(&vport->work_port_lock);
546 work_port_events = vport->work_port_events;
547 vport->work_port_events &= ~work_port_events;
548 spin_unlock_irq(&vport->work_port_lock);
549 if (work_port_events & WORKER_DISC_TMO)
550 lpfc_disc_timeout_handler(vport);
551 if (work_port_events & WORKER_ELS_TMO)
552 lpfc_els_timeout_handler(vport);
553 if (work_port_events & WORKER_HB_TMO)
554 lpfc_hb_timeout_handler(phba);
555 if (work_port_events & WORKER_MBOX_TMO)
556 lpfc_mbox_timeout_handler(phba);
557 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
558 lpfc_unblock_fabric_iocbs(phba);
559 if (work_port_events & WORKER_FDMI_TMO)
560 lpfc_fdmi_timeout_handler(vport);
561 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
562 lpfc_ramp_down_queue_handler(phba);
563 if (work_port_events & WORKER_RAMP_UP_QUEUE)
564 lpfc_ramp_up_queue_handler(phba);
566 lpfc_destroy_vport_work_array(phba, vports);
568 pring = &phba->sli.ring[LPFC_ELS_RING];
569 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
570 status >>= (4*LPFC_ELS_RING);
571 if ((status & HA_RXMASK) ||
572 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
573 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
574 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
575 pring->flag |= LPFC_DEFERRED_RING_EVENT;
576 /* Set the lpfc data pending flag */
577 set_bit(LPFC_DATA_READY, &phba->data_flags);
579 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
580 lpfc_sli_handle_slow_ring_event(phba, pring,
585 * Turn on Ring interrupts
587 if (phba->sli_rev <= LPFC_SLI_REV3) {
588 spin_lock_irq(&phba->hbalock);
589 control = readl(phba->HCregaddr);
590 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
591 lpfc_debugfs_slow_ring_trc(phba,
592 "WRK Enable ring: cntl:x%x hacopy:x%x",
593 control, ha_copy, 0);
595 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
596 writel(control, phba->HCregaddr);
597 readl(phba->HCregaddr); /* flush */
599 lpfc_debugfs_slow_ring_trc(phba,
600 "WRK Ring ok: cntl:x%x hacopy:x%x",
601 control, ha_copy, 0);
603 spin_unlock_irq(&phba->hbalock);
606 lpfc_work_list_done(phba);
610 lpfc_do_work(void *p)
612 struct lpfc_hba *phba = p;
615 set_user_nice(current, -20);
616 phba->data_flags = 0;
618 while (!kthread_should_stop()) {
619 /* wait and check worker queue activities */
620 rc = wait_event_interruptible(phba->work_waitq,
621 (test_and_clear_bit(LPFC_DATA_READY,
623 || kthread_should_stop()));
624 /* Signal wakeup shall terminate the worker thread */
626 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
627 "0433 Wakeup on signal: rc=x%x\n", rc);
631 /* Attend pending lpfc data processing */
632 lpfc_work_done(phba);
634 phba->worker_thread = NULL;
635 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
636 "0432 Worker thread stopped.\n");
641 * This is only called to handle FC worker events. Since this a rare
642 * occurance, we allocate a struct lpfc_work_evt structure here instead of
643 * embedding it in the IOCB.
646 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
649 struct lpfc_work_evt *evtp;
653 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
654 * be queued to worker thread for processing
656 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
660 evtp->evt_arg1 = arg1;
661 evtp->evt_arg2 = arg2;
664 spin_lock_irqsave(&phba->hbalock, flags);
665 list_add_tail(&evtp->evt_listp, &phba->work_list);
666 spin_unlock_irqrestore(&phba->hbalock, flags);
668 lpfc_worker_wake_up(phba);
674 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
676 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
677 struct lpfc_hba *phba = vport->phba;
678 struct lpfc_nodelist *ndlp, *next_ndlp;
681 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
682 if (!NLP_CHK_NODE_ACT(ndlp))
684 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
686 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
687 ((vport->port_type == LPFC_NPIV_PORT) &&
688 (ndlp->nlp_DID == NameServer_DID)))
689 lpfc_unreg_rpi(vport, ndlp);
691 /* Leave Fabric nodes alone on link down */
692 if ((phba->sli_rev < LPFC_SLI_REV4) &&
693 (!remove && ndlp->nlp_type & NLP_FABRIC))
695 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
698 : NLP_EVT_DEVICE_RECOVERY);
700 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
701 lpfc_mbx_unreg_vpi(vport);
702 spin_lock_irq(shost->host_lock);
703 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
704 spin_unlock_irq(shost->host_lock);
709 lpfc_port_link_failure(struct lpfc_vport *vport)
711 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
713 /* Cleanup any outstanding received buffers */
714 lpfc_cleanup_rcv_buffers(vport);
716 /* Cleanup any outstanding RSCN activity */
717 lpfc_els_flush_rscn(vport);
719 /* Cleanup any outstanding ELS commands */
720 lpfc_els_flush_cmd(vport);
722 lpfc_cleanup_rpis(vport, 0);
724 /* Turn off discovery timer if its running */
725 lpfc_can_disctmo(vport);
729 lpfc_linkdown_port(struct lpfc_vport *vport)
731 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
733 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
736 "Link Down: state:x%x rtry:x%x flg:x%x",
737 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
739 lpfc_port_link_failure(vport);
744 lpfc_linkdown(struct lpfc_hba *phba)
746 struct lpfc_vport *vport = phba->pport;
747 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
748 struct lpfc_vport **vports;
752 if (phba->link_state == LPFC_LINK_DOWN)
755 /* Block all SCSI stack I/Os */
756 lpfc_scsi_dev_block(phba);
758 spin_lock_irq(&phba->hbalock);
759 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
760 spin_unlock_irq(&phba->hbalock);
761 if (phba->link_state > LPFC_LINK_DOWN) {
762 phba->link_state = LPFC_LINK_DOWN;
763 spin_lock_irq(shost->host_lock);
764 phba->pport->fc_flag &= ~FC_LBIT;
765 spin_unlock_irq(shost->host_lock);
767 vports = lpfc_create_vport_work_array(phba);
769 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
770 /* Issue a LINK DOWN event to all nodes */
771 lpfc_linkdown_port(vports[i]);
773 lpfc_destroy_vport_work_array(phba, vports);
774 /* Clean up any firmware default rpi's */
775 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
777 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
779 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
780 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
781 == MBX_NOT_FINISHED) {
782 mempool_free(mb, phba->mbox_mem_pool);
786 /* Setup myDID for link up if we are in pt2pt mode */
787 if (phba->pport->fc_flag & FC_PT2PT) {
788 phba->pport->fc_myDID = 0;
789 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
791 lpfc_config_link(phba, mb);
792 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
794 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
795 == MBX_NOT_FINISHED) {
796 mempool_free(mb, phba->mbox_mem_pool);
799 spin_lock_irq(shost->host_lock);
800 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
801 spin_unlock_irq(shost->host_lock);
808 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
810 struct lpfc_nodelist *ndlp;
812 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
813 if (!NLP_CHK_NODE_ACT(ndlp))
815 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
817 if (ndlp->nlp_type & NLP_FABRIC) {
818 /* On Linkup its safe to clean up the ndlp
819 * from Fabric connections.
821 if (ndlp->nlp_DID != Fabric_DID)
822 lpfc_unreg_rpi(vport, ndlp);
823 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
824 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
825 /* Fail outstanding IO now since device is
828 lpfc_unreg_rpi(vport, ndlp);
834 lpfc_linkup_port(struct lpfc_vport *vport)
836 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
837 struct lpfc_hba *phba = vport->phba;
839 if ((vport->load_flag & FC_UNLOADING) != 0)
842 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
843 "Link Up: top:x%x speed:x%x flg:x%x",
844 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
846 /* If NPIV is not enabled, only bring the physical port up */
847 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
848 (vport != phba->pport))
851 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
853 spin_lock_irq(shost->host_lock);
854 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
855 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
856 vport->fc_flag |= FC_NDISC_ACTIVE;
857 vport->fc_ns_retry = 0;
858 spin_unlock_irq(shost->host_lock);
860 if (vport->fc_flag & FC_LBIT)
861 lpfc_linkup_cleanup_nodes(vport);
866 lpfc_linkup(struct lpfc_hba *phba)
868 struct lpfc_vport **vports;
871 phba->link_state = LPFC_LINK_UP;
873 /* Unblock fabric iocbs if they are blocked */
874 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
875 del_timer_sync(&phba->fabric_block_timer);
877 vports = lpfc_create_vport_work_array(phba);
879 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
880 lpfc_linkup_port(vports[i]);
881 lpfc_destroy_vport_work_array(phba, vports);
882 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
883 (phba->sli_rev < LPFC_SLI_REV4))
884 lpfc_issue_clear_la(phba, phba->pport);
890 * This routine handles processing a CLEAR_LA mailbox
891 * command upon completion. It is setup in the LPFC_MBOXQ
892 * as the completion routine when the command is
893 * handed off to the SLI layer.
896 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
898 struct lpfc_vport *vport = pmb->vport;
899 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
900 struct lpfc_sli *psli = &phba->sli;
901 MAILBOX_t *mb = &pmb->u.mb;
904 /* Since we don't do discovery right now, turn these off here */
905 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
906 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
907 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
909 /* Check for error */
910 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
911 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
912 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
913 "0320 CLEAR_LA mbxStatus error x%x hba "
915 mb->mbxStatus, vport->port_state);
916 phba->link_state = LPFC_HBA_ERROR;
920 if (vport->port_type == LPFC_PHYSICAL_PORT)
921 phba->link_state = LPFC_HBA_READY;
923 spin_lock_irq(&phba->hbalock);
924 psli->sli_flag |= LPFC_PROCESS_LA;
925 control = readl(phba->HCregaddr);
926 control |= HC_LAINT_ENA;
927 writel(control, phba->HCregaddr);
928 readl(phba->HCregaddr); /* flush */
929 spin_unlock_irq(&phba->hbalock);
930 mempool_free(pmb, phba->mbox_mem_pool);
934 /* Device Discovery completes */
935 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
936 "0225 Device Discovery completes\n");
937 mempool_free(pmb, phba->mbox_mem_pool);
939 spin_lock_irq(shost->host_lock);
940 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
941 spin_unlock_irq(shost->host_lock);
943 lpfc_can_disctmo(vport);
945 /* turn on Link Attention interrupts */
947 spin_lock_irq(&phba->hbalock);
948 psli->sli_flag |= LPFC_PROCESS_LA;
949 control = readl(phba->HCregaddr);
950 control |= HC_LAINT_ENA;
951 writel(control, phba->HCregaddr);
952 readl(phba->HCregaddr); /* flush */
953 spin_unlock_irq(&phba->hbalock);
960 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
962 struct lpfc_vport *vport = pmb->vport;
964 if (pmb->u.mb.mbxStatus)
967 mempool_free(pmb, phba->mbox_mem_pool);
969 if (phba->fc_topology == TOPOLOGY_LOOP &&
970 vport->fc_flag & FC_PUBLIC_LOOP &&
971 !(vport->fc_flag & FC_LBIT)) {
972 /* Need to wait for FAN - use discovery timer
973 * for timeout. port_state is identically
974 * LPFC_LOCAL_CFG_LINK while waiting for FAN
976 lpfc_set_disctmo(vport);
980 /* Start discovery by sending a FLOGI. port_state is identically
981 * LPFC_FLOGI while waiting for FLOGI cmpl
983 if (vport->port_state != LPFC_FLOGI) {
984 lpfc_initial_flogi(vport);
989 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
990 "0306 CONFIG_LINK mbxStatus error x%x "
992 pmb->u.mb.mbxStatus, vport->port_state);
993 mempool_free(pmb, phba->mbox_mem_pool);
997 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
998 "0200 CONFIG_LINK bad hba state x%x\n",
1001 lpfc_issue_clear_la(phba, vport);
1006 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1008 struct lpfc_vport *vport = mboxq->vport;
1009 unsigned long flags;
1011 if (mboxq->u.mb.mbxStatus) {
1012 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1013 "2017 REG_FCFI mbxStatus error x%x "
1015 mboxq->u.mb.mbxStatus, vport->port_state);
1016 mempool_free(mboxq, phba->mbox_mem_pool);
1020 /* Start FCoE discovery by sending a FLOGI. */
1021 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1022 /* Set the FCFI registered flag */
1023 spin_lock_irqsave(&phba->hbalock, flags);
1024 phba->fcf.fcf_flag |= FCF_REGISTERED;
1025 spin_unlock_irqrestore(&phba->hbalock, flags);
1026 /* If there is a pending FCoE event, restart FCF table scan. */
1027 if (lpfc_check_pending_fcoe_event(phba, 1)) {
1028 mempool_free(mboxq, phba->mbox_mem_pool);
1031 spin_lock_irqsave(&phba->hbalock, flags);
1032 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1033 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1034 spin_unlock_irqrestore(&phba->hbalock, flags);
1035 if (vport->port_state != LPFC_FLOGI)
1036 lpfc_initial_flogi(vport);
1038 mempool_free(mboxq, phba->mbox_mem_pool);
1043 * lpfc_fab_name_match - Check if the fcf fabric name match.
1044 * @fab_name: pointer to fabric name.
1045 * @new_fcf_record: pointer to fcf record.
1047 * This routine compare the fcf record's fabric name with provided
1048 * fabric name. If the fabric name are identical this function
1049 * returns 1 else return 0.
1052 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1054 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1056 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1058 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1060 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1062 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1064 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1066 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1068 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1074 * lpfc_sw_name_match - Check if the fcf switch name match.
1075 * @fab_name: pointer to fabric name.
1076 * @new_fcf_record: pointer to fcf record.
1078 * This routine compare the fcf record's switch name with provided
1079 * switch name. If the switch name are identical this function
1080 * returns 1 else return 0.
1083 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1085 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1087 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1089 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1091 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1093 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1095 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1097 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1099 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1105 * lpfc_mac_addr_match - Check if the fcf mac address match.
1106 * @mac_addr: pointer to mac address.
1107 * @new_fcf_record: pointer to fcf record.
1109 * This routine compare the fcf record's mac address with HBA's
1110 * FCF mac address. If the mac addresses are identical this function
1111 * returns 1 else return 0.
1114 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1116 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1118 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1120 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1122 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1124 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1126 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1132 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1134 return (curr_vlan_id == new_vlan_id);
1138 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1139 * @fcf: pointer to driver fcf record.
1140 * @new_fcf_record: pointer to fcf record.
1142 * This routine copies the FCF information from the FCF
1143 * record to lpfc_hba data structure.
1146 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1147 struct fcf_record *new_fcf_record)
1150 fcf_rec->fabric_name[0] =
1151 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1152 fcf_rec->fabric_name[1] =
1153 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1154 fcf_rec->fabric_name[2] =
1155 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1156 fcf_rec->fabric_name[3] =
1157 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1158 fcf_rec->fabric_name[4] =
1159 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1160 fcf_rec->fabric_name[5] =
1161 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1162 fcf_rec->fabric_name[6] =
1163 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1164 fcf_rec->fabric_name[7] =
1165 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1167 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1168 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1169 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1170 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1171 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1172 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1173 /* FCF record index */
1174 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1175 /* FCF record priority */
1176 fcf_rec->priority = new_fcf_record->fip_priority;
1178 fcf_rec->switch_name[0] =
1179 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1180 fcf_rec->switch_name[1] =
1181 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1182 fcf_rec->switch_name[2] =
1183 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1184 fcf_rec->switch_name[3] =
1185 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1186 fcf_rec->switch_name[4] =
1187 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1188 fcf_rec->switch_name[5] =
1189 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1190 fcf_rec->switch_name[6] =
1191 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1192 fcf_rec->switch_name[7] =
1193 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1197 * lpfc_update_fcf_record - Update driver fcf record
1198 * @phba: pointer to lpfc hba data structure.
1199 * @fcf_rec: pointer to driver fcf record.
1200 * @new_fcf_record: pointer to hba fcf record.
1201 * @addr_mode: address mode to be set to the driver fcf record.
1202 * @vlan_id: vlan tag to be set to the driver fcf record.
1203 * @flag: flag bits to be set to the driver fcf record.
1205 * This routine updates the driver FCF record from the new HBA FCF record
1206 * together with the address mode, vlan_id, and other informations. This
1207 * routine is called with the host lock held.
1210 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1211 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1212 uint16_t vlan_id, uint32_t flag)
1214 /* Copy the fields from the HBA's FCF record */
1215 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1216 /* Update other fields of driver FCF record */
1217 fcf_rec->addr_mode = addr_mode;
1218 fcf_rec->vlan_id = vlan_id;
1219 fcf_rec->flag |= (flag | RECORD_VALID);
1223 * lpfc_register_fcf - Register the FCF with hba.
1224 * @phba: pointer to lpfc hba data structure.
1226 * This routine issues a register fcfi mailbox command to register
1230 lpfc_register_fcf(struct lpfc_hba *phba)
1232 LPFC_MBOXQ_t *fcf_mbxq;
1234 unsigned long flags;
1236 spin_lock_irqsave(&phba->hbalock, flags);
1238 /* If the FCF is not availabe do nothing. */
1239 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1240 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1241 spin_unlock_irqrestore(&phba->hbalock, flags);
1245 /* The FCF is already registered, start discovery */
1246 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1247 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1248 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1249 spin_unlock_irqrestore(&phba->hbalock, flags);
1250 if (phba->pport->port_state != LPFC_FLOGI)
1251 lpfc_initial_flogi(phba->pport);
1254 spin_unlock_irqrestore(&phba->hbalock, flags);
1256 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool,
1259 spin_lock_irqsave(&phba->hbalock, flags);
1260 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1261 spin_unlock_irqrestore(&phba->hbalock, flags);
1265 lpfc_reg_fcfi(phba, fcf_mbxq);
1266 fcf_mbxq->vport = phba->pport;
1267 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1268 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1269 if (rc == MBX_NOT_FINISHED) {
1270 spin_lock_irqsave(&phba->hbalock, flags);
1271 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1272 spin_unlock_irqrestore(&phba->hbalock, flags);
1273 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1280 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1281 * @phba: pointer to lpfc hba data structure.
1282 * @new_fcf_record: pointer to fcf record.
1283 * @boot_flag: Indicates if this record used by boot bios.
1284 * @addr_mode: The address mode to be used by this FCF
1285 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1287 * This routine compare the fcf record with connect list obtained from the
1288 * config region to decide if this FCF can be used for SAN discovery. It returns
1289 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1290 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1291 * is used by boot bios and addr_mode will indicate the addressing mode to be
1292 * used for this FCF when the function returns.
1293 * If the FCF record need to be used with a particular vlan id, the vlan is
1294 * set in the vlan_id on return of the function. If not VLAN tagging need to
1295 * be used with the FCF vlan_id will be set to 0xFFFF;
1298 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1299 struct fcf_record *new_fcf_record,
1300 uint32_t *boot_flag, uint32_t *addr_mode,
1303 struct lpfc_fcf_conn_entry *conn_entry;
1304 int i, j, fcf_vlan_id = 0;
1306 /* Find the lowest VLAN id in the FCF record */
1307 for (i = 0; i < 512; i++) {
1308 if (new_fcf_record->vlan_bitmap[i]) {
1309 fcf_vlan_id = i * 8;
1311 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1319 /* If FCF not available return 0 */
1320 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1321 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
1324 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1326 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1328 if (phba->valid_vlan)
1329 *vlan_id = phba->vlan_id;
1336 * If there are no FCF connection table entry, driver connect to all
1339 if (list_empty(&phba->fcf_conn_rec_list)) {
1341 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1345 * When there are no FCF connect entries, use driver's default
1346 * addressing mode - FPMA.
1348 if (*addr_mode & LPFC_FCF_FPMA)
1349 *addr_mode = LPFC_FCF_FPMA;
1351 /* If FCF record report a vlan id use that vlan id */
1353 *vlan_id = fcf_vlan_id;
1359 list_for_each_entry(conn_entry,
1360 &phba->fcf_conn_rec_list, list) {
1361 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1364 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1365 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1368 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1369 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1372 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1374 * If the vlan bit map does not have the bit set for the
1375 * vlan id to be used, then it is not a match.
1377 if (!(new_fcf_record->vlan_bitmap
1378 [conn_entry->conn_rec.vlan_tag / 8] &
1379 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1384 * If connection record does not support any addressing mode,
1385 * skip the FCF record.
1387 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1388 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1392 * Check if the connection record specifies a required
1395 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1396 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1399 * If SPMA required but FCF not support this continue.
1401 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1402 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1403 new_fcf_record) & LPFC_FCF_SPMA))
1407 * If FPMA required but FCF not support this continue.
1409 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1410 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1411 new_fcf_record) & LPFC_FCF_FPMA))
1416 * This fcf record matches filtering criteria.
1418 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1424 * If user did not specify any addressing mode, or if the
1425 * prefered addressing mode specified by user is not supported
1426 * by FCF, allow fabric to pick the addressing mode.
1428 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1431 * If the user specified a required address mode, assign that
1434 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1435 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1436 *addr_mode = (conn_entry->conn_rec.flags &
1438 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1440 * If the user specified a prefered address mode, use the
1441 * addr mode only if FCF support the addr_mode.
1443 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1444 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1445 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1446 (*addr_mode & LPFC_FCF_SPMA))
1447 *addr_mode = LPFC_FCF_SPMA;
1448 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1449 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1450 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1451 (*addr_mode & LPFC_FCF_FPMA))
1452 *addr_mode = LPFC_FCF_FPMA;
1454 /* If matching connect list has a vlan id, use it */
1455 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1456 *vlan_id = conn_entry->conn_rec.vlan_tag;
1458 * If no vlan id is specified in connect list, use the vlan id
1461 else if (fcf_vlan_id)
1462 *vlan_id = fcf_vlan_id;
1473 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1474 * @phba: pointer to lpfc hba data structure.
1475 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1477 * This function check if there is any fcoe event pending while driver
1478 * scan FCF entries. If there is any pending event, it will restart the
1479 * FCF saning and return 1 else return 0.
1482 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1487 * If the Link is up and no FCoE events while in the
1488 * FCF discovery, no need to restart FCF discovery.
1490 if ((phba->link_state >= LPFC_LINK_UP) &&
1491 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1494 spin_lock_irq(&phba->hbalock);
1495 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1496 spin_unlock_irq(&phba->hbalock);
1498 if (phba->link_state >= LPFC_LINK_UP)
1499 lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
1502 * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS
1505 spin_lock_irq(&phba->hbalock);
1506 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1507 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1508 spin_unlock_irq(&phba->hbalock);
1512 spin_lock_irq(&phba->hbalock);
1513 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1514 spin_unlock_irq(&phba->hbalock);
1515 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1517 lpfc_printf_log(phba, KERN_ERR,
1518 LOG_DISCOVERY|LOG_MBOX,
1519 "2610 UNREG_FCFI mbox allocation failed\n");
1522 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
1523 mbox->vport = phba->pport;
1524 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
1525 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
1526 if (rc == MBX_NOT_FINISHED) {
1527 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
1528 "2611 UNREG_FCFI issue mbox failed\n");
1529 mempool_free(mbox, phba->mbox_mem_pool);
1537 * lpfc_mbx_cmpl_read_fcf_record - Completion handler for read_fcf mbox.
1538 * @phba: pointer to lpfc hba data structure.
1539 * @mboxq: pointer to mailbox object.
1541 * This function iterate through all the fcf records available in
1542 * HBA and choose the optimal FCF record for discovery. After finding
1543 * the FCF for discovery it register the FCF record and kick start
1545 * If FCF_IN_USE flag is set in currently used FCF, the routine try to
1546 * use a FCF record which match fabric name and mac address of the
1547 * currently used FCF record.
1548 * If the driver support only one FCF, it will try to use the FCF record
1549 * used by BOOT_BIOS.
1552 lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1555 dma_addr_t phys_addr;
1557 struct lpfc_mbx_sge sge;
1558 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1559 uint32_t shdr_status, shdr_add_status;
1560 union lpfc_sli4_cfg_shdr *shdr;
1561 struct fcf_record *new_fcf_record;
1562 uint32_t boot_flag, addr_mode;
1563 uint32_t next_fcf_index;
1564 struct lpfc_fcf_rec *fcf_rec = NULL;
1565 unsigned long iflags;
1569 /* If there is pending FCoE event restart FCF table scan */
1570 if (lpfc_check_pending_fcoe_event(phba, 0)) {
1571 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1575 /* Get the first SGE entry from the non-embedded DMA memory. This
1576 * routine only uses a single SGE.
1578 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1579 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1580 if (unlikely(!mboxq->sge_array)) {
1581 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1582 "2524 Failed to get the non-embedded SGE "
1583 "virtual address\n");
1586 virt_addr = mboxq->sge_array->addr[0];
1588 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1589 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1590 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
1593 * The FCF Record was read and there is no reason for the driver
1594 * to maintain the FCF record data or memory. Instead, just need
1595 * to book keeping the FCFIs can be used.
1597 if (shdr_status || shdr_add_status) {
1598 if (shdr_status == STATUS_FCF_TABLE_EMPTY) {
1599 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1600 "2726 READ_FCF_RECORD Indicates empty "
1603 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1604 "2521 READ_FCF_RECORD mailbox failed "
1605 "with status x%x add_status x%x, mbx\n",
1606 shdr_status, shdr_add_status);
1610 /* Interpreting the returned information of FCF records */
1611 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1612 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1613 sizeof(struct lpfc_mbx_read_fcf_tbl));
1614 next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1616 new_fcf_record = (struct fcf_record *)(virt_addr +
1617 sizeof(struct lpfc_mbx_read_fcf_tbl));
1618 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1619 sizeof(struct fcf_record));
1620 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
1622 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
1623 &addr_mode, &vlan_id);
1625 * If the fcf record does not match with connect list entries
1626 * read the next entry.
1631 * If this is not the first FCF discovery of the HBA, use last
1632 * FCF record for the discovery. The condition that a rescan
1633 * matches the in-use FCF record: fabric name, switch name, mac
1634 * address, and vlan_id.
1636 spin_lock_irqsave(&phba->hbalock, iflags);
1637 if (phba->fcf.fcf_flag & FCF_IN_USE) {
1638 if (lpfc_fab_name_match(phba->fcf.current_rec.fabric_name,
1640 lpfc_sw_name_match(phba->fcf.current_rec.switch_name,
1642 lpfc_mac_addr_match(phba->fcf.current_rec.mac_addr,
1644 lpfc_vlan_id_match(phba->fcf.current_rec.vlan_id,
1646 phba->fcf.fcf_flag |= FCF_AVAILABLE;
1647 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
1648 /* Stop FCF redisc wait timer if pending */
1649 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba);
1650 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
1651 /* If in fast failover, mark it's completed */
1652 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1653 spin_unlock_irqrestore(&phba->hbalock, iflags);
1657 * Read next FCF record from HBA searching for the matching
1658 * with in-use record only if not during the fast failover
1659 * period. In case of fast failover period, it shall try to
1660 * determine whether the FCF record just read should be the
1663 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
1664 spin_unlock_irqrestore(&phba->hbalock, iflags);
1669 * Update on failover FCF record only if it's in FCF fast-failover
1670 * period; otherwise, update on current FCF record.
1672 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
1673 /* Fast FCF failover only to the same fabric name */
1674 if (lpfc_fab_name_match(phba->fcf.current_rec.fabric_name,
1676 fcf_rec = &phba->fcf.failover_rec;
1680 fcf_rec = &phba->fcf.current_rec;
1682 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
1684 * If the driver FCF record does not have boot flag
1685 * set and new hba fcf record has boot flag set, use
1686 * the new hba fcf record.
1688 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
1689 /* Choose this FCF record */
1690 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1691 addr_mode, vlan_id, BOOT_ENABLE);
1692 spin_unlock_irqrestore(&phba->hbalock, iflags);
1696 * If the driver FCF record has boot flag set and the
1697 * new hba FCF record does not have boot flag, read
1698 * the next FCF record.
1700 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
1701 spin_unlock_irqrestore(&phba->hbalock, iflags);
1705 * If the new hba FCF record has lower priority value
1706 * than the driver FCF record, use the new record.
1708 if (lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record) &&
1709 (new_fcf_record->fip_priority < fcf_rec->priority)) {
1710 /* Choose this FCF record */
1711 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1712 addr_mode, vlan_id, 0);
1714 spin_unlock_irqrestore(&phba->hbalock, iflags);
1718 * This is the first suitable FCF record, choose this record for
1719 * initial best-fit FCF.
1722 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1723 addr_mode, vlan_id, (boot_flag ?
1725 phba->fcf.fcf_flag |= FCF_AVAILABLE;
1727 spin_unlock_irqrestore(&phba->hbalock, iflags);
1731 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1732 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
1733 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
1735 * Case of FCF fast failover scan
1739 * It has not found any suitable FCF record, cancel
1740 * FCF scan inprogress, and do nothing
1742 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
1743 spin_lock_irqsave(&phba->hbalock, iflags);
1744 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1745 spin_unlock_irqrestore(&phba->hbalock, iflags);
1749 * It has found a suitable FCF record that is not
1750 * the same as in-use FCF record, unregister the
1751 * in-use FCF record, replace the in-use FCF record
1752 * with the new FCF record, mark FCF fast failover
1753 * completed, and then start register the new FCF
1757 /* unregister the current in-use FCF record */
1758 lpfc_unregister_fcf(phba);
1759 /* replace in-use record with the new record */
1760 memcpy(&phba->fcf.current_rec,
1761 &phba->fcf.failover_rec,
1762 sizeof(struct lpfc_fcf_rec));
1763 /* mark the FCF fast failover completed */
1764 spin_lock_irqsave(&phba->hbalock, iflags);
1765 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1766 spin_unlock_irqrestore(&phba->hbalock, iflags);
1767 /* Register to the new FCF record */
1768 lpfc_register_fcf(phba);
1771 * In case of transaction period to fast FCF failover,
1772 * do nothing when search to the end of the FCF table.
1774 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
1775 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
1778 * Otherwise, initial scan or post linkdown rescan,
1779 * register with the best fit FCF record found so
1780 * far through the scanning process.
1782 lpfc_register_fcf(phba);
1785 lpfc_sli4_read_fcf_record(phba, next_fcf_index);
1789 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1790 lpfc_register_fcf(phba);
1796 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
1797 * @phba: pointer to lpfc hba data structure.
1798 * @mboxq: pointer to mailbox data structure.
1800 * This function handles completion of init vpi mailbox command.
1803 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1805 struct lpfc_vport *vport = mboxq->vport;
1806 struct lpfc_nodelist *ndlp;
1807 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1809 if (mboxq->u.mb.mbxStatus) {
1810 lpfc_printf_vlog(vport, KERN_ERR,
1812 "2609 Init VPI mailbox failed 0x%x\n",
1813 mboxq->u.mb.mbxStatus);
1814 mempool_free(mboxq, phba->mbox_mem_pool);
1815 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1818 spin_lock_irq(shost->host_lock);
1819 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
1820 spin_unlock_irq(shost->host_lock);
1822 /* If this port is physical port or FDISC is done, do reg_vpi */
1823 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
1824 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1826 lpfc_printf_vlog(vport, KERN_ERR,
1828 "2731 Cannot find fabric "
1829 "controller node\n");
1831 lpfc_register_new_vport(phba, vport, ndlp);
1832 mempool_free(mboxq, phba->mbox_mem_pool);
1836 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
1837 lpfc_initial_fdisc(vport);
1839 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
1840 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1841 "2606 No NPIV Fabric support\n");
1843 mempool_free(mboxq, phba->mbox_mem_pool);
1848 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
1849 * @vport: pointer to lpfc_vport data structure.
1851 * This function issue a init_vpi mailbox command to initialize
1852 * VPI for the vport.
1855 lpfc_issue_init_vpi(struct lpfc_vport *vport)
1857 LPFC_MBOXQ_t *mboxq;
1860 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
1862 lpfc_printf_vlog(vport, KERN_ERR,
1863 LOG_MBOX, "2607 Failed to allocate "
1864 "init_vpi mailbox\n");
1867 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
1868 mboxq->vport = vport;
1869 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
1870 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
1871 if (rc == MBX_NOT_FINISHED) {
1872 lpfc_printf_vlog(vport, KERN_ERR,
1873 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
1874 mempool_free(mboxq, vport->phba->mbox_mem_pool);
1879 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
1880 * @phba: pointer to lpfc hba data structure.
1882 * This function loops through the list of vports on the @phba and issues an
1883 * FDISC if possible.
1886 lpfc_start_fdiscs(struct lpfc_hba *phba)
1888 struct lpfc_vport **vports;
1891 vports = lpfc_create_vport_work_array(phba);
1892 if (vports != NULL) {
1893 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1894 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
1896 /* There are no vpi for this vport */
1897 if (vports[i]->vpi > phba->max_vpi) {
1898 lpfc_vport_set_state(vports[i],
1902 if (phba->fc_topology == TOPOLOGY_LOOP) {
1903 lpfc_vport_set_state(vports[i],
1907 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
1908 lpfc_issue_init_vpi(vports[i]);
1911 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
1912 lpfc_initial_fdisc(vports[i]);
1914 lpfc_vport_set_state(vports[i],
1915 FC_VPORT_NO_FABRIC_SUPP);
1916 lpfc_printf_vlog(vports[i], KERN_ERR,
1919 "Fabric support\n");
1923 lpfc_destroy_vport_work_array(phba, vports);
1927 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1929 struct lpfc_dmabuf *dmabuf = mboxq->context1;
1930 struct lpfc_vport *vport = mboxq->vport;
1931 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1933 if (mboxq->u.mb.mbxStatus) {
1934 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1935 "2018 REG_VFI mbxStatus error x%x "
1937 mboxq->u.mb.mbxStatus, vport->port_state);
1938 if (phba->fc_topology == TOPOLOGY_LOOP) {
1939 /* FLOGI failed, use loop map to make discovery list */
1940 lpfc_disc_list_loopmap(vport);
1941 /* Start discovery */
1942 lpfc_disc_start(vport);
1945 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1948 /* The VPI is implicitly registered when the VFI is registered */
1949 spin_lock_irq(shost->host_lock);
1950 vport->vpi_state |= LPFC_VPI_REGISTERED;
1951 vport->fc_flag |= FC_VFI_REGISTERED;
1952 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
1953 spin_unlock_irq(shost->host_lock);
1955 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
1956 lpfc_start_fdiscs(phba);
1957 lpfc_do_scr_ns_plogi(phba, vport);
1961 mempool_free(mboxq, phba->mbox_mem_pool);
1962 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
1968 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1970 MAILBOX_t *mb = &pmb->u.mb;
1971 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
1972 struct lpfc_vport *vport = pmb->vport;
1975 /* Check for error */
1976 if (mb->mbxStatus) {
1977 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
1978 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1979 "0319 READ_SPARAM mbxStatus error x%x "
1981 mb->mbxStatus, vport->port_state);
1982 lpfc_linkdown(phba);
1986 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
1987 sizeof (struct serv_parm));
1988 if (phba->cfg_soft_wwnn)
1989 u64_to_wwn(phba->cfg_soft_wwnn,
1990 vport->fc_sparam.nodeName.u.wwn);
1991 if (phba->cfg_soft_wwpn)
1992 u64_to_wwn(phba->cfg_soft_wwpn,
1993 vport->fc_sparam.portName.u.wwn);
1994 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
1995 sizeof(vport->fc_nodename));
1996 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
1997 sizeof(vport->fc_portname));
1998 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1999 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
2000 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
2003 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2005 mempool_free(pmb, phba->mbox_mem_pool);
2009 pmb->context1 = NULL;
2010 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2012 lpfc_issue_clear_la(phba, vport);
2013 mempool_free(pmb, phba->mbox_mem_pool);
2018 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
2020 struct lpfc_vport *vport = phba->pport;
2021 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
2023 struct lpfc_dmabuf *mp;
2025 struct fcf_record *fcf_record;
2027 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2029 spin_lock_irq(&phba->hbalock);
2030 switch (la->UlnkSpeed) {
2032 phba->fc_linkspeed = LA_1GHZ_LINK;
2035 phba->fc_linkspeed = LA_2GHZ_LINK;
2038 phba->fc_linkspeed = LA_4GHZ_LINK;
2041 phba->fc_linkspeed = LA_8GHZ_LINK;
2044 phba->fc_linkspeed = LA_10GHZ_LINK;
2047 phba->fc_linkspeed = LA_UNKNW_LINK;
2051 phba->fc_topology = la->topology;
2052 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
2054 if (phba->fc_topology == TOPOLOGY_LOOP) {
2055 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
2057 /* if npiv is enabled and this adapter supports npiv log
2058 * a message that npiv is not supported in this topology
2060 if (phba->cfg_enable_npiv && phba->max_vpi)
2061 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2062 "1309 Link Up Event npiv not supported in loop "
2064 /* Get Loop Map information */
2066 vport->fc_flag |= FC_LBIT;
2068 vport->fc_myDID = la->granted_AL_PA;
2069 i = la->un.lilpBde64.tus.f.bdeSize;
2072 phba->alpa_map[0] = 0;
2074 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
2085 numalpa = phba->alpa_map[0];
2087 while (j < numalpa) {
2088 memset(un.pamap, 0, 16);
2089 for (k = 1; j < numalpa; k++) {
2091 phba->alpa_map[j + 1];
2096 /* Link Up Event ALPA map */
2097 lpfc_printf_log(phba,
2100 "1304 Link Up Event "
2101 "ALPA map Data: x%x "
2103 un.pa.wd1, un.pa.wd2,
2104 un.pa.wd3, un.pa.wd4);
2109 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
2110 if (phba->max_vpi && phba->cfg_enable_npiv &&
2111 (phba->sli_rev == 3))
2112 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
2114 vport->fc_myDID = phba->fc_pref_DID;
2115 vport->fc_flag |= FC_LBIT;
2117 spin_unlock_irq(&phba->hbalock);
2121 lpfc_read_sparam(phba, sparam_mbox, 0);
2122 sparam_mbox->vport = vport;
2123 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
2124 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
2125 if (rc == MBX_NOT_FINISHED) {
2126 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
2127 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2129 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2134 if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) {
2135 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2138 vport->port_state = LPFC_LOCAL_CFG_LINK;
2139 lpfc_config_link(phba, cfglink_mbox);
2140 cfglink_mbox->vport = vport;
2141 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
2142 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
2143 if (rc == MBX_NOT_FINISHED) {
2144 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
2148 vport->port_state = LPFC_VPORT_UNKNOWN;
2150 * Add the driver's default FCF record at FCF index 0 now. This
2151 * is phase 1 implementation that support FCF index 0 and driver
2154 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
2155 fcf_record = kzalloc(sizeof(struct fcf_record),
2157 if (unlikely(!fcf_record)) {
2158 lpfc_printf_log(phba, KERN_ERR,
2160 "2554 Could not allocate memmory for "
2166 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
2167 LPFC_FCOE_FCF_DEF_INDEX);
2168 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
2170 lpfc_printf_log(phba, KERN_ERR,
2172 "2013 Could not manually add FCF "
2173 "record 0, status %d\n", rc);
2181 * The driver is expected to do FIP/FCF. Call the port
2182 * and get the FCF Table.
2184 spin_lock_irq(&phba->hbalock);
2185 if (phba->hba_flag & FCF_DISC_INPROGRESS) {
2186 spin_unlock_irq(&phba->hbalock);
2189 spin_unlock_irq(&phba->hbalock);
2190 rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
2197 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2198 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2199 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2200 vport->port_state, sparam_mbox, cfglink_mbox);
2201 lpfc_issue_clear_la(phba, vport);
2206 lpfc_enable_la(struct lpfc_hba *phba)
2209 struct lpfc_sli *psli = &phba->sli;
2210 spin_lock_irq(&phba->hbalock);
2211 psli->sli_flag |= LPFC_PROCESS_LA;
2212 if (phba->sli_rev <= LPFC_SLI_REV3) {
2213 control = readl(phba->HCregaddr);
2214 control |= HC_LAINT_ENA;
2215 writel(control, phba->HCregaddr);
2216 readl(phba->HCregaddr); /* flush */
2218 spin_unlock_irq(&phba->hbalock);
2222 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
2224 lpfc_linkdown(phba);
2225 lpfc_enable_la(phba);
2226 lpfc_unregister_unused_fcf(phba);
2227 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2232 * This routine handles processing a READ_LA mailbox
2233 * command upon completion. It is setup in the LPFC_MBOXQ
2234 * as the completion routine when the command is
2235 * handed off to the SLI layer.
2238 lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2240 struct lpfc_vport *vport = pmb->vport;
2241 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2243 MAILBOX_t *mb = &pmb->u.mb;
2244 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2246 /* Unblock ELS traffic */
2247 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2248 /* Check for error */
2249 if (mb->mbxStatus) {
2250 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
2251 "1307 READ_LA mbox error x%x state x%x\n",
2252 mb->mbxStatus, vport->port_state);
2253 lpfc_mbx_issue_link_down(phba);
2254 phba->link_state = LPFC_HBA_ERROR;
2255 goto lpfc_mbx_cmpl_read_la_free_mbuf;
2258 la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
2260 memcpy(&phba->alpa_map[0], mp->virt, 128);
2262 spin_lock_irq(shost->host_lock);
2264 vport->fc_flag |= FC_BYPASSED_MODE;
2266 vport->fc_flag &= ~FC_BYPASSED_MODE;
2267 spin_unlock_irq(shost->host_lock);
2269 if ((phba->fc_eventTag < la->eventTag) ||
2270 (phba->fc_eventTag == la->eventTag)) {
2271 phba->fc_stat.LinkMultiEvent++;
2272 if (la->attType == AT_LINK_UP)
2273 if (phba->fc_eventTag != 0)
2274 lpfc_linkdown(phba);
2277 phba->fc_eventTag = la->eventTag;
2278 spin_lock_irq(&phba->hbalock);
2280 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
2282 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
2283 spin_unlock_irq(&phba->hbalock);
2285 phba->link_events++;
2286 if (la->attType == AT_LINK_UP && (!la->mm)) {
2287 phba->fc_stat.LinkUp++;
2288 if (phba->link_flag & LS_LOOPBACK_MODE) {
2289 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2290 "1306 Link Up Event in loop back mode "
2291 "x%x received Data: x%x x%x x%x x%x\n",
2292 la->eventTag, phba->fc_eventTag,
2293 la->granted_AL_PA, la->UlnkSpeed,
2296 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2297 "1303 Link Up Event x%x received "
2298 "Data: x%x x%x x%x x%x x%x x%x %d\n",
2299 la->eventTag, phba->fc_eventTag,
2300 la->granted_AL_PA, la->UlnkSpeed,
2303 phba->wait_4_mlo_maint_flg);
2305 lpfc_mbx_process_link_up(phba, la);
2306 } else if (la->attType == AT_LINK_DOWN) {
2307 phba->fc_stat.LinkDown++;
2308 if (phba->link_flag & LS_LOOPBACK_MODE) {
2309 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2310 "1308 Link Down Event in loop back mode "
2312 "Data: x%x x%x x%x\n",
2313 la->eventTag, phba->fc_eventTag,
2314 phba->pport->port_state, vport->fc_flag);
2317 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2318 "1305 Link Down Event x%x received "
2319 "Data: x%x x%x x%x x%x x%x\n",
2320 la->eventTag, phba->fc_eventTag,
2321 phba->pport->port_state, vport->fc_flag,
2324 lpfc_mbx_issue_link_down(phba);
2326 if (la->mm && la->attType == AT_LINK_UP) {
2327 if (phba->link_state != LPFC_LINK_DOWN) {
2328 phba->fc_stat.LinkDown++;
2329 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2330 "1312 Link Down Event x%x received "
2331 "Data: x%x x%x x%x\n",
2332 la->eventTag, phba->fc_eventTag,
2333 phba->pport->port_state, vport->fc_flag);
2334 lpfc_mbx_issue_link_down(phba);
2336 lpfc_enable_la(phba);
2338 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2339 "1310 Menlo Maint Mode Link up Event x%x rcvd "
2340 "Data: x%x x%x x%x\n",
2341 la->eventTag, phba->fc_eventTag,
2342 phba->pport->port_state, vport->fc_flag);
2344 * The cmnd that triggered this will be waiting for this
2347 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
2348 if (phba->wait_4_mlo_maint_flg) {
2349 phba->wait_4_mlo_maint_flg = 0;
2350 wake_up_interruptible(&phba->wait_4_mlo_m_q);
2356 lpfc_issue_clear_la(phba, vport);
2357 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
2358 "1311 fa %d\n", la->fa);
2361 lpfc_mbx_cmpl_read_la_free_mbuf:
2362 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2364 mempool_free(pmb, phba->mbox_mem_pool);
2369 * This routine handles processing a REG_LOGIN mailbox
2370 * command upon completion. It is setup in the LPFC_MBOXQ
2371 * as the completion routine when the command is
2372 * handed off to the SLI layer.
2375 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2377 struct lpfc_vport *vport = pmb->vport;
2378 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2379 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2381 pmb->context1 = NULL;
2383 /* Good status, call state machine */
2384 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
2385 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2387 mempool_free(pmb, phba->mbox_mem_pool);
2388 /* decrement the node reference count held for this callback
2397 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2399 MAILBOX_t *mb = &pmb->u.mb;
2400 struct lpfc_vport *vport = pmb->vport;
2401 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2403 switch (mb->mbxStatus) {
2407 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2408 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
2412 spin_lock_irq(shost->host_lock);
2413 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
2414 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
2415 spin_unlock_irq(shost->host_lock);
2416 vport->unreg_vpi_cmpl = VPORT_OK;
2417 mempool_free(pmb, phba->mbox_mem_pool);
2419 * This shost reference might have been taken at the beginning of
2420 * lpfc_vport_delete()
2422 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
2423 scsi_host_put(shost);
2427 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
2429 struct lpfc_hba *phba = vport->phba;
2433 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2437 lpfc_unreg_vpi(phba, vport->vpi, mbox);
2438 mbox->vport = vport;
2439 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
2440 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
2441 if (rc == MBX_NOT_FINISHED) {
2442 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
2443 "1800 Could not issue unreg_vpi\n");
2444 mempool_free(mbox, phba->mbox_mem_pool);
2445 vport->unreg_vpi_cmpl = VPORT_ERROR;
2452 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2454 struct lpfc_vport *vport = pmb->vport;
2455 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2456 MAILBOX_t *mb = &pmb->u.mb;
2458 switch (mb->mbxStatus) {
2462 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2463 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
2465 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2466 spin_lock_irq(shost->host_lock);
2467 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2468 spin_unlock_irq(shost->host_lock);
2469 vport->fc_myDID = 0;
2473 spin_lock_irq(shost->host_lock);
2474 vport->vpi_state |= LPFC_VPI_REGISTERED;
2475 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2476 spin_unlock_irq(shost->host_lock);
2477 vport->num_disc_nodes = 0;
2478 /* go thru NPR list and issue ELS PLOGIs */
2479 if (vport->fc_npr_cnt)
2480 lpfc_els_disc_plogi(vport);
2482 if (!vport->num_disc_nodes) {
2483 spin_lock_irq(shost->host_lock);
2484 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2485 spin_unlock_irq(shost->host_lock);
2486 lpfc_can_disctmo(vport);
2488 vport->port_state = LPFC_VPORT_READY;
2491 mempool_free(pmb, phba->mbox_mem_pool);
2496 * lpfc_create_static_vport - Read HBA config region to create static vports.
2497 * @phba: pointer to lpfc hba data structure.
2499 * This routine issue a DUMP mailbox command for config region 22 to get
2500 * the list of static vports to be created. The function create vports
2501 * based on the information returned from the HBA.
2504 lpfc_create_static_vport(struct lpfc_hba *phba)
2506 LPFC_MBOXQ_t *pmb = NULL;
2508 struct static_vport_info *vport_info;
2510 struct fc_vport_identifiers vport_id;
2511 struct fc_vport *new_fc_vport;
2512 struct Scsi_Host *shost;
2513 struct lpfc_vport *vport;
2514 uint16_t offset = 0;
2515 uint8_t *vport_buff;
2516 struct lpfc_dmabuf *mp;
2517 uint32_t byte_count = 0;
2519 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2521 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2522 "0542 lpfc_create_static_vport failed to"
2523 " allocate mailbox memory\n");
2529 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
2531 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2532 "0543 lpfc_create_static_vport failed to"
2533 " allocate vport_info\n");
2534 mempool_free(pmb, phba->mbox_mem_pool);
2538 vport_buff = (uint8_t *) vport_info;
2540 if (lpfc_dump_static_vport(phba, pmb, offset))
2543 pmb->vport = phba->pport;
2544 rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
2546 if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
2547 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2548 "0544 lpfc_create_static_vport failed to"
2549 " issue dump mailbox command ret 0x%x "
2555 if (phba->sli_rev == LPFC_SLI_REV4) {
2556 byte_count = pmb->u.mqe.un.mb_words[5];
2557 mp = (struct lpfc_dmabuf *) pmb->context2;
2558 if (byte_count > sizeof(struct static_vport_info) -
2560 byte_count = sizeof(struct static_vport_info)
2562 memcpy(vport_buff + offset, mp->virt, byte_count);
2563 offset += byte_count;
2565 if (mb->un.varDmp.word_cnt >
2566 sizeof(struct static_vport_info) - offset)
2567 mb->un.varDmp.word_cnt =
2568 sizeof(struct static_vport_info)
2570 byte_count = mb->un.varDmp.word_cnt;
2571 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
2572 vport_buff + offset,
2575 offset += byte_count;
2578 } while (byte_count &&
2579 offset < sizeof(struct static_vport_info));
2582 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
2583 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
2584 != VPORT_INFO_REV)) {
2585 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2586 "0545 lpfc_create_static_vport bad"
2587 " information header 0x%x 0x%x\n",
2588 le32_to_cpu(vport_info->signature),
2589 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
2594 shost = lpfc_shost_from_vport(phba->pport);
2596 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
2597 memset(&vport_id, 0, sizeof(vport_id));
2598 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
2599 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
2600 if (!vport_id.port_name || !vport_id.node_name)
2603 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
2604 vport_id.vport_type = FC_PORTTYPE_NPIV;
2605 vport_id.disable = false;
2606 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
2608 if (!new_fc_vport) {
2609 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2610 "0546 lpfc_create_static_vport failed to"
2615 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
2616 vport->vport_flag |= STATIC_VPORT;
2621 if (rc != MBX_TIMEOUT) {
2622 if (pmb->context2) {
2623 mp = (struct lpfc_dmabuf *) pmb->context2;
2624 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2627 mempool_free(pmb, phba->mbox_mem_pool);
2634 * This routine handles processing a Fabric REG_LOGIN mailbox
2635 * command upon completion. It is setup in the LPFC_MBOXQ
2636 * as the completion routine when the command is
2637 * handed off to the SLI layer.
2640 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2642 struct lpfc_vport *vport = pmb->vport;
2643 MAILBOX_t *mb = &pmb->u.mb;
2644 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2645 struct lpfc_nodelist *ndlp;
2647 ndlp = (struct lpfc_nodelist *) pmb->context2;
2648 pmb->context1 = NULL;
2649 pmb->context2 = NULL;
2650 if (mb->mbxStatus) {
2651 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2652 "0258 Register Fabric login error: 0x%x\n",
2654 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2656 mempool_free(pmb, phba->mbox_mem_pool);
2658 if (phba->fc_topology == TOPOLOGY_LOOP) {
2659 /* FLOGI failed, use loop map to make discovery list */
2660 lpfc_disc_list_loopmap(vport);
2662 /* Start discovery */
2663 lpfc_disc_start(vport);
2664 /* Decrement the reference count to ndlp after the
2665 * reference to the ndlp are done.
2671 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2672 /* Decrement the reference count to ndlp after the reference
2673 * to the ndlp are done.
2679 ndlp->nlp_rpi = mb->un.varWords[0];
2680 ndlp->nlp_flag |= NLP_RPI_VALID;
2681 ndlp->nlp_type |= NLP_FABRIC;
2682 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2684 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
2685 lpfc_start_fdiscs(phba);
2686 lpfc_do_scr_ns_plogi(phba, vport);
2689 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2691 mempool_free(pmb, phba->mbox_mem_pool);
2693 /* Drop the reference count from the mbox at the end after
2694 * all the current reference to the ndlp have been done.
2701 * This routine handles processing a NameServer REG_LOGIN mailbox
2702 * command upon completion. It is setup in the LPFC_MBOXQ
2703 * as the completion routine when the command is
2704 * handed off to the SLI layer.
2707 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2709 MAILBOX_t *mb = &pmb->u.mb;
2710 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2711 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2712 struct lpfc_vport *vport = pmb->vport;
2714 if (mb->mbxStatus) {
2716 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2717 "0260 Register NameServer error: 0x%x\n",
2719 /* decrement the node reference count held for this
2720 * callback function.
2723 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2725 mempool_free(pmb, phba->mbox_mem_pool);
2727 /* If no other thread is using the ndlp, free it */
2728 lpfc_nlp_not_used(ndlp);
2730 if (phba->fc_topology == TOPOLOGY_LOOP) {
2732 * RegLogin failed, use loop map to make discovery
2735 lpfc_disc_list_loopmap(vport);
2737 /* Start discovery */
2738 lpfc_disc_start(vport);
2741 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2745 pmb->context1 = NULL;
2747 ndlp->nlp_rpi = mb->un.varWords[0];
2748 ndlp->nlp_flag |= NLP_RPI_VALID;
2749 ndlp->nlp_type |= NLP_FABRIC;
2750 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2752 if (vport->port_state < LPFC_VPORT_READY) {
2753 /* Link up discovery requires Fabric registration. */
2754 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
2755 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
2756 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
2757 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
2758 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
2760 /* Issue SCR just before NameServer GID_FT Query */
2761 lpfc_issue_els_scr(vport, SCR_DID, 0);
2764 vport->fc_ns_retry = 0;
2765 /* Good status, issue CT Request to NameServer */
2766 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
2767 /* Cannot issue NameServer Query, so finish up discovery */
2771 /* decrement the node reference count held for this
2772 * callback function.
2775 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2777 mempool_free(pmb, phba->mbox_mem_pool);
2783 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
2785 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2786 struct fc_rport *rport;
2787 struct lpfc_rport_data *rdata;
2788 struct fc_rport_identifiers rport_ids;
2789 struct lpfc_hba *phba = vport->phba;
2791 /* Remote port has reappeared. Re-register w/ FC transport */
2792 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
2793 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
2794 rport_ids.port_id = ndlp->nlp_DID;
2795 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2798 * We leave our node pointer in rport->dd_data when we unregister a
2799 * FCP target port. But fc_remote_port_add zeros the space to which
2800 * rport->dd_data points. So, if we're reusing a previously
2801 * registered port, drop the reference that we took the last time we
2802 * registered the port.
2804 if (ndlp->rport && ndlp->rport->dd_data &&
2805 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
2808 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
2809 "rport add: did:x%x flg:x%x type x%x",
2810 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
2812 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
2813 if (!rport || !get_device(&rport->dev)) {
2814 dev_printk(KERN_WARNING, &phba->pcidev->dev,
2815 "Warning: fc_remote_port_add failed\n");
2819 /* initialize static port data */
2820 rport->maxframe_size = ndlp->nlp_maxframe;
2821 rport->supported_classes = ndlp->nlp_class_sup;
2822 rdata = rport->dd_data;
2823 rdata->pnode = lpfc_nlp_get(ndlp);
2825 if (ndlp->nlp_type & NLP_FCP_TARGET)
2826 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
2827 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
2828 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2831 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
2832 fc_remote_port_rolechg(rport, rport_ids.roles);
2834 if ((rport->scsi_target_id != -1) &&
2835 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
2836 ndlp->nlp_sid = rport->scsi_target_id;
2842 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
2844 struct fc_rport *rport = ndlp->rport;
2846 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
2847 "rport delete: did:x%x flg:x%x type x%x",
2848 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
2850 fc_remote_port_delete(rport);
2856 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
2858 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2860 spin_lock_irq(shost->host_lock);
2862 case NLP_STE_UNUSED_NODE:
2863 vport->fc_unused_cnt += count;
2865 case NLP_STE_PLOGI_ISSUE:
2866 vport->fc_plogi_cnt += count;
2868 case NLP_STE_ADISC_ISSUE:
2869 vport->fc_adisc_cnt += count;
2871 case NLP_STE_REG_LOGIN_ISSUE:
2872 vport->fc_reglogin_cnt += count;
2874 case NLP_STE_PRLI_ISSUE:
2875 vport->fc_prli_cnt += count;
2877 case NLP_STE_UNMAPPED_NODE:
2878 vport->fc_unmap_cnt += count;
2880 case NLP_STE_MAPPED_NODE:
2881 vport->fc_map_cnt += count;
2883 case NLP_STE_NPR_NODE:
2884 vport->fc_npr_cnt += count;
2887 spin_unlock_irq(shost->host_lock);
2891 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2892 int old_state, int new_state)
2894 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2896 if (new_state == NLP_STE_UNMAPPED_NODE) {
2897 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2898 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
2899 ndlp->nlp_type |= NLP_FC_NODE;
2901 if (new_state == NLP_STE_MAPPED_NODE)
2902 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
2903 if (new_state == NLP_STE_NPR_NODE)
2904 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
2906 /* Transport interface */
2907 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
2908 old_state == NLP_STE_UNMAPPED_NODE)) {
2909 vport->phba->nport_event_cnt++;
2910 lpfc_unregister_remote_port(ndlp);
2913 if (new_state == NLP_STE_MAPPED_NODE ||
2914 new_state == NLP_STE_UNMAPPED_NODE) {
2915 vport->phba->nport_event_cnt++;
2917 * Tell the fc transport about the port, if we haven't
2918 * already. If we have, and it's a scsi entity, be
2919 * sure to unblock any attached scsi devices
2921 lpfc_register_remote_port(vport, ndlp);
2923 if ((new_state == NLP_STE_MAPPED_NODE) &&
2924 (vport->stat_data_enabled)) {
2926 * A new target is discovered, if there is no buffer for
2927 * statistical data collection allocate buffer.
2929 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
2930 sizeof(struct lpfc_scsicmd_bkt),
2933 if (!ndlp->lat_data)
2934 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
2935 "0286 lpfc_nlp_state_cleanup failed to "
2936 "allocate statistical data buffer DID "
2937 "0x%x\n", ndlp->nlp_DID);
2940 * if we added to Mapped list, but the remote port
2941 * registration failed or assigned a target id outside
2942 * our presentable range - move the node to the
2945 if (new_state == NLP_STE_MAPPED_NODE &&
2947 ndlp->rport->scsi_target_id == -1 ||
2948 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
2949 spin_lock_irq(shost->host_lock);
2950 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
2951 spin_unlock_irq(shost->host_lock);
2952 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
2957 lpfc_nlp_state_name(char *buffer, size_t size, int state)
2959 static char *states[] = {
2960 [NLP_STE_UNUSED_NODE] = "UNUSED",
2961 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
2962 [NLP_STE_ADISC_ISSUE] = "ADISC",
2963 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
2964 [NLP_STE_PRLI_ISSUE] = "PRLI",
2965 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
2966 [NLP_STE_MAPPED_NODE] = "MAPPED",
2967 [NLP_STE_NPR_NODE] = "NPR",
2970 if (state < NLP_STE_MAX_STATE && states[state])
2971 strlcpy(buffer, states[state], size);
2973 snprintf(buffer, size, "unknown (%d)", state);
2978 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2981 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2982 int old_state = ndlp->nlp_state;
2983 char name1[16], name2[16];
2985 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2986 "0904 NPort state transition x%06x, %s -> %s\n",
2988 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
2989 lpfc_nlp_state_name(name2, sizeof(name2), state));
2991 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2992 "node statechg did:x%x old:%d ste:%d",
2993 ndlp->nlp_DID, old_state, state);
2995 if (old_state == NLP_STE_NPR_NODE &&
2996 state != NLP_STE_NPR_NODE)
2997 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2998 if (old_state == NLP_STE_UNMAPPED_NODE) {
2999 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
3000 ndlp->nlp_type &= ~NLP_FC_NODE;
3003 if (list_empty(&ndlp->nlp_listp)) {
3004 spin_lock_irq(shost->host_lock);
3005 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3006 spin_unlock_irq(shost->host_lock);
3007 } else if (old_state)
3008 lpfc_nlp_counters(vport, old_state, -1);
3010 ndlp->nlp_state = state;
3011 lpfc_nlp_counters(vport, state, 1);
3012 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
3016 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3020 if (list_empty(&ndlp->nlp_listp)) {
3021 spin_lock_irq(shost->host_lock);
3022 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3023 spin_unlock_irq(shost->host_lock);
3028 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3030 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3032 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3033 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
3034 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3035 spin_lock_irq(shost->host_lock);
3036 list_del_init(&ndlp->nlp_listp);
3037 spin_unlock_irq(shost->host_lock);
3038 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
3039 NLP_STE_UNUSED_NODE);
3043 lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3045 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3046 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
3047 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3048 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
3049 NLP_STE_UNUSED_NODE);
3052 * lpfc_initialize_node - Initialize all fields of node object
3053 * @vport: Pointer to Virtual Port object.
3054 * @ndlp: Pointer to FC node object.
3055 * @did: FC_ID of the node.
3057 * This function is always called when node object need to be initialized.
3058 * It initializes all the fields of the node object. Although the reference
3059 * to phba from @ndlp can be obtained indirectly through it's reference to
3060 * @vport, a direct reference to phba is taken here by @ndlp. This is due
3061 * to the life-span of the @ndlp might go beyond the existence of @vport as
3062 * the final release of ndlp is determined by its reference count. And, the
3063 * operation on @ndlp needs the reference to phba.
3066 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3069 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
3070 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
3071 init_timer(&ndlp->nlp_delayfunc);
3072 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
3073 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
3074 ndlp->nlp_DID = did;
3075 ndlp->vport = vport;
3076 ndlp->phba = vport->phba;
3077 ndlp->nlp_sid = NLP_NO_SID;
3078 kref_init(&ndlp->kref);
3079 NLP_INT_NODE_ACT(ndlp);
3080 atomic_set(&ndlp->cmd_pending, 0);
3081 ndlp->cmd_qdepth = LPFC_MAX_TGT_QDEPTH;
3084 struct lpfc_nodelist *
3085 lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3088 struct lpfc_hba *phba = vport->phba;
3090 unsigned long flags;
3095 spin_lock_irqsave(&phba->ndlp_lock, flags);
3096 /* The ndlp should not be in memory free mode */
3097 if (NLP_CHK_FREE_REQ(ndlp)) {
3098 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3099 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3100 "0277 lpfc_enable_node: ndlp:x%p "
3101 "usgmap:x%x refcnt:%d\n",
3102 (void *)ndlp, ndlp->nlp_usg_map,
3103 atomic_read(&ndlp->kref.refcount));
3106 /* The ndlp should not already be in active mode */
3107 if (NLP_CHK_NODE_ACT(ndlp)) {
3108 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3109 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3110 "0278 lpfc_enable_node: ndlp:x%p "
3111 "usgmap:x%x refcnt:%d\n",
3112 (void *)ndlp, ndlp->nlp_usg_map,
3113 atomic_read(&ndlp->kref.refcount));
3117 /* Keep the original DID */
3118 did = ndlp->nlp_DID;
3120 /* re-initialize ndlp except of ndlp linked list pointer */
3121 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
3122 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
3123 lpfc_initialize_node(vport, ndlp, did);
3125 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3127 if (state != NLP_STE_UNUSED_NODE)
3128 lpfc_nlp_set_state(vport, ndlp, state);
3130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3131 "node enable: did:x%x",
3132 ndlp->nlp_DID, 0, 0);
3137 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3140 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
3141 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
3142 * the ndlp from the vport. The ndlp marked as UNUSED on the list
3143 * until ALL other outstanding threads have completed. We check
3144 * that the ndlp not already in the UNUSED state before we proceed.
3146 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3148 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
3154 * Start / ReStart rescue timer for Discovery / RSCN handling
3157 lpfc_set_disctmo(struct lpfc_vport *vport)
3159 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3160 struct lpfc_hba *phba = vport->phba;
3163 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
3164 /* For FAN, timeout should be greater than edtov */
3165 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
3167 /* Normal discovery timeout should be > than ELS/CT timeout
3168 * FC spec states we need 3 * ratov for CT requests
3170 tmo = ((phba->fc_ratov * 3) + 3);
3174 if (!timer_pending(&vport->fc_disctmo)) {
3175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3176 "set disc timer: tmo:x%x state:x%x flg:x%x",
3177 tmo, vport->port_state, vport->fc_flag);
3180 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
3181 spin_lock_irq(shost->host_lock);
3182 vport->fc_flag |= FC_DISC_TMO;
3183 spin_unlock_irq(shost->host_lock);
3185 /* Start Discovery Timer state <hba_state> */
3186 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3187 "0247 Start Discovery Timer state x%x "
3188 "Data: x%x x%lx x%x x%x\n",
3189 vport->port_state, tmo,
3190 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
3191 vport->fc_adisc_cnt);
3197 * Cancel rescue timer for Discovery / RSCN handling
3200 lpfc_can_disctmo(struct lpfc_vport *vport)
3202 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3203 unsigned long iflags;
3205 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3206 "can disc timer: state:x%x rtry:x%x flg:x%x",
3207 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
3209 /* Turn off discovery timer if its running */
3210 if (vport->fc_flag & FC_DISC_TMO) {
3211 spin_lock_irqsave(shost->host_lock, iflags);
3212 vport->fc_flag &= ~FC_DISC_TMO;
3213 spin_unlock_irqrestore(shost->host_lock, iflags);
3214 del_timer_sync(&vport->fc_disctmo);
3215 spin_lock_irqsave(&vport->work_port_lock, iflags);
3216 vport->work_port_events &= ~WORKER_DISC_TMO;
3217 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
3220 /* Cancel Discovery Timer state <hba_state> */
3221 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3222 "0248 Cancel Discovery Timer state x%x "
3223 "Data: x%x x%x x%x\n",
3224 vport->port_state, vport->fc_flag,
3225 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
3230 * Check specified ring for outstanding IOCB on the SLI queue
3231 * Return true if iocb matches the specified nport
3234 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
3235 struct lpfc_sli_ring *pring,
3236 struct lpfc_iocbq *iocb,
3237 struct lpfc_nodelist *ndlp)
3239 struct lpfc_sli *psli = &phba->sli;
3240 IOCB_t *icmd = &iocb->iocb;
3241 struct lpfc_vport *vport = ndlp->vport;
3243 if (iocb->vport != vport)
3246 if (pring->ringno == LPFC_ELS_RING) {
3247 switch (icmd->ulpCommand) {
3248 case CMD_GEN_REQUEST64_CR:
3249 if (iocb->context_un.ndlp == ndlp)
3251 case CMD_ELS_REQUEST64_CR:
3252 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
3254 case CMD_XMIT_ELS_RSP64_CX:
3255 if (iocb->context1 == (uint8_t *) ndlp)
3258 } else if (pring->ringno == psli->extra_ring) {
3260 } else if (pring->ringno == psli->fcp_ring) {
3261 /* Skip match check if waiting to relogin to FCP target */
3262 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3263 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
3266 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
3269 } else if (pring->ringno == psli->next_ring) {
3276 * Free resources / clean up outstanding I/Os
3277 * associated with nlp_rpi in the LPFC_NODELIST entry.
3280 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
3282 LIST_HEAD(completions);
3283 struct lpfc_sli *psli;
3284 struct lpfc_sli_ring *pring;
3285 struct lpfc_iocbq *iocb, *next_iocb;
3288 lpfc_fabric_abort_nport(ndlp);
3291 * Everything that matches on txcmplq will be returned
3292 * by firmware with a no rpi error.
3295 if (ndlp->nlp_flag & NLP_RPI_VALID) {
3296 /* Now process each ring */
3297 for (i = 0; i < psli->num_rings; i++) {
3298 pring = &psli->ring[i];
3300 spin_lock_irq(&phba->hbalock);
3301 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
3304 * Check to see if iocb matches the nport we are
3307 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
3309 /* It matches, so deque and call compl
3311 list_move_tail(&iocb->list,
3316 spin_unlock_irq(&phba->hbalock);
3320 /* Cancel all the IOCBs from the completions list */
3321 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3328 * Free rpi associated with LPFC_NODELIST entry.
3329 * This routine is called from lpfc_freenode(), when we are removing
3330 * a LPFC_NODELIST entry. It is also called if the driver initiates a
3331 * LOGO that completes successfully, and we are waiting to PLOGI back
3332 * to the remote NPort. In addition, it is called after we receive
3333 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
3334 * we are waiting to PLOGI back to the remote NPort.
3337 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3339 struct lpfc_hba *phba = vport->phba;
3343 if (ndlp->nlp_flag & NLP_RPI_VALID) {
3344 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3346 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
3347 mbox->vport = vport;
3348 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3349 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3350 if (rc == MBX_NOT_FINISHED)
3351 mempool_free(mbox, phba->mbox_mem_pool);
3353 lpfc_no_rpi(phba, ndlp);
3355 ndlp->nlp_flag &= ~NLP_RPI_VALID;
3356 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
3363 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
3364 * @phba: pointer to lpfc hba data structure.
3366 * This routine is invoked to unregister all the currently registered RPIs
3370 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
3372 struct lpfc_vport **vports;
3373 struct lpfc_nodelist *ndlp;
3374 struct Scsi_Host *shost;
3377 vports = lpfc_create_vport_work_array(phba);
3378 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3379 shost = lpfc_shost_from_vport(vports[i]);
3380 spin_lock_irq(shost->host_lock);
3381 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
3382 if (ndlp->nlp_flag & NLP_RPI_VALID)
3383 lpfc_unreg_rpi(vports[i], ndlp);
3385 spin_unlock_irq(shost->host_lock);
3387 lpfc_destroy_vport_work_array(phba, vports);
3391 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
3393 struct lpfc_hba *phba = vport->phba;
3397 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3399 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
3400 mbox->vport = vport;
3401 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3402 mbox->context1 = NULL;
3403 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
3404 if (rc != MBX_TIMEOUT)
3405 mempool_free(mbox, phba->mbox_mem_pool);
3407 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
3408 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3409 "1836 Could not issue "
3410 "unreg_login(all_rpis) status %d\n", rc);
3415 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
3417 struct lpfc_hba *phba = vport->phba;
3421 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3423 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
3424 mbox->vport = vport;
3425 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3426 mbox->context1 = NULL;
3427 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
3428 if (rc != MBX_TIMEOUT)
3429 mempool_free(mbox, phba->mbox_mem_pool);
3431 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
3432 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3433 "1815 Could not issue "
3434 "unreg_did (default rpis) status %d\n",
3440 * Free resources associated with LPFC_NODELIST entry
3441 * so it can be freed.
3444 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3447 struct lpfc_hba *phba = vport->phba;
3448 LPFC_MBOXQ_t *mb, *nextmb;
3449 struct lpfc_dmabuf *mp;
3451 /* Cleanup node for NPort <nlp_DID> */
3452 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3453 "0900 Cleanup node for NPort x%x "
3454 "Data: x%x x%x x%x\n",
3455 ndlp->nlp_DID, ndlp->nlp_flag,
3456 ndlp->nlp_state, ndlp->nlp_rpi);
3457 if (NLP_CHK_FREE_REQ(ndlp)) {
3458 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3459 "0280 lpfc_cleanup_node: ndlp:x%p "
3460 "usgmap:x%x refcnt:%d\n",
3461 (void *)ndlp, ndlp->nlp_usg_map,
3462 atomic_read(&ndlp->kref.refcount));
3463 lpfc_dequeue_node(vport, ndlp);
3465 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3466 "0281 lpfc_cleanup_node: ndlp:x%p "
3467 "usgmap:x%x refcnt:%d\n",
3468 (void *)ndlp, ndlp->nlp_usg_map,
3469 atomic_read(&ndlp->kref.refcount));
3470 lpfc_disable_node(vport, ndlp);
3473 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
3474 if ((mb = phba->sli.mbox_active)) {
3475 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
3476 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
3477 mb->context2 = NULL;
3478 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3482 spin_lock_irq(&phba->hbalock);
3483 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
3484 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
3485 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
3486 mp = (struct lpfc_dmabuf *) (mb->context1);
3488 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
3491 list_del(&mb->list);
3492 mempool_free(mb, phba->mbox_mem_pool);
3493 /* We shall not invoke the lpfc_nlp_put to decrement
3494 * the ndlp reference count as we are in the process
3495 * of lpfc_nlp_release.
3499 spin_unlock_irq(&phba->hbalock);
3501 lpfc_els_abort(phba, ndlp);
3503 spin_lock_irq(shost->host_lock);
3504 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3505 spin_unlock_irq(shost->host_lock);
3507 ndlp->nlp_last_elscmd = 0;
3508 del_timer_sync(&ndlp->nlp_delayfunc);
3510 list_del_init(&ndlp->els_retry_evt.evt_listp);
3511 list_del_init(&ndlp->dev_loss_evt.evt_listp);
3513 lpfc_unreg_rpi(vport, ndlp);
3519 * Check to see if we can free the nlp back to the freelist.
3520 * If we are in the middle of using the nlp in the discovery state
3521 * machine, defer the free till we reach the end of the state machine.
3524 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3526 struct lpfc_hba *phba = vport->phba;
3527 struct lpfc_rport_data *rdata;
3531 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3532 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
3533 !(ndlp->nlp_flag & NLP_RPI_VALID)) {
3534 /* For this case we need to cleanup the default rpi
3535 * allocated by the firmware.
3537 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
3539 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
3540 (uint8_t *) &vport->fc_sparam, mbox, 0);
3542 mempool_free(mbox, phba->mbox_mem_pool);
3545 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3546 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3547 mbox->vport = vport;
3548 mbox->context2 = NULL;
3549 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3550 if (rc == MBX_NOT_FINISHED) {
3551 mempool_free(mbox, phba->mbox_mem_pool);
3556 lpfc_cleanup_node(vport, ndlp);
3559 * We can get here with a non-NULL ndlp->rport because when we
3560 * unregister a rport we don't break the rport/node linkage. So if we
3561 * do, make sure we don't leaving any dangling pointers behind.
3564 rdata = ndlp->rport->dd_data;
3565 rdata->pnode = NULL;
3571 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3574 D_ID mydid, ndlpdid, matchdid;
3576 if (did == Bcast_DID)
3579 /* First check for Direct match */
3580 if (ndlp->nlp_DID == did)
3583 /* Next check for area/domain identically equals 0 match */
3584 mydid.un.word = vport->fc_myDID;
3585 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
3589 matchdid.un.word = did;
3590 ndlpdid.un.word = ndlp->nlp_DID;
3591 if (matchdid.un.b.id == ndlpdid.un.b.id) {
3592 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
3593 (mydid.un.b.area == matchdid.un.b.area)) {
3594 if ((ndlpdid.un.b.domain == 0) &&
3595 (ndlpdid.un.b.area == 0)) {
3596 if (ndlpdid.un.b.id)
3602 matchdid.un.word = ndlp->nlp_DID;
3603 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
3604 (mydid.un.b.area == ndlpdid.un.b.area)) {
3605 if ((matchdid.un.b.domain == 0) &&
3606 (matchdid.un.b.area == 0)) {
3607 if (matchdid.un.b.id)
3615 /* Search for a nodelist entry */
3616 static struct lpfc_nodelist *
3617 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
3619 struct lpfc_nodelist *ndlp;
3622 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
3623 if (lpfc_matchdid(vport, ndlp, did)) {
3624 data1 = (((uint32_t) ndlp->nlp_state << 24) |
3625 ((uint32_t) ndlp->nlp_xri << 16) |
3626 ((uint32_t) ndlp->nlp_type << 8) |
3627 ((uint32_t) ndlp->nlp_rpi & 0xff));
3628 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3629 "0929 FIND node DID "
3630 "Data: x%p x%x x%x x%x\n",
3631 ndlp, ndlp->nlp_DID,
3632 ndlp->nlp_flag, data1);
3637 /* FIND node did <did> NOT FOUND */
3638 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3639 "0932 FIND node did x%x NOT FOUND.\n", did);
3643 struct lpfc_nodelist *
3644 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
3646 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3647 struct lpfc_nodelist *ndlp;
3649 spin_lock_irq(shost->host_lock);
3650 ndlp = __lpfc_findnode_did(vport, did);
3651 spin_unlock_irq(shost->host_lock);
3655 struct lpfc_nodelist *
3656 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
3658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3659 struct lpfc_nodelist *ndlp;
3661 ndlp = lpfc_findnode_did(vport, did);
3663 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
3664 lpfc_rscn_payload_check(vport, did) == 0)
3666 ndlp = (struct lpfc_nodelist *)
3667 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
3670 lpfc_nlp_init(vport, ndlp, did);
3671 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3672 spin_lock_irq(shost->host_lock);
3673 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
3674 spin_unlock_irq(shost->host_lock);
3676 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3677 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
3680 spin_lock_irq(shost->host_lock);
3681 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
3682 spin_unlock_irq(shost->host_lock);
3686 if ((vport->fc_flag & FC_RSCN_MODE) &&
3687 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
3688 if (lpfc_rscn_payload_check(vport, did)) {
3689 /* If we've already recieved a PLOGI from this NPort
3690 * we don't need to try to discover it again.
3692 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
3695 /* Since this node is marked for discovery,
3696 * delay timeout is not needed.
3698 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3699 spin_lock_irq(shost->host_lock);
3700 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
3701 spin_unlock_irq(shost->host_lock);
3705 /* If we've already recieved a PLOGI from this NPort,
3706 * or we are already in the process of discovery on it,
3707 * we don't need to try to discover it again.
3709 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
3710 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
3711 ndlp->nlp_flag & NLP_RCV_PLOGI)
3713 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3714 spin_lock_irq(shost->host_lock);
3715 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
3716 spin_unlock_irq(shost->host_lock);
3721 /* Build a list of nodes to discover based on the loopmap */
3723 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
3725 struct lpfc_hba *phba = vport->phba;
3727 uint32_t alpa, index;
3729 if (!lpfc_is_link_up(phba))
3732 if (phba->fc_topology != TOPOLOGY_LOOP)
3735 /* Check for loop map present or not */
3736 if (phba->alpa_map[0]) {
3737 for (j = 1; j <= phba->alpa_map[0]; j++) {
3738 alpa = phba->alpa_map[j];
3739 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
3741 lpfc_setup_disc_node(vport, alpa);
3744 /* No alpamap, so try all alpa's */
3745 for (j = 0; j < FC_MAXLOOP; j++) {
3746 /* If cfg_scan_down is set, start from highest
3747 * ALPA (0xef) to lowest (0x1).
3749 if (vport->cfg_scan_down)
3752 index = FC_MAXLOOP - j - 1;
3753 alpa = lpfcAlpaArray[index];
3754 if ((vport->fc_myDID & 0xff) == alpa)
3756 lpfc_setup_disc_node(vport, alpa);
3763 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
3766 struct lpfc_sli *psli = &phba->sli;
3767 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
3768 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
3769 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
3773 * if it's not a physical port or if we already send
3774 * clear_la then don't send it.
3776 if ((phba->link_state >= LPFC_CLEAR_LA) ||
3777 (vport->port_type != LPFC_PHYSICAL_PORT) ||
3778 (phba->sli_rev == LPFC_SLI_REV4))
3781 /* Link up discovery */
3782 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
3783 phba->link_state = LPFC_CLEAR_LA;
3784 lpfc_clear_la(phba, mbox);
3785 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
3786 mbox->vport = vport;
3787 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3788 if (rc == MBX_NOT_FINISHED) {
3789 mempool_free(mbox, phba->mbox_mem_pool);
3790 lpfc_disc_flush_list(vport);
3791 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
3792 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
3793 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
3794 phba->link_state = LPFC_HBA_ERROR;
3799 /* Reg_vpi to tell firmware to resume normal operations */
3801 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
3803 LPFC_MBOXQ_t *regvpimbox;
3805 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3807 lpfc_reg_vpi(vport, regvpimbox);
3808 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
3809 regvpimbox->vport = vport;
3810 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
3811 == MBX_NOT_FINISHED) {
3812 mempool_free(regvpimbox, phba->mbox_mem_pool);
3817 /* Start Link up / RSCN discovery on NPR nodes */
3819 lpfc_disc_start(struct lpfc_vport *vport)
3821 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3822 struct lpfc_hba *phba = vport->phba;
3824 uint32_t clear_la_pending;
3827 if (!lpfc_is_link_up(phba))
3830 if (phba->link_state == LPFC_CLEAR_LA)
3831 clear_la_pending = 1;
3833 clear_la_pending = 0;
3835 if (vport->port_state < LPFC_VPORT_READY)
3836 vport->port_state = LPFC_DISC_AUTH;
3838 lpfc_set_disctmo(vport);
3840 if (vport->fc_prevDID == vport->fc_myDID)
3845 vport->fc_prevDID = vport->fc_myDID;
3846 vport->num_disc_nodes = 0;
3848 /* Start Discovery state <hba_state> */
3849 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3850 "0202 Start Discovery hba state x%x "
3851 "Data: x%x x%x x%x\n",
3852 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
3853 vport->fc_adisc_cnt);
3855 /* First do ADISCs - if any */
3856 num_sent = lpfc_els_disc_adisc(vport);
3862 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
3863 * continue discovery.
3865 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3866 !(vport->fc_flag & FC_PT2PT) &&
3867 !(vport->fc_flag & FC_RSCN_MODE) &&
3868 (phba->sli_rev < LPFC_SLI_REV4)) {
3869 lpfc_issue_reg_vpi(phba, vport);
3874 * For SLI2, we need to set port_state to READY and continue
3877 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
3878 /* If we get here, there is nothing to ADISC */
3879 if (vport->port_type == LPFC_PHYSICAL_PORT)
3880 lpfc_issue_clear_la(phba, vport);
3882 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
3883 vport->num_disc_nodes = 0;
3884 /* go thru NPR nodes and issue ELS PLOGIs */
3885 if (vport->fc_npr_cnt)
3886 lpfc_els_disc_plogi(vport);
3888 if (!vport->num_disc_nodes) {
3889 spin_lock_irq(shost->host_lock);
3890 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3891 spin_unlock_irq(shost->host_lock);
3892 lpfc_can_disctmo(vport);
3895 vport->port_state = LPFC_VPORT_READY;
3897 /* Next do PLOGIs - if any */
3898 num_sent = lpfc_els_disc_plogi(vport);
3903 if (vport->fc_flag & FC_RSCN_MODE) {
3904 /* Check to see if more RSCNs came in while we
3905 * were processing this one.
3907 if ((vport->fc_rscn_id_cnt == 0) &&
3908 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
3909 spin_lock_irq(shost->host_lock);
3910 vport->fc_flag &= ~FC_RSCN_MODE;
3911 spin_unlock_irq(shost->host_lock);
3912 lpfc_can_disctmo(vport);
3914 lpfc_els_handle_rscn(vport);
3921 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
3922 * ring the match the sppecified nodelist.
3925 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
3927 LIST_HEAD(completions);
3928 struct lpfc_sli *psli;
3930 struct lpfc_iocbq *iocb, *next_iocb;
3931 struct lpfc_sli_ring *pring;
3934 pring = &psli->ring[LPFC_ELS_RING];
3936 /* Error matching iocb on txq or txcmplq
3937 * First check the txq.
3939 spin_lock_irq(&phba->hbalock);
3940 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
3941 if (iocb->context1 != ndlp) {
3945 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
3946 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
3948 list_move_tail(&iocb->list, &completions);
3953 /* Next check the txcmplq */
3954 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
3955 if (iocb->context1 != ndlp) {
3959 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
3960 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
3961 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
3964 spin_unlock_irq(&phba->hbalock);
3966 /* Cancel all the IOCBs from the completions list */
3967 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3972 lpfc_disc_flush_list(struct lpfc_vport *vport)
3974 struct lpfc_nodelist *ndlp, *next_ndlp;
3975 struct lpfc_hba *phba = vport->phba;
3977 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
3978 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
3980 if (!NLP_CHK_NODE_ACT(ndlp))
3982 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
3983 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
3984 lpfc_free_tx(phba, ndlp);
3991 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
3993 lpfc_els_flush_rscn(vport);
3994 lpfc_els_flush_cmd(vport);
3995 lpfc_disc_flush_list(vport);
3998 /*****************************************************************************/
4000 * NAME: lpfc_disc_timeout
4002 * FUNCTION: Fibre Channel driver discovery timeout routine.
4004 * EXECUTION ENVIRONMENT: interrupt only
4012 /*****************************************************************************/
4014 lpfc_disc_timeout(unsigned long ptr)
4016 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4017 struct lpfc_hba *phba = vport->phba;
4018 uint32_t tmo_posted;
4019 unsigned long flags = 0;
4021 if (unlikely(!phba))
4024 spin_lock_irqsave(&vport->work_port_lock, flags);
4025 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
4027 vport->work_port_events |= WORKER_DISC_TMO;
4028 spin_unlock_irqrestore(&vport->work_port_lock, flags);
4031 lpfc_worker_wake_up(phba);
4036 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
4038 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4039 struct lpfc_hba *phba = vport->phba;
4040 struct lpfc_sli *psli = &phba->sli;
4041 struct lpfc_nodelist *ndlp, *next_ndlp;
4042 LPFC_MBOXQ_t *initlinkmbox;
4043 int rc, clrlaerr = 0;
4045 if (!(vport->fc_flag & FC_DISC_TMO))
4048 spin_lock_irq(shost->host_lock);
4049 vport->fc_flag &= ~FC_DISC_TMO;
4050 spin_unlock_irq(shost->host_lock);
4052 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4053 "disc timeout: state:x%x rtry:x%x flg:x%x",
4054 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4056 switch (vport->port_state) {
4058 case LPFC_LOCAL_CFG_LINK:
4059 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
4063 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
4064 "0221 FAN timeout\n");
4065 /* Start discovery by sending FLOGI, clean up old rpis */
4066 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
4068 if (!NLP_CHK_NODE_ACT(ndlp))
4070 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
4072 if (ndlp->nlp_type & NLP_FABRIC) {
4073 /* Clean up the ndlp on Fabric connections */
4074 lpfc_drop_node(vport, ndlp);
4076 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
4077 /* Fail outstanding IO now since device
4078 * is marked for PLOGI.
4080 lpfc_unreg_rpi(vport, ndlp);
4083 if (vport->port_state != LPFC_FLOGI) {
4084 lpfc_initial_flogi(vport);
4091 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
4092 /* Initial FLOGI timeout */
4093 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4094 "0222 Initial %s timeout\n",
4095 vport->vpi ? "FDISC" : "FLOGI");
4097 /* Assume no Fabric and go on with discovery.
4098 * Check for outstanding ELS FLOGI to abort.
4101 /* FLOGI failed, so just use loop map to make discovery list */
4102 lpfc_disc_list_loopmap(vport);
4104 /* Start discovery */
4105 lpfc_disc_start(vport);
4108 case LPFC_FABRIC_CFG_LINK:
4109 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
4111 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4112 "0223 Timeout while waiting for "
4113 "NameServer login\n");
4114 /* Next look for NameServer ndlp */
4115 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4116 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4117 lpfc_els_abort(phba, ndlp);
4119 /* ReStart discovery */
4123 /* Check for wait for NameServer Rsp timeout */
4124 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4125 "0224 NameServer Query timeout "
4127 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
4129 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
4130 /* Try it one more time */
4131 vport->fc_ns_retry++;
4132 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
4133 vport->fc_ns_retry, 0);
4137 vport->fc_ns_retry = 0;
4141 * Discovery is over.
4142 * set port_state to PORT_READY if SLI2.
4143 * cmpl_reg_vpi will set port_state to READY for SLI3.
4145 if (phba->sli_rev < LPFC_SLI_REV4) {
4146 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4147 lpfc_issue_reg_vpi(phba, vport);
4148 else { /* NPIV Not enabled */
4149 lpfc_issue_clear_la(phba, vport);
4150 vport->port_state = LPFC_VPORT_READY;
4154 /* Setup and issue mailbox INITIALIZE LINK command */
4155 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4156 if (!initlinkmbox) {
4157 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4158 "0206 Device Discovery "
4159 "completion error\n");
4160 phba->link_state = LPFC_HBA_ERROR;
4164 lpfc_linkdown(phba);
4165 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
4166 phba->cfg_link_speed);
4167 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4168 initlinkmbox->vport = vport;
4169 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4170 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
4171 lpfc_set_loopback_flag(phba);
4172 if (rc == MBX_NOT_FINISHED)
4173 mempool_free(initlinkmbox, phba->mbox_mem_pool);
4177 case LPFC_DISC_AUTH:
4178 /* Node Authentication timeout */
4179 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4180 "0227 Node Authentication timeout\n");
4181 lpfc_disc_flush_list(vport);
4184 * set port_state to PORT_READY if SLI2.
4185 * cmpl_reg_vpi will set port_state to READY for SLI3.
4187 if (phba->sli_rev < LPFC_SLI_REV4) {
4188 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4189 lpfc_issue_reg_vpi(phba, vport);
4190 else { /* NPIV Not enabled */
4191 lpfc_issue_clear_la(phba, vport);
4192 vport->port_state = LPFC_VPORT_READY;
4197 case LPFC_VPORT_READY:
4198 if (vport->fc_flag & FC_RSCN_MODE) {
4199 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4200 "0231 RSCN timeout Data: x%x "
4202 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
4204 /* Cleanup any outstanding ELS commands */
4205 lpfc_els_flush_cmd(vport);
4207 lpfc_els_flush_rscn(vport);
4208 lpfc_disc_flush_list(vport);
4213 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4214 "0273 Unexpected discovery timeout, "
4215 "vport State x%x\n", vport->port_state);
4219 switch (phba->link_state) {
4221 /* CLEAR LA timeout */
4222 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4223 "0228 CLEAR LA timeout\n");
4228 lpfc_issue_clear_la(phba, vport);
4230 case LPFC_LINK_UNKNOWN:
4231 case LPFC_WARM_START:
4232 case LPFC_INIT_START:
4233 case LPFC_INIT_MBX_CMDS:
4234 case LPFC_LINK_DOWN:
4235 case LPFC_HBA_ERROR:
4236 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4237 "0230 Unexpected timeout, hba link "
4238 "state x%x\n", phba->link_state);
4242 case LPFC_HBA_READY:
4247 lpfc_disc_flush_list(vport);
4248 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
4249 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
4250 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
4251 vport->port_state = LPFC_VPORT_READY;
4258 * This routine handles processing a NameServer REG_LOGIN mailbox
4259 * command upon completion. It is setup in the LPFC_MBOXQ
4260 * as the completion routine when the command is
4261 * handed off to the SLI layer.
4264 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4266 MAILBOX_t *mb = &pmb->u.mb;
4267 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
4268 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4269 struct lpfc_vport *vport = pmb->vport;
4271 pmb->context1 = NULL;
4273 ndlp->nlp_rpi = mb->un.varWords[0];
4274 ndlp->nlp_flag |= NLP_RPI_VALID;
4275 ndlp->nlp_type |= NLP_FABRIC;
4276 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4279 * Start issuing Fabric-Device Management Interface (FDMI) command to
4280 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
4281 * fdmi-on=2 (supporting RPA/hostnmae)
4284 if (vport->cfg_fdmi_on == 1)
4285 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
4287 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
4289 /* decrement the node reference count held for this callback
4293 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4295 mempool_free(pmb, phba->mbox_mem_pool);
4301 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
4303 uint16_t *rpi = param;
4305 return ndlp->nlp_rpi == *rpi;
4309 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
4311 return memcmp(&ndlp->nlp_portname, param,
4312 sizeof(ndlp->nlp_portname)) == 0;
4315 static struct lpfc_nodelist *
4316 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
4318 struct lpfc_nodelist *ndlp;
4320 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4321 if (filter(ndlp, param))
4328 * This routine looks up the ndlp lists for the given RPI. If rpi found it
4329 * returns the node list element pointer else return NULL.
4331 struct lpfc_nodelist *
4332 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
4334 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
4338 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
4339 * returns the node element list pointer else return NULL.
4341 struct lpfc_nodelist *
4342 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
4344 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4345 struct lpfc_nodelist *ndlp;
4347 spin_lock_irq(shost->host_lock);
4348 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
4349 spin_unlock_irq(shost->host_lock);
4354 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4357 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
4359 lpfc_initialize_node(vport, ndlp, did);
4360 INIT_LIST_HEAD(&ndlp->nlp_listp);
4362 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4363 "node init: did:x%x",
4364 ndlp->nlp_DID, 0, 0);
4369 /* This routine releases all resources associated with a specifc NPort's ndlp
4370 * and mempool_free's the nodelist.
4373 lpfc_nlp_release(struct kref *kref)
4375 struct lpfc_hba *phba;
4376 unsigned long flags;
4377 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
4380 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
4381 "node release: did:x%x flg:x%x type:x%x",
4382 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4384 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4385 "0279 lpfc_nlp_release: ndlp:x%p "
4386 "usgmap:x%x refcnt:%d\n",
4387 (void *)ndlp, ndlp->nlp_usg_map,
4388 atomic_read(&ndlp->kref.refcount));
4390 /* remove ndlp from action. */
4391 lpfc_nlp_remove(ndlp->vport, ndlp);
4393 /* clear the ndlp active flag for all release cases */
4395 spin_lock_irqsave(&phba->ndlp_lock, flags);
4396 NLP_CLR_NODE_ACT(ndlp);
4397 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4399 /* free ndlp memory for final ndlp release */
4400 if (NLP_CHK_FREE_REQ(ndlp)) {
4401 kfree(ndlp->lat_data);
4402 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
4406 /* This routine bumps the reference count for a ndlp structure to ensure
4407 * that one discovery thread won't free a ndlp while another discovery thread
4410 struct lpfc_nodelist *
4411 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
4413 struct lpfc_hba *phba;
4414 unsigned long flags;
4417 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
4418 "node get: did:x%x flg:x%x refcnt:x%x",
4419 ndlp->nlp_DID, ndlp->nlp_flag,
4420 atomic_read(&ndlp->kref.refcount));
4421 /* The check of ndlp usage to prevent incrementing the
4422 * ndlp reference count that is in the process of being
4426 spin_lock_irqsave(&phba->ndlp_lock, flags);
4427 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
4428 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4429 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
4430 "0276 lpfc_nlp_get: ndlp:x%p "
4431 "usgmap:x%x refcnt:%d\n",
4432 (void *)ndlp, ndlp->nlp_usg_map,
4433 atomic_read(&ndlp->kref.refcount));
4436 kref_get(&ndlp->kref);
4437 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4442 /* This routine decrements the reference count for a ndlp structure. If the
4443 * count goes to 0, this indicates the the associated nodelist should be
4444 * freed. Returning 1 indicates the ndlp resource has been released; on the
4445 * other hand, returning 0 indicates the ndlp resource has not been released
4449 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
4451 struct lpfc_hba *phba;
4452 unsigned long flags;
4457 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
4458 "node put: did:x%x flg:x%x refcnt:x%x",
4459 ndlp->nlp_DID, ndlp->nlp_flag,
4460 atomic_read(&ndlp->kref.refcount));
4462 spin_lock_irqsave(&phba->ndlp_lock, flags);
4463 /* Check the ndlp memory free acknowledge flag to avoid the
4464 * possible race condition that kref_put got invoked again
4465 * after previous one has done ndlp memory free.
4467 if (NLP_CHK_FREE_ACK(ndlp)) {
4468 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4469 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
4470 "0274 lpfc_nlp_put: ndlp:x%p "
4471 "usgmap:x%x refcnt:%d\n",
4472 (void *)ndlp, ndlp->nlp_usg_map,
4473 atomic_read(&ndlp->kref.refcount));
4476 /* Check the ndlp inactivate log flag to avoid the possible
4477 * race condition that kref_put got invoked again after ndlp
4478 * is already in inactivating state.
4480 if (NLP_CHK_IACT_REQ(ndlp)) {
4481 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4482 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
4483 "0275 lpfc_nlp_put: ndlp:x%p "
4484 "usgmap:x%x refcnt:%d\n",
4485 (void *)ndlp, ndlp->nlp_usg_map,
4486 atomic_read(&ndlp->kref.refcount));
4489 /* For last put, mark the ndlp usage flags to make sure no
4490 * other kref_get and kref_put on the same ndlp shall get
4491 * in between the process when the final kref_put has been
4492 * invoked on this ndlp.
4494 if (atomic_read(&ndlp->kref.refcount) == 1) {
4495 /* Indicate ndlp is put to inactive state. */
4496 NLP_SET_IACT_REQ(ndlp);
4497 /* Acknowledge ndlp memory free has been seen. */
4498 if (NLP_CHK_FREE_REQ(ndlp))
4499 NLP_SET_FREE_ACK(ndlp);
4501 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4502 /* Note, the kref_put returns 1 when decrementing a reference
4503 * count that was 1, it invokes the release callback function,
4504 * but it still left the reference count as 1 (not actually
4505 * performs the last decrementation). Otherwise, it actually
4506 * decrements the reference count and returns 0.
4508 return kref_put(&ndlp->kref, lpfc_nlp_release);
4511 /* This routine free's the specified nodelist if it is not in use
4512 * by any other discovery thread. This routine returns 1 if the
4513 * ndlp has been freed. A return value of 0 indicates the ndlp is
4514 * not yet been released.
4517 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
4519 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
4520 "node not used: did:x%x flg:x%x refcnt:x%x",
4521 ndlp->nlp_DID, ndlp->nlp_flag,
4522 atomic_read(&ndlp->kref.refcount));
4523 if (atomic_read(&ndlp->kref.refcount) == 1)
4524 if (lpfc_nlp_put(ndlp))
4530 * lpfc_fcf_inuse - Check if FCF can be unregistered.
4531 * @phba: Pointer to hba context object.
4533 * This function iterate through all FC nodes associated
4534 * will all vports to check if there is any node with
4535 * fc_rports associated with it. If there is an fc_rport
4536 * associated with the node, then the node is either in
4537 * discovered state or its devloss_timer is pending.
4540 lpfc_fcf_inuse(struct lpfc_hba *phba)
4542 struct lpfc_vport **vports;
4544 struct lpfc_nodelist *ndlp;
4545 struct Scsi_Host *shost;
4547 vports = lpfc_create_vport_work_array(phba);
4549 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4550 shost = lpfc_shost_from_vport(vports[i]);
4551 spin_lock_irq(shost->host_lock);
4552 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
4553 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
4554 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
4556 spin_unlock_irq(shost->host_lock);
4559 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
4560 "2624 RPI %x DID %x flg %x still "
4562 ndlp->nlp_rpi, ndlp->nlp_DID,
4564 if (ndlp->nlp_flag & NLP_RPI_VALID)
4568 spin_unlock_irq(shost->host_lock);
4571 lpfc_destroy_vport_work_array(phba, vports);
4576 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
4577 * @phba: Pointer to hba context object.
4578 * @mboxq: Pointer to mailbox object.
4580 * This function frees memory associated with the mailbox command.
4583 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
4585 struct lpfc_vport *vport = mboxq->vport;
4587 if (mboxq->u.mb.mbxStatus) {
4588 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4589 "2555 UNREG_VFI mbxStatus error x%x "
4591 mboxq->u.mb.mbxStatus, vport->port_state);
4593 mempool_free(mboxq, phba->mbox_mem_pool);
4598 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
4599 * @phba: Pointer to hba context object.
4600 * @mboxq: Pointer to mailbox object.
4602 * This function frees memory associated with the mailbox command.
4605 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
4607 struct lpfc_vport *vport = mboxq->vport;
4609 if (mboxq->u.mb.mbxStatus) {
4610 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4611 "2550 UNREG_FCFI mbxStatus error x%x "
4613 mboxq->u.mb.mbxStatus, vport->port_state);
4615 mempool_free(mboxq, phba->mbox_mem_pool);
4620 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
4621 * @phba: Pointer to hba context object.
4623 * This function prepare the HBA for unregistering the currently registered
4624 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
4628 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
4631 struct lpfc_vport **vports;
4632 struct lpfc_nodelist *ndlp;
4633 struct Scsi_Host *shost;
4636 /* Unregister RPIs */
4637 if (lpfc_fcf_inuse(phba))
4638 lpfc_unreg_hba_rpis(phba);
4640 /* At this point, all discovery is aborted */
4641 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4643 /* Unregister VPIs */
4644 vports = lpfc_create_vport_work_array(phba);
4645 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
4646 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4647 /* Stop FLOGI/FDISC retries */
4648 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
4650 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
4651 lpfc_mbx_unreg_vpi(vports[i]);
4652 shost = lpfc_shost_from_vport(vports[i]);
4653 spin_lock_irq(shost->host_lock);
4654 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
4655 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
4656 spin_unlock_irq(shost->host_lock);
4658 lpfc_destroy_vport_work_array(phba, vports);
4660 /* Cleanup any outstanding ELS commands */
4661 lpfc_els_flush_all_cmd(phba);
4663 /* Unregister VFI */
4664 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4666 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4667 "2556 UNREG_VFI mbox allocation failed"
4668 "HBA state x%x\n", phba->pport->port_state);
4672 lpfc_unreg_vfi(mbox, phba->pport);
4673 mbox->vport = phba->pport;
4674 mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
4676 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4677 if (rc == MBX_NOT_FINISHED) {
4678 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4679 "2557 UNREG_VFI issue mbox failed rc x%x "
4681 rc, phba->pport->port_state);
4682 mempool_free(mbox, phba->mbox_mem_pool);
4686 shost = lpfc_shost_from_vport(phba->pport);
4687 spin_lock_irq(shost->host_lock);
4688 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
4689 spin_unlock_irq(shost->host_lock);
4695 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
4696 * @phba: Pointer to hba context object.
4698 * This function issues synchronous unregister FCF mailbox command to HBA to
4699 * unregister the currently registered FCF record. The driver does not reset
4700 * the driver FCF usage state flags.
4702 * Return 0 if successfully issued, none-zero otherwise.
4705 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
4710 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4712 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4713 "2551 UNREG_FCFI mbox allocation failed"
4714 "HBA state x%x\n", phba->pport->port_state);
4717 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
4718 mbox->vport = phba->pport;
4719 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
4720 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4722 if (rc == MBX_NOT_FINISHED) {
4723 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4724 "2552 Unregister FCFI command failed rc x%x "
4726 rc, phba->pport->port_state);
4733 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
4734 * @phba: Pointer to hba context object.
4736 * This function unregisters the currently reigstered FCF. This function
4737 * also tries to find another FCF for discovery by rescan the HBA FCF table.
4740 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
4744 /* Preparation for unregistering fcf */
4745 rc = lpfc_unregister_fcf_prep(phba);
4747 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4748 "2748 Failed to prepare for unregistering "
4749 "HBA's FCF record: rc=%d\n", rc);
4753 /* Now, unregister FCF record and reset HBA FCF state */
4754 rc = lpfc_sli4_unregister_fcf(phba);
4757 /* Reset HBA FCF states after successful unregister FCF */
4758 phba->fcf.fcf_flag = 0;
4761 * If driver is not unloading, check if there is any other
4762 * FCF record that can be used for discovery.
4764 if ((phba->pport->load_flag & FC_UNLOADING) ||
4765 (phba->link_state < LPFC_LINK_UP))
4768 rc = lpfc_sli4_read_fcf_record(phba, LPFC_FCOE_FCF_GET_FIRST);
4771 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
4772 "2553 lpfc_unregister_unused_fcf failed "
4773 "to read FCF record HBA state x%x\n",
4774 phba->pport->port_state);
4778 * lpfc_unregister_fcf - Unregister the currently registered fcf record
4779 * @phba: Pointer to hba context object.
4781 * This function just unregisters the currently reigstered FCF. It does not
4782 * try to find another FCF for discovery.
4785 lpfc_unregister_fcf(struct lpfc_hba *phba)
4789 /* Preparation for unregistering fcf */
4790 rc = lpfc_unregister_fcf_prep(phba);
4792 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4793 "2749 Failed to prepare for unregistering "
4794 "HBA's FCF record: rc=%d\n", rc);
4798 /* Now, unregister FCF record and reset HBA FCF state */
4799 rc = lpfc_sli4_unregister_fcf(phba);
4802 /* Set proper HBA FCF states after successful unregister FCF */
4803 spin_lock_irq(&phba->hbalock);
4804 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
4805 spin_unlock_irq(&phba->hbalock);
4809 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
4810 * @phba: Pointer to hba context object.
4812 * This function check if there are any connected remote port for the FCF and
4813 * if all the devices are disconnected, this function unregister FCFI.
4814 * This function also tries to use another FCF for discovery.
4817 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
4820 * If HBA is not running in FIP mode or if HBA does not support
4821 * FCoE or if FCF is not registered, do nothing.
4823 spin_lock_irq(&phba->hbalock);
4824 if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
4825 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
4826 !(phba->hba_flag & HBA_FIP_SUPPORT)) {
4827 spin_unlock_irq(&phba->hbalock);
4830 spin_unlock_irq(&phba->hbalock);
4832 if (lpfc_fcf_inuse(phba))
4835 lpfc_unregister_fcf_rescan(phba);
4839 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
4840 * @phba: Pointer to hba context object.
4841 * @buff: Buffer containing the FCF connection table as in the config
4843 * This function create driver data structure for the FCF connection
4844 * record table read from config region 23.
4847 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
4850 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
4851 struct lpfc_fcf_conn_hdr *conn_hdr;
4852 struct lpfc_fcf_conn_rec *conn_rec;
4853 uint32_t record_count;
4856 /* Free the current connect table */
4857 list_for_each_entry_safe(conn_entry, next_conn_entry,
4858 &phba->fcf_conn_rec_list, list) {
4859 list_del_init(&conn_entry->list);
4863 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
4864 record_count = conn_hdr->length * sizeof(uint32_t)/
4865 sizeof(struct lpfc_fcf_conn_rec);
4867 conn_rec = (struct lpfc_fcf_conn_rec *)
4868 (buff + sizeof(struct lpfc_fcf_conn_hdr));
4870 for (i = 0; i < record_count; i++) {
4871 if (!(conn_rec[i].flags & FCFCNCT_VALID))
4873 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
4876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4877 "2566 Failed to allocate connection"
4882 memcpy(&conn_entry->conn_rec, &conn_rec[i],
4883 sizeof(struct lpfc_fcf_conn_rec));
4884 conn_entry->conn_rec.vlan_tag =
4885 le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
4886 conn_entry->conn_rec.flags =
4887 le16_to_cpu(conn_entry->conn_rec.flags);
4888 list_add_tail(&conn_entry->list,
4889 &phba->fcf_conn_rec_list);
4894 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
4895 * @phba: Pointer to hba context object.
4896 * @buff: Buffer containing the FCoE parameter data structure.
4898 * This function update driver data structure with config
4899 * parameters read from config region 23.
4902 lpfc_read_fcoe_param(struct lpfc_hba *phba,
4905 struct lpfc_fip_param_hdr *fcoe_param_hdr;
4906 struct lpfc_fcoe_params *fcoe_param;
4908 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
4910 fcoe_param = (struct lpfc_fcoe_params *)
4911 (buff + sizeof(struct lpfc_fip_param_hdr));
4913 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
4914 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
4917 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
4918 phba->valid_vlan = 1;
4919 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
4923 phba->fc_map[0] = fcoe_param->fc_map[0];
4924 phba->fc_map[1] = fcoe_param->fc_map[1];
4925 phba->fc_map[2] = fcoe_param->fc_map[2];
4930 * lpfc_get_rec_conf23 - Get a record type in config region data.
4931 * @buff: Buffer containing config region 23 data.
4932 * @size: Size of the data buffer.
4933 * @rec_type: Record type to be searched.
4935 * This function searches config region data to find the begining
4936 * of the record specified by record_type. If record found, this
4937 * function return pointer to the record else return NULL.
4940 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
4942 uint32_t offset = 0, rec_length;
4944 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
4945 (size < sizeof(uint32_t)))
4948 rec_length = buff[offset + 1];
4951 * One TLV record has one word header and number of data words
4952 * specified in the rec_length field of the record header.
4954 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
4956 if (buff[offset] == rec_type)
4957 return &buff[offset];
4959 if (buff[offset] == LPFC_REGION23_LAST_REC)
4962 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
4963 rec_length = buff[offset + 1];
4969 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
4970 * @phba: Pointer to lpfc_hba data structure.
4971 * @buff: Buffer containing config region 23 data.
4972 * @size: Size of the data buffer.
4974 * This fuction parse the FCoE config parameters in config region 23 and
4975 * populate driver data structure with the parameters.
4978 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
4982 uint32_t offset = 0, rec_length;
4986 * If data size is less than 2 words signature and version cannot be
4989 if (size < 2*sizeof(uint32_t))
4992 /* Check the region signature first */
4993 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
4994 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4995 "2567 Config region 23 has bad signature\n");
5001 /* Check the data structure version */
5002 if (buff[offset] != LPFC_REGION23_VERSION) {
5003 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5004 "2568 Config region 23 has bad version\n");
5009 rec_length = buff[offset + 1];
5011 /* Read FCoE param record */
5012 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5013 size - offset, FCOE_PARAM_TYPE);
5015 lpfc_read_fcoe_param(phba, rec_ptr);
5017 /* Read FCF connection table */
5018 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5019 size - offset, FCOE_CONN_TBL_TYPE);
5021 lpfc_read_fcf_conn_tbl(phba, rec_ptr);