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/delay.h>
24 #include <linux/slab.h>
25 #include <linux/pci.h>
26 #include <linux/kthread.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_disc.h"
39 #include "lpfc_sli4.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 /* AlpaArray for assignment of scsid for scan-down and bind_method */
48 static uint8_t lpfcAlpaArray[] = {
49 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
50 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
51 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
52 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
53 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
54 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
55 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
56 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
57 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
58 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
59 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
60 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
61 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
64 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
65 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
66 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
67 static int lpfc_fcf_inuse(struct lpfc_hba *);
70 lpfc_terminate_rport_io(struct fc_rport *rport)
72 struct lpfc_rport_data *rdata;
73 struct lpfc_nodelist * ndlp;
74 struct lpfc_hba *phba;
76 rdata = rport->dd_data;
79 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
80 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
81 printk(KERN_ERR "Cannot find remote node"
82 " to terminate I/O Data x%x\n",
89 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
90 "rport terminate: sid:x%x did:x%x flg:x%x",
91 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
93 if (ndlp->nlp_sid != NLP_NO_SID) {
94 lpfc_sli_abort_iocb(ndlp->vport,
95 &phba->sli.ring[phba->sli.fcp_ring],
96 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
101 * This function will be called when dev_loss_tmo fire.
104 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
106 struct lpfc_rport_data *rdata;
107 struct lpfc_nodelist * ndlp;
108 struct lpfc_vport *vport;
109 struct lpfc_hba *phba;
110 struct lpfc_work_evt *evtp;
114 rdata = rport->dd_data;
116 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
122 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
123 "rport devlosscb: sid:x%x did:x%x flg:x%x",
124 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
126 /* Don't defer this if we are in the process of deleting the vport
127 * or unloading the driver. The unload will cleanup the node
128 * appropriately we just need to cleanup the ndlp rport info here.
130 if (vport->load_flag & FC_UNLOADING) {
131 put_node = rdata->pnode != NULL;
132 put_rport = ndlp->rport != NULL;
138 put_device(&rport->dev);
142 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
145 evtp = &ndlp->dev_loss_evt;
147 if (!list_empty(&evtp->evt_listp))
150 spin_lock_irq(&phba->hbalock);
151 /* We need to hold the node by incrementing the reference
152 * count until this queued work is done
154 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
155 if (evtp->evt_arg1) {
156 evtp->evt = LPFC_EVT_DEV_LOSS;
157 list_add_tail(&evtp->evt_listp, &phba->work_list);
158 lpfc_worker_wake_up(phba);
160 spin_unlock_irq(&phba->hbalock);
166 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
167 * @ndlp: Pointer to remote node object.
169 * This function is called from the worker thread when devloss timeout timer
170 * expires. For SLI4 host, this routine shall return 1 when at lease one
171 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
172 * routine shall return 0 when there is no remote node is still in use of FCF
173 * when devloss timeout happened to this @ndlp.
176 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
178 struct lpfc_rport_data *rdata;
179 struct fc_rport *rport;
180 struct lpfc_vport *vport;
181 struct lpfc_hba *phba;
193 rdata = rport->dd_data;
194 name = (uint8_t *) &ndlp->nlp_portname;
198 if (phba->sli_rev == LPFC_SLI_REV4)
199 fcf_inuse = lpfc_fcf_inuse(phba);
201 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
202 "rport devlosstmo:did:x%x type:x%x id:x%x",
203 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
205 /* Don't defer this if we are in the process of deleting the vport
206 * or unloading the driver. The unload will cleanup the node
207 * appropriately we just need to cleanup the ndlp rport info here.
209 if (vport->load_flag & FC_UNLOADING) {
210 if (ndlp->nlp_sid != NLP_NO_SID) {
211 /* flush the target */
212 lpfc_sli_abort_iocb(vport,
213 &phba->sli.ring[phba->sli.fcp_ring],
214 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
216 put_node = rdata->pnode != NULL;
217 put_rport = ndlp->rport != NULL;
223 put_device(&rport->dev);
227 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
228 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
229 "0284 Devloss timeout Ignored on "
230 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
232 *name, *(name+1), *(name+2), *(name+3),
233 *(name+4), *(name+5), *(name+6), *(name+7),
238 if (ndlp->nlp_type & NLP_FABRIC) {
239 /* We will clean up these Nodes in linkup */
240 put_node = rdata->pnode != NULL;
241 put_rport = ndlp->rport != NULL;
247 put_device(&rport->dev);
251 if (ndlp->nlp_sid != NLP_NO_SID) {
253 /* flush the target */
254 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
255 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
259 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
260 "0203 Devloss timeout on "
261 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
262 "NPort x%06x Data: x%x x%x x%x\n",
263 *name, *(name+1), *(name+2), *(name+3),
264 *(name+4), *(name+5), *(name+6), *(name+7),
265 ndlp->nlp_DID, ndlp->nlp_flag,
266 ndlp->nlp_state, ndlp->nlp_rpi);
268 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
269 "0204 Devloss timeout on "
270 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
271 "NPort x%06x Data: x%x x%x x%x\n",
272 *name, *(name+1), *(name+2), *(name+3),
273 *(name+4), *(name+5), *(name+6), *(name+7),
274 ndlp->nlp_DID, ndlp->nlp_flag,
275 ndlp->nlp_state, ndlp->nlp_rpi);
278 put_node = rdata->pnode != NULL;
279 put_rport = ndlp->rport != NULL;
285 put_device(&rport->dev);
287 if (!(vport->load_flag & FC_UNLOADING) &&
288 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
289 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
290 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
291 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
292 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
293 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
299 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
300 * @phba: Pointer to hba context object.
301 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
302 * @nlp_did: remote node identifer with devloss timeout.
304 * This function is called from the worker thread after invoking devloss
305 * timeout handler and releasing the reference count for the ndlp with
306 * which the devloss timeout was handled for SLI4 host. For the devloss
307 * timeout of the last remote node which had been in use of FCF, when this
308 * routine is invoked, it shall be guaranteed that none of the remote are
309 * in-use of FCF. When devloss timeout to the last remote using the FCF,
310 * if the FIP engine is neither in FCF table scan process nor roundrobin
311 * failover process, the in-use FCF shall be unregistered. If the FIP
312 * engine is in FCF discovery process, the devloss timeout state shall
313 * be set for either the FCF table scan process or roundrobin failover
314 * process to unregister the in-use FCF.
317 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
320 /* If devloss timeout happened to a remote node when FCF had no
321 * longer been in-use, do nothing.
326 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
327 spin_lock_irq(&phba->hbalock);
328 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
329 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
330 spin_unlock_irq(&phba->hbalock);
333 phba->hba_flag |= HBA_DEVLOSS_TMO;
334 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
335 "2847 Last remote node (x%x) using "
336 "FCF devloss tmo\n", nlp_did);
338 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
339 spin_unlock_irq(&phba->hbalock);
340 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
341 "2868 Devloss tmo to FCF rediscovery "
345 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
346 spin_unlock_irq(&phba->hbalock);
347 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
348 "2869 Devloss tmo to idle FIP engine, "
349 "unreg in-use FCF and rescan.\n");
350 /* Unregister in-use FCF and rescan */
351 lpfc_unregister_fcf_rescan(phba);
354 spin_unlock_irq(&phba->hbalock);
355 if (phba->hba_flag & FCF_TS_INPROG)
356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
357 "2870 FCF table scan in progress\n");
358 if (phba->hba_flag & FCF_RR_INPROG)
359 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
360 "2871 FLOGI roundrobin FCF failover "
363 lpfc_unregister_unused_fcf(phba);
367 * lpfc_alloc_fast_evt - Allocates data structure for posting event
368 * @phba: Pointer to hba context object.
370 * This function is called from the functions which need to post
371 * events from interrupt context. This function allocates data
372 * structure required for posting event. It also keeps track of
373 * number of events pending and prevent event storm when there are
376 struct lpfc_fast_path_event *
377 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
378 struct lpfc_fast_path_event *ret;
380 /* If there are lot of fast event do not exhaust memory due to this */
381 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
384 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
387 atomic_inc(&phba->fast_event_count);
388 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
389 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
395 * lpfc_free_fast_evt - Frees event data structure
396 * @phba: Pointer to hba context object.
397 * @evt: Event object which need to be freed.
399 * This function frees the data structure required for posting
403 lpfc_free_fast_evt(struct lpfc_hba *phba,
404 struct lpfc_fast_path_event *evt) {
406 atomic_dec(&phba->fast_event_count);
411 * lpfc_send_fastpath_evt - Posts events generated from fast path
412 * @phba: Pointer to hba context object.
413 * @evtp: Event data structure.
415 * This function is called from worker thread, when the interrupt
416 * context need to post an event. This function posts the event
417 * to fc transport netlink interface.
420 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
421 struct lpfc_work_evt *evtp)
423 unsigned long evt_category, evt_sub_category;
424 struct lpfc_fast_path_event *fast_evt_data;
426 uint32_t evt_data_size;
427 struct Scsi_Host *shost;
429 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
432 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
433 evt_sub_category = (unsigned long) fast_evt_data->un.
434 fabric_evt.subcategory;
435 shost = lpfc_shost_from_vport(fast_evt_data->vport);
436 if (evt_category == FC_REG_FABRIC_EVENT) {
437 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
438 evt_data = (char *) &fast_evt_data->un.read_check_error;
439 evt_data_size = sizeof(fast_evt_data->un.
441 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
442 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
443 evt_data = (char *) &fast_evt_data->un.fabric_evt;
444 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
446 lpfc_free_fast_evt(phba, fast_evt_data);
449 } else if (evt_category == FC_REG_SCSI_EVENT) {
450 switch (evt_sub_category) {
451 case LPFC_EVENT_QFULL:
452 case LPFC_EVENT_DEVBSY:
453 evt_data = (char *) &fast_evt_data->un.scsi_evt;
454 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
456 case LPFC_EVENT_CHECK_COND:
457 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
458 evt_data_size = sizeof(fast_evt_data->un.
461 case LPFC_EVENT_VARQUEDEPTH:
462 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
463 evt_data_size = sizeof(fast_evt_data->un.
467 lpfc_free_fast_evt(phba, fast_evt_data);
471 lpfc_free_fast_evt(phba, fast_evt_data);
475 fc_host_post_vendor_event(shost,
476 fc_get_event_number(),
481 lpfc_free_fast_evt(phba, fast_evt_data);
486 lpfc_work_list_done(struct lpfc_hba *phba)
488 struct lpfc_work_evt *evtp = NULL;
489 struct lpfc_nodelist *ndlp;
494 spin_lock_irq(&phba->hbalock);
495 while (!list_empty(&phba->work_list)) {
496 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
498 spin_unlock_irq(&phba->hbalock);
501 case LPFC_EVT_ELS_RETRY:
502 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
503 lpfc_els_retry_delay_handler(ndlp);
504 free_evt = 0; /* evt is part of ndlp */
505 /* decrement the node reference count held
506 * for this queued work
510 case LPFC_EVT_DEV_LOSS:
511 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
512 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
514 /* decrement the node reference count held for
517 nlp_did = ndlp->nlp_DID;
519 if (phba->sli_rev == LPFC_SLI_REV4)
520 lpfc_sli4_post_dev_loss_tmo_handler(phba,
524 case LPFC_EVT_ONLINE:
525 if (phba->link_state < LPFC_LINK_DOWN)
526 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
528 *(int *) (evtp->evt_arg1) = 0;
529 complete((struct completion *)(evtp->evt_arg2));
531 case LPFC_EVT_OFFLINE_PREP:
532 if (phba->link_state >= LPFC_LINK_DOWN)
533 lpfc_offline_prep(phba);
534 *(int *)(evtp->evt_arg1) = 0;
535 complete((struct completion *)(evtp->evt_arg2));
537 case LPFC_EVT_OFFLINE:
539 lpfc_sli_brdrestart(phba);
540 *(int *)(evtp->evt_arg1) =
541 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
542 lpfc_unblock_mgmt_io(phba);
543 complete((struct completion *)(evtp->evt_arg2));
545 case LPFC_EVT_WARM_START:
547 lpfc_reset_barrier(phba);
548 lpfc_sli_brdreset(phba);
549 lpfc_hba_down_post(phba);
550 *(int *)(evtp->evt_arg1) =
551 lpfc_sli_brdready(phba, HS_MBRDY);
552 lpfc_unblock_mgmt_io(phba);
553 complete((struct completion *)(evtp->evt_arg2));
557 *(int *)(evtp->evt_arg1)
558 = (phba->pport->stopped)
559 ? 0 : lpfc_sli_brdkill(phba);
560 lpfc_unblock_mgmt_io(phba);
561 complete((struct completion *)(evtp->evt_arg2));
563 case LPFC_EVT_FASTPATH_MGMT_EVT:
564 lpfc_send_fastpath_evt(phba, evtp);
567 case LPFC_EVT_RESET_HBA:
568 if (!(phba->pport->load_flag & FC_UNLOADING))
569 lpfc_reset_hba(phba);
574 spin_lock_irq(&phba->hbalock);
576 spin_unlock_irq(&phba->hbalock);
581 lpfc_work_done(struct lpfc_hba *phba)
583 struct lpfc_sli_ring *pring;
584 uint32_t ha_copy, status, control, work_port_events;
585 struct lpfc_vport **vports;
586 struct lpfc_vport *vport;
589 spin_lock_irq(&phba->hbalock);
590 ha_copy = phba->work_ha;
592 spin_unlock_irq(&phba->hbalock);
594 /* First, try to post the next mailbox command to SLI4 device */
595 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
596 lpfc_sli4_post_async_mbox(phba);
598 if (ha_copy & HA_ERATT)
599 /* Handle the error attention event */
600 lpfc_handle_eratt(phba);
602 if (ha_copy & HA_MBATT)
603 lpfc_sli_handle_mb_event(phba);
605 if (ha_copy & HA_LATT)
606 lpfc_handle_latt(phba);
608 /* Process SLI4 events */
609 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
610 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
611 lpfc_sli4_fcp_xri_abort_event_proc(phba);
612 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
613 lpfc_sli4_els_xri_abort_event_proc(phba);
614 if (phba->hba_flag & ASYNC_EVENT)
615 lpfc_sli4_async_event_proc(phba);
616 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
617 spin_lock_irq(&phba->hbalock);
618 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
619 spin_unlock_irq(&phba->hbalock);
620 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
622 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
623 lpfc_sli4_fcf_redisc_event_proc(phba);
626 vports = lpfc_create_vport_work_array(phba);
628 for (i = 0; i <= phba->max_vports; i++) {
630 * We could have no vports in array if unloading, so if
631 * this happens then just use the pport
633 if (vports[i] == NULL && i == 0)
639 spin_lock_irq(&vport->work_port_lock);
640 work_port_events = vport->work_port_events;
641 vport->work_port_events &= ~work_port_events;
642 spin_unlock_irq(&vport->work_port_lock);
643 if (work_port_events & WORKER_DISC_TMO)
644 lpfc_disc_timeout_handler(vport);
645 if (work_port_events & WORKER_ELS_TMO)
646 lpfc_els_timeout_handler(vport);
647 if (work_port_events & WORKER_HB_TMO)
648 lpfc_hb_timeout_handler(phba);
649 if (work_port_events & WORKER_MBOX_TMO)
650 lpfc_mbox_timeout_handler(phba);
651 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
652 lpfc_unblock_fabric_iocbs(phba);
653 if (work_port_events & WORKER_FDMI_TMO)
654 lpfc_fdmi_timeout_handler(vport);
655 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
656 lpfc_ramp_down_queue_handler(phba);
657 if (work_port_events & WORKER_RAMP_UP_QUEUE)
658 lpfc_ramp_up_queue_handler(phba);
660 lpfc_destroy_vport_work_array(phba, vports);
662 pring = &phba->sli.ring[LPFC_ELS_RING];
663 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
664 status >>= (4*LPFC_ELS_RING);
665 if ((status & HA_RXMASK) ||
666 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
667 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
668 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
669 pring->flag |= LPFC_DEFERRED_RING_EVENT;
670 /* Set the lpfc data pending flag */
671 set_bit(LPFC_DATA_READY, &phba->data_flags);
673 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
674 lpfc_sli_handle_slow_ring_event(phba, pring,
678 if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt)
679 lpfc_drain_txq(phba);
681 * Turn on Ring interrupts
683 if (phba->sli_rev <= LPFC_SLI_REV3) {
684 spin_lock_irq(&phba->hbalock);
685 control = readl(phba->HCregaddr);
686 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
687 lpfc_debugfs_slow_ring_trc(phba,
688 "WRK Enable ring: cntl:x%x hacopy:x%x",
689 control, ha_copy, 0);
691 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
692 writel(control, phba->HCregaddr);
693 readl(phba->HCregaddr); /* flush */
695 lpfc_debugfs_slow_ring_trc(phba,
696 "WRK Ring ok: cntl:x%x hacopy:x%x",
697 control, ha_copy, 0);
699 spin_unlock_irq(&phba->hbalock);
702 lpfc_work_list_done(phba);
706 lpfc_do_work(void *p)
708 struct lpfc_hba *phba = p;
711 set_user_nice(current, -20);
712 phba->data_flags = 0;
714 while (!kthread_should_stop()) {
715 /* wait and check worker queue activities */
716 rc = wait_event_interruptible(phba->work_waitq,
717 (test_and_clear_bit(LPFC_DATA_READY,
719 || kthread_should_stop()));
720 /* Signal wakeup shall terminate the worker thread */
722 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
723 "0433 Wakeup on signal: rc=x%x\n", rc);
727 /* Attend pending lpfc data processing */
728 lpfc_work_done(phba);
730 phba->worker_thread = NULL;
731 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
732 "0432 Worker thread stopped.\n");
737 * This is only called to handle FC worker events. Since this a rare
738 * occurance, we allocate a struct lpfc_work_evt structure here instead of
739 * embedding it in the IOCB.
742 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
745 struct lpfc_work_evt *evtp;
749 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
750 * be queued to worker thread for processing
752 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
756 evtp->evt_arg1 = arg1;
757 evtp->evt_arg2 = arg2;
760 spin_lock_irqsave(&phba->hbalock, flags);
761 list_add_tail(&evtp->evt_listp, &phba->work_list);
762 spin_unlock_irqrestore(&phba->hbalock, flags);
764 lpfc_worker_wake_up(phba);
770 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
773 struct lpfc_hba *phba = vport->phba;
774 struct lpfc_nodelist *ndlp, *next_ndlp;
777 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
778 if (!NLP_CHK_NODE_ACT(ndlp))
780 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
782 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
783 ((vport->port_type == LPFC_NPIV_PORT) &&
784 (ndlp->nlp_DID == NameServer_DID)))
785 lpfc_unreg_rpi(vport, ndlp);
787 /* Leave Fabric nodes alone on link down */
788 if ((phba->sli_rev < LPFC_SLI_REV4) &&
789 (!remove && ndlp->nlp_type & NLP_FABRIC))
791 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
794 : NLP_EVT_DEVICE_RECOVERY);
796 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
797 lpfc_mbx_unreg_vpi(vport);
798 spin_lock_irq(shost->host_lock);
799 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
800 spin_unlock_irq(shost->host_lock);
805 lpfc_port_link_failure(struct lpfc_vport *vport)
807 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
809 /* Cleanup any outstanding received buffers */
810 lpfc_cleanup_rcv_buffers(vport);
812 /* Cleanup any outstanding RSCN activity */
813 lpfc_els_flush_rscn(vport);
815 /* Cleanup any outstanding ELS commands */
816 lpfc_els_flush_cmd(vport);
818 lpfc_cleanup_rpis(vport, 0);
820 /* Turn off discovery timer if its running */
821 lpfc_can_disctmo(vport);
825 lpfc_linkdown_port(struct lpfc_vport *vport)
827 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
829 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
831 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
832 "Link Down: state:x%x rtry:x%x flg:x%x",
833 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
835 lpfc_port_link_failure(vport);
840 lpfc_linkdown(struct lpfc_hba *phba)
842 struct lpfc_vport *vport = phba->pport;
843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
844 struct lpfc_vport **vports;
848 if (phba->link_state == LPFC_LINK_DOWN)
851 /* Block all SCSI stack I/Os */
852 lpfc_scsi_dev_block(phba);
854 spin_lock_irq(&phba->hbalock);
855 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
856 spin_unlock_irq(&phba->hbalock);
857 if (phba->link_state > LPFC_LINK_DOWN) {
858 phba->link_state = LPFC_LINK_DOWN;
859 spin_lock_irq(shost->host_lock);
860 phba->pport->fc_flag &= ~FC_LBIT;
861 spin_unlock_irq(shost->host_lock);
863 vports = lpfc_create_vport_work_array(phba);
865 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
866 /* Issue a LINK DOWN event to all nodes */
867 lpfc_linkdown_port(vports[i]);
869 lpfc_destroy_vport_work_array(phba, vports);
870 /* Clean up any firmware default rpi's */
871 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
873 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
875 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
876 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
877 == MBX_NOT_FINISHED) {
878 mempool_free(mb, phba->mbox_mem_pool);
882 /* Setup myDID for link up if we are in pt2pt mode */
883 if (phba->pport->fc_flag & FC_PT2PT) {
884 phba->pport->fc_myDID = 0;
885 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
887 lpfc_config_link(phba, mb);
888 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
890 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
891 == MBX_NOT_FINISHED) {
892 mempool_free(mb, phba->mbox_mem_pool);
895 spin_lock_irq(shost->host_lock);
896 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
897 spin_unlock_irq(shost->host_lock);
904 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
906 struct lpfc_nodelist *ndlp;
908 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
909 if (!NLP_CHK_NODE_ACT(ndlp))
911 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
913 if (ndlp->nlp_type & NLP_FABRIC) {
914 /* On Linkup its safe to clean up the ndlp
915 * from Fabric connections.
917 if (ndlp->nlp_DID != Fabric_DID)
918 lpfc_unreg_rpi(vport, ndlp);
919 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
920 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
921 /* Fail outstanding IO now since device is
924 lpfc_unreg_rpi(vport, ndlp);
930 lpfc_linkup_port(struct lpfc_vport *vport)
932 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
933 struct lpfc_hba *phba = vport->phba;
935 if ((vport->load_flag & FC_UNLOADING) != 0)
938 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
939 "Link Up: top:x%x speed:x%x flg:x%x",
940 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
942 /* If NPIV is not enabled, only bring the physical port up */
943 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
944 (vport != phba->pport))
947 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
949 spin_lock_irq(shost->host_lock);
950 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
951 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
952 vport->fc_flag |= FC_NDISC_ACTIVE;
953 vport->fc_ns_retry = 0;
954 spin_unlock_irq(shost->host_lock);
956 if (vport->fc_flag & FC_LBIT)
957 lpfc_linkup_cleanup_nodes(vport);
962 lpfc_linkup(struct lpfc_hba *phba)
964 struct lpfc_vport **vports;
967 phba->link_state = LPFC_LINK_UP;
969 /* Unblock fabric iocbs if they are blocked */
970 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
971 del_timer_sync(&phba->fabric_block_timer);
973 vports = lpfc_create_vport_work_array(phba);
975 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
976 lpfc_linkup_port(vports[i]);
977 lpfc_destroy_vport_work_array(phba, vports);
978 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
979 (phba->sli_rev < LPFC_SLI_REV4))
980 lpfc_issue_clear_la(phba, phba->pport);
986 * This routine handles processing a CLEAR_LA mailbox
987 * command upon completion. It is setup in the LPFC_MBOXQ
988 * as the completion routine when the command is
989 * handed off to the SLI layer.
992 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
994 struct lpfc_vport *vport = pmb->vport;
995 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
996 struct lpfc_sli *psli = &phba->sli;
997 MAILBOX_t *mb = &pmb->u.mb;
1000 /* Since we don't do discovery right now, turn these off here */
1001 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1002 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1003 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1005 /* Check for error */
1006 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1007 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1008 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1009 "0320 CLEAR_LA mbxStatus error x%x hba "
1011 mb->mbxStatus, vport->port_state);
1012 phba->link_state = LPFC_HBA_ERROR;
1016 if (vport->port_type == LPFC_PHYSICAL_PORT)
1017 phba->link_state = LPFC_HBA_READY;
1019 spin_lock_irq(&phba->hbalock);
1020 psli->sli_flag |= LPFC_PROCESS_LA;
1021 control = readl(phba->HCregaddr);
1022 control |= HC_LAINT_ENA;
1023 writel(control, phba->HCregaddr);
1024 readl(phba->HCregaddr); /* flush */
1025 spin_unlock_irq(&phba->hbalock);
1026 mempool_free(pmb, phba->mbox_mem_pool);
1030 /* Device Discovery completes */
1031 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1032 "0225 Device Discovery completes\n");
1033 mempool_free(pmb, phba->mbox_mem_pool);
1035 spin_lock_irq(shost->host_lock);
1036 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1037 spin_unlock_irq(shost->host_lock);
1039 lpfc_can_disctmo(vport);
1041 /* turn on Link Attention interrupts */
1043 spin_lock_irq(&phba->hbalock);
1044 psli->sli_flag |= LPFC_PROCESS_LA;
1045 control = readl(phba->HCregaddr);
1046 control |= HC_LAINT_ENA;
1047 writel(control, phba->HCregaddr);
1048 readl(phba->HCregaddr); /* flush */
1049 spin_unlock_irq(&phba->hbalock);
1056 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1058 struct lpfc_vport *vport = pmb->vport;
1060 if (pmb->u.mb.mbxStatus)
1063 mempool_free(pmb, phba->mbox_mem_pool);
1065 if (phba->fc_topology == TOPOLOGY_LOOP &&
1066 vport->fc_flag & FC_PUBLIC_LOOP &&
1067 !(vport->fc_flag & FC_LBIT)) {
1068 /* Need to wait for FAN - use discovery timer
1069 * for timeout. port_state is identically
1070 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1072 lpfc_set_disctmo(vport);
1076 /* Start discovery by sending a FLOGI. port_state is identically
1077 * LPFC_FLOGI while waiting for FLOGI cmpl
1079 if (vport->port_state != LPFC_FLOGI) {
1080 lpfc_initial_flogi(vport);
1085 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1086 "0306 CONFIG_LINK mbxStatus error x%x "
1088 pmb->u.mb.mbxStatus, vport->port_state);
1089 mempool_free(pmb, phba->mbox_mem_pool);
1091 lpfc_linkdown(phba);
1093 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1094 "0200 CONFIG_LINK bad hba state x%x\n",
1097 lpfc_issue_clear_la(phba, vport);
1102 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1104 struct lpfc_vport *vport = mboxq->vport;
1106 if (mboxq->u.mb.mbxStatus) {
1107 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1108 "2017 REG_FCFI mbxStatus error x%x "
1110 mboxq->u.mb.mbxStatus, vport->port_state);
1114 /* Start FCoE discovery by sending a FLOGI. */
1115 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1116 /* Set the FCFI registered flag */
1117 spin_lock_irq(&phba->hbalock);
1118 phba->fcf.fcf_flag |= FCF_REGISTERED;
1119 spin_unlock_irq(&phba->hbalock);
1121 /* If there is a pending FCoE event, restart FCF table scan. */
1122 if (lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1125 /* Mark successful completion of FCF table scan */
1126 spin_lock_irq(&phba->hbalock);
1127 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1128 phba->hba_flag &= ~FCF_TS_INPROG;
1129 if (vport->port_state != LPFC_FLOGI) {
1130 phba->hba_flag |= FCF_RR_INPROG;
1131 spin_unlock_irq(&phba->hbalock);
1132 lpfc_initial_flogi(vport);
1135 spin_unlock_irq(&phba->hbalock);
1139 spin_lock_irq(&phba->hbalock);
1140 phba->hba_flag &= ~FCF_RR_INPROG;
1141 spin_unlock_irq(&phba->hbalock);
1143 mempool_free(mboxq, phba->mbox_mem_pool);
1147 * lpfc_fab_name_match - Check if the fcf fabric name match.
1148 * @fab_name: pointer to fabric name.
1149 * @new_fcf_record: pointer to fcf record.
1151 * This routine compare the fcf record's fabric name with provided
1152 * fabric name. If the fabric name are identical this function
1153 * returns 1 else return 0.
1156 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1158 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1160 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1162 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1164 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1166 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1168 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1170 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1172 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1178 * lpfc_sw_name_match - Check if the fcf switch name match.
1179 * @fab_name: pointer to fabric name.
1180 * @new_fcf_record: pointer to fcf record.
1182 * This routine compare the fcf record's switch name with provided
1183 * switch name. If the switch name are identical this function
1184 * returns 1 else return 0.
1187 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1189 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1191 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1193 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1195 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1197 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1199 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1201 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1203 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1209 * lpfc_mac_addr_match - Check if the fcf mac address match.
1210 * @mac_addr: pointer to mac address.
1211 * @new_fcf_record: pointer to fcf record.
1213 * This routine compare the fcf record's mac address with HBA's
1214 * FCF mac address. If the mac addresses are identical this function
1215 * returns 1 else return 0.
1218 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1220 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1222 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1224 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1226 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1228 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1230 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1236 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1238 return (curr_vlan_id == new_vlan_id);
1242 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1243 * @fcf: pointer to driver fcf record.
1244 * @new_fcf_record: pointer to fcf record.
1246 * This routine copies the FCF information from the FCF
1247 * record to lpfc_hba data structure.
1250 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1251 struct fcf_record *new_fcf_record)
1254 fcf_rec->fabric_name[0] =
1255 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1256 fcf_rec->fabric_name[1] =
1257 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1258 fcf_rec->fabric_name[2] =
1259 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1260 fcf_rec->fabric_name[3] =
1261 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1262 fcf_rec->fabric_name[4] =
1263 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1264 fcf_rec->fabric_name[5] =
1265 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1266 fcf_rec->fabric_name[6] =
1267 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1268 fcf_rec->fabric_name[7] =
1269 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1271 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1272 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1273 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1274 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1275 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1276 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1277 /* FCF record index */
1278 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1279 /* FCF record priority */
1280 fcf_rec->priority = new_fcf_record->fip_priority;
1282 fcf_rec->switch_name[0] =
1283 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1284 fcf_rec->switch_name[1] =
1285 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1286 fcf_rec->switch_name[2] =
1287 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1288 fcf_rec->switch_name[3] =
1289 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1290 fcf_rec->switch_name[4] =
1291 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1292 fcf_rec->switch_name[5] =
1293 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1294 fcf_rec->switch_name[6] =
1295 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1296 fcf_rec->switch_name[7] =
1297 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1301 * lpfc_update_fcf_record - Update driver fcf record
1302 * @phba: pointer to lpfc hba data structure.
1303 * @fcf_rec: pointer to driver fcf record.
1304 * @new_fcf_record: pointer to hba fcf record.
1305 * @addr_mode: address mode to be set to the driver fcf record.
1306 * @vlan_id: vlan tag to be set to the driver fcf record.
1307 * @flag: flag bits to be set to the driver fcf record.
1309 * This routine updates the driver FCF record from the new HBA FCF record
1310 * together with the address mode, vlan_id, and other informations. This
1311 * routine is called with the host lock held.
1314 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1315 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1316 uint16_t vlan_id, uint32_t flag)
1318 /* Copy the fields from the HBA's FCF record */
1319 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1320 /* Update other fields of driver FCF record */
1321 fcf_rec->addr_mode = addr_mode;
1322 fcf_rec->vlan_id = vlan_id;
1323 fcf_rec->flag |= (flag | RECORD_VALID);
1327 * lpfc_register_fcf - Register the FCF with hba.
1328 * @phba: pointer to lpfc hba data structure.
1330 * This routine issues a register fcfi mailbox command to register
1334 lpfc_register_fcf(struct lpfc_hba *phba)
1336 LPFC_MBOXQ_t *fcf_mbxq;
1339 spin_lock_irq(&phba->hbalock);
1340 /* If the FCF is not availabe do nothing. */
1341 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1342 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1343 spin_unlock_irq(&phba->hbalock);
1347 /* The FCF is already registered, start discovery */
1348 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1349 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1350 phba->hba_flag &= ~FCF_TS_INPROG;
1351 if (phba->pport->port_state != LPFC_FLOGI) {
1352 phba->hba_flag |= FCF_RR_INPROG;
1353 spin_unlock_irq(&phba->hbalock);
1354 lpfc_initial_flogi(phba->pport);
1357 spin_unlock_irq(&phba->hbalock);
1360 spin_unlock_irq(&phba->hbalock);
1362 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1364 spin_lock_irq(&phba->hbalock);
1365 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1366 spin_unlock_irq(&phba->hbalock);
1370 lpfc_reg_fcfi(phba, fcf_mbxq);
1371 fcf_mbxq->vport = phba->pport;
1372 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1373 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1374 if (rc == MBX_NOT_FINISHED) {
1375 spin_lock_irq(&phba->hbalock);
1376 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1377 spin_unlock_irq(&phba->hbalock);
1378 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1385 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1386 * @phba: pointer to lpfc hba data structure.
1387 * @new_fcf_record: pointer to fcf record.
1388 * @boot_flag: Indicates if this record used by boot bios.
1389 * @addr_mode: The address mode to be used by this FCF
1390 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1392 * This routine compare the fcf record with connect list obtained from the
1393 * config region to decide if this FCF can be used for SAN discovery. It returns
1394 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1395 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1396 * is used by boot bios and addr_mode will indicate the addressing mode to be
1397 * used for this FCF when the function returns.
1398 * If the FCF record need to be used with a particular vlan id, the vlan is
1399 * set in the vlan_id on return of the function. If not VLAN tagging need to
1400 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1403 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1404 struct fcf_record *new_fcf_record,
1405 uint32_t *boot_flag, uint32_t *addr_mode,
1408 struct lpfc_fcf_conn_entry *conn_entry;
1409 int i, j, fcf_vlan_id = 0;
1411 /* Find the lowest VLAN id in the FCF record */
1412 for (i = 0; i < 512; i++) {
1413 if (new_fcf_record->vlan_bitmap[i]) {
1414 fcf_vlan_id = i * 8;
1416 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1424 /* If FCF not available return 0 */
1425 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1426 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
1429 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1431 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1433 if (phba->valid_vlan)
1434 *vlan_id = phba->vlan_id;
1436 *vlan_id = LPFC_FCOE_NULL_VID;
1441 * If there are no FCF connection table entry, driver connect to all
1444 if (list_empty(&phba->fcf_conn_rec_list)) {
1446 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1450 * When there are no FCF connect entries, use driver's default
1451 * addressing mode - FPMA.
1453 if (*addr_mode & LPFC_FCF_FPMA)
1454 *addr_mode = LPFC_FCF_FPMA;
1456 /* If FCF record report a vlan id use that vlan id */
1458 *vlan_id = fcf_vlan_id;
1460 *vlan_id = LPFC_FCOE_NULL_VID;
1464 list_for_each_entry(conn_entry,
1465 &phba->fcf_conn_rec_list, list) {
1466 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1469 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1470 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1473 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1474 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1477 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1479 * If the vlan bit map does not have the bit set for the
1480 * vlan id to be used, then it is not a match.
1482 if (!(new_fcf_record->vlan_bitmap
1483 [conn_entry->conn_rec.vlan_tag / 8] &
1484 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1489 * If connection record does not support any addressing mode,
1490 * skip the FCF record.
1492 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1493 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1497 * Check if the connection record specifies a required
1500 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1501 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1504 * If SPMA required but FCF not support this continue.
1506 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1507 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1508 new_fcf_record) & LPFC_FCF_SPMA))
1512 * If FPMA required but FCF not support this continue.
1514 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1515 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1516 new_fcf_record) & LPFC_FCF_FPMA))
1521 * This fcf record matches filtering criteria.
1523 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1529 * If user did not specify any addressing mode, or if the
1530 * prefered addressing mode specified by user is not supported
1531 * by FCF, allow fabric to pick the addressing mode.
1533 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1536 * If the user specified a required address mode, assign that
1539 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1540 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1541 *addr_mode = (conn_entry->conn_rec.flags &
1543 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1545 * If the user specified a prefered address mode, use the
1546 * addr mode only if FCF support the addr_mode.
1548 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1549 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1550 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1551 (*addr_mode & LPFC_FCF_SPMA))
1552 *addr_mode = LPFC_FCF_SPMA;
1553 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1554 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1555 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1556 (*addr_mode & LPFC_FCF_FPMA))
1557 *addr_mode = LPFC_FCF_FPMA;
1559 /* If matching connect list has a vlan id, use it */
1560 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1561 *vlan_id = conn_entry->conn_rec.vlan_tag;
1563 * If no vlan id is specified in connect list, use the vlan id
1566 else if (fcf_vlan_id)
1567 *vlan_id = fcf_vlan_id;
1569 *vlan_id = LPFC_FCOE_NULL_VID;
1578 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1579 * @phba: pointer to lpfc hba data structure.
1580 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1582 * This function check if there is any fcoe event pending while driver
1583 * scan FCF entries. If there is any pending event, it will restart the
1584 * FCF saning and return 1 else return 0.
1587 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1590 * If the Link is up and no FCoE events while in the
1591 * FCF discovery, no need to restart FCF discovery.
1593 if ((phba->link_state >= LPFC_LINK_UP) &&
1594 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1597 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1598 "2768 Pending link or FCF event during current "
1599 "handling of the previous event: link_state:x%x, "
1600 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1601 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1602 phba->fcoe_eventtag);
1604 spin_lock_irq(&phba->hbalock);
1605 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1606 spin_unlock_irq(&phba->hbalock);
1608 if (phba->link_state >= LPFC_LINK_UP) {
1609 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1610 "2780 Restart FCF table scan due to "
1611 "pending FCF event:evt_tag_at_scan:x%x, "
1612 "evt_tag_current:x%x\n",
1613 phba->fcoe_eventtag_at_fcf_scan,
1614 phba->fcoe_eventtag);
1615 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1618 * Do not continue FCF discovery and clear FCF_TS_INPROG
1621 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1622 "2833 Stop FCF discovery process due to link "
1623 "state change (x%x)\n", phba->link_state);
1624 spin_lock_irq(&phba->hbalock);
1625 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1626 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1627 spin_unlock_irq(&phba->hbalock);
1630 /* Unregister the currently registered FCF if required */
1632 spin_lock_irq(&phba->hbalock);
1633 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1634 spin_unlock_irq(&phba->hbalock);
1635 lpfc_sli4_unregister_fcf(phba);
1641 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1642 * @phba: pointer to lpfc hba data structure.
1643 * @fcf_cnt: number of eligible fcf record seen so far.
1645 * This function makes an running random selection decision on FCF record to
1646 * use through a sequence of @fcf_cnt eligible FCF records with equal
1647 * probability. To perform integer manunipulation of random numbers with
1648 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1649 * from random32() are taken as the random random number generated.
1651 * Returns true when outcome is for the newly read FCF record should be
1652 * chosen; otherwise, return false when outcome is for keeping the previously
1653 * chosen FCF record.
1656 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1660 /* Get 16-bit uniform random number */
1661 rand_num = (0xFFFF & random32());
1663 /* Decision with probability 1/fcf_cnt */
1664 if ((fcf_cnt * rand_num) < 0xFFFF)
1671 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1672 * @phba: pointer to lpfc hba data structure.
1673 * @mboxq: pointer to mailbox object.
1674 * @next_fcf_index: pointer to holder of next fcf index.
1676 * This routine parses the non-embedded fcf mailbox command by performing the
1677 * necessarily error checking, non-embedded read FCF record mailbox command
1678 * SGE parsing, and endianness swapping.
1680 * Returns the pointer to the new FCF record in the non-embedded mailbox
1681 * command DMA memory if successfully, other NULL.
1683 static struct fcf_record *
1684 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1685 uint16_t *next_fcf_index)
1688 dma_addr_t phys_addr;
1689 struct lpfc_mbx_sge sge;
1690 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1691 uint32_t shdr_status, shdr_add_status;
1692 union lpfc_sli4_cfg_shdr *shdr;
1693 struct fcf_record *new_fcf_record;
1695 /* Get the first SGE entry from the non-embedded DMA memory. This
1696 * routine only uses a single SGE.
1698 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1699 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1700 if (unlikely(!mboxq->sge_array)) {
1701 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1702 "2524 Failed to get the non-embedded SGE "
1703 "virtual address\n");
1706 virt_addr = mboxq->sge_array->addr[0];
1708 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1709 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1710 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1711 if (shdr_status || shdr_add_status) {
1712 if (shdr_status == STATUS_FCF_TABLE_EMPTY)
1713 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1714 "2726 READ_FCF_RECORD Indicates empty "
1717 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1718 "2521 READ_FCF_RECORD mailbox failed "
1719 "with status x%x add_status x%x, "
1720 "mbx\n", shdr_status, shdr_add_status);
1724 /* Interpreting the returned information of the FCF record */
1725 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1726 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1727 sizeof(struct lpfc_mbx_read_fcf_tbl));
1728 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1729 new_fcf_record = (struct fcf_record *)(virt_addr +
1730 sizeof(struct lpfc_mbx_read_fcf_tbl));
1731 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1732 offsetof(struct fcf_record, vlan_bitmap));
1733 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1734 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
1736 return new_fcf_record;
1740 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1741 * @phba: pointer to lpfc hba data structure.
1742 * @fcf_record: pointer to the fcf record.
1743 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1744 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1746 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1750 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1751 struct fcf_record *fcf_record,
1753 uint16_t next_fcf_index)
1755 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1756 "2764 READ_FCF_RECORD:\n"
1757 "\tFCF_Index : x%x\n"
1758 "\tFCF_Avail : x%x\n"
1759 "\tFCF_Valid : x%x\n"
1760 "\tFIP_Priority : x%x\n"
1761 "\tMAC_Provider : x%x\n"
1762 "\tLowest VLANID : x%x\n"
1763 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1764 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1765 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1766 "\tNext_FCF_Index: x%x\n",
1767 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1768 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1769 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1770 fcf_record->fip_priority,
1771 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1773 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1774 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1775 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1776 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1777 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1778 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1779 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1780 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1781 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1782 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1783 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1784 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1785 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1786 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1787 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1788 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1789 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1790 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1791 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1792 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1793 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1794 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1799 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1800 * @phba: pointer to lpfc hba data structure.
1801 * @fcf_rec: pointer to an existing FCF record.
1802 * @new_fcf_record: pointer to a new FCF record.
1803 * @new_vlan_id: vlan id from the new FCF record.
1805 * This function performs matching test of a new FCF record against an existing
1806 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1807 * will not be used as part of the FCF record matching criteria.
1809 * Returns true if all the fields matching, otherwise returns false.
1812 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1813 struct lpfc_fcf_rec *fcf_rec,
1814 struct fcf_record *new_fcf_record,
1815 uint16_t new_vlan_id)
1817 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1818 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1820 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1822 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1824 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1830 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1831 * @vport: Pointer to vport object.
1832 * @fcf_index: index to next fcf.
1834 * This function processing the roundrobin fcf failover to next fcf index.
1835 * When this function is invoked, there will be a current fcf registered
1837 * Return: 0 for continue retrying flogi on currently registered fcf;
1838 * 1 for stop flogi on currently registered fcf;
1840 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1842 struct lpfc_hba *phba = vport->phba;
1845 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1846 spin_lock_irq(&phba->hbalock);
1847 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1848 spin_unlock_irq(&phba->hbalock);
1849 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1850 "2872 Devloss tmo with no eligible "
1851 "FCF, unregister in-use FCF (x%x) "
1852 "and rescan FCF table\n",
1853 phba->fcf.current_rec.fcf_indx);
1854 lpfc_unregister_fcf_rescan(phba);
1855 goto stop_flogi_current_fcf;
1857 /* Mark the end to FLOGI roundrobin failover */
1858 phba->hba_flag &= ~FCF_RR_INPROG;
1859 /* Allow action to new fcf asynchronous event */
1860 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1861 spin_unlock_irq(&phba->hbalock);
1862 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1863 "2865 No FCF available, stop roundrobin FCF "
1864 "failover and change port state:x%x/x%x\n",
1865 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1866 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1867 goto stop_flogi_current_fcf;
1869 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1870 "2794 Try FLOGI roundrobin FCF failover to "
1871 "(x%x)\n", fcf_index);
1872 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1874 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1875 "2761 FLOGI roundrobin FCF failover "
1876 "failed (rc:x%x) to read FCF (x%x)\n",
1877 rc, phba->fcf.current_rec.fcf_indx);
1879 goto stop_flogi_current_fcf;
1883 stop_flogi_current_fcf:
1884 lpfc_can_disctmo(vport);
1889 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
1890 * @phba: pointer to lpfc hba data structure.
1891 * @mboxq: pointer to mailbox object.
1893 * This function iterates through all the fcf records available in
1894 * HBA and chooses the optimal FCF record for discovery. After finding
1895 * the FCF for discovery it registers the FCF record and kicks start
1897 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
1898 * use an FCF record which matches fabric name and mac address of the
1899 * currently used FCF record.
1900 * If the driver supports only one FCF, it will try to use the FCF record
1901 * used by BOOT_BIOS.
1904 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1906 struct fcf_record *new_fcf_record;
1907 uint32_t boot_flag, addr_mode;
1908 uint16_t fcf_index, next_fcf_index;
1909 struct lpfc_fcf_rec *fcf_rec = NULL;
1912 bool select_new_fcf;
1915 /* If there is pending FCoE event restart FCF table scan */
1916 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
1917 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1921 /* Parse the FCF record from the non-embedded mailbox command */
1922 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
1924 if (!new_fcf_record) {
1925 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1926 "2765 Mailbox command READ_FCF_RECORD "
1927 "failed to retrieve a FCF record.\n");
1928 /* Let next new FCF event trigger fast failover */
1929 spin_lock_irq(&phba->hbalock);
1930 phba->hba_flag &= ~FCF_TS_INPROG;
1931 spin_unlock_irq(&phba->hbalock);
1932 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1936 /* Check the FCF record against the connection list */
1937 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
1938 &addr_mode, &vlan_id);
1940 /* Log the FCF record information if turned on */
1941 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
1945 * If the fcf record does not match with connect list entries
1946 * read the next entry; otherwise, this is an eligible FCF
1947 * record for roundrobin FCF failover.
1950 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1951 "2781 FCF (x%x) failed connection "
1952 "list check: (x%x/x%x)\n",
1953 bf_get(lpfc_fcf_record_fcf_index,
1955 bf_get(lpfc_fcf_record_fcf_avail,
1957 bf_get(lpfc_fcf_record_fcf_valid,
1959 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
1960 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
1961 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
1962 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
1963 phba->fcf.current_rec.fcf_indx) {
1964 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1965 "2862 FCF (x%x) matches property "
1966 "of in-use FCF (x%x)\n",
1967 bf_get(lpfc_fcf_record_fcf_index,
1969 phba->fcf.current_rec.fcf_indx);
1973 * In case the current in-use FCF record becomes
1974 * invalid/unavailable during FCF discovery that
1975 * was not triggered by fast FCF failover process,
1976 * treat it as fast FCF failover.
1978 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
1979 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
1980 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1981 "2835 Invalid in-use FCF "
1982 "(x%x), enter FCF failover "
1984 phba->fcf.current_rec.fcf_indx);
1985 spin_lock_irq(&phba->hbalock);
1986 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
1987 spin_unlock_irq(&phba->hbalock);
1988 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1989 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
1990 LPFC_FCOE_FCF_GET_FIRST);
1996 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1997 rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
2003 * If this is not the first FCF discovery of the HBA, use last
2004 * FCF record for the discovery. The condition that a rescan
2005 * matches the in-use FCF record: fabric name, switch name, mac
2006 * address, and vlan_id.
2008 spin_lock_irq(&phba->hbalock);
2009 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2010 if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2011 new_fcf_record, vlan_id)) {
2012 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2013 phba->fcf.current_rec.fcf_indx) {
2014 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2015 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2016 /* Stop FCF redisc wait timer */
2017 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2019 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2020 /* Fast failover, mark completed */
2021 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2022 spin_unlock_irq(&phba->hbalock);
2023 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2024 "2836 New FCF matches in-use "
2026 phba->fcf.current_rec.fcf_indx);
2029 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2030 "2863 New FCF (x%x) matches "
2031 "property of in-use FCF (x%x)\n",
2032 bf_get(lpfc_fcf_record_fcf_index,
2034 phba->fcf.current_rec.fcf_indx);
2037 * Read next FCF record from HBA searching for the matching
2038 * with in-use record only if not during the fast failover
2039 * period. In case of fast failover period, it shall try to
2040 * determine whether the FCF record just read should be the
2043 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2044 spin_unlock_irq(&phba->hbalock);
2049 * Update on failover FCF record only if it's in FCF fast-failover
2050 * period; otherwise, update on current FCF record.
2052 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2053 fcf_rec = &phba->fcf.failover_rec;
2055 fcf_rec = &phba->fcf.current_rec;
2057 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2059 * If the driver FCF record does not have boot flag
2060 * set and new hba fcf record has boot flag set, use
2061 * the new hba fcf record.
2063 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2064 /* Choose this FCF record */
2065 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2066 "2837 Update current FCF record "
2067 "(x%x) with new FCF record (x%x)\n",
2069 bf_get(lpfc_fcf_record_fcf_index,
2071 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2072 addr_mode, vlan_id, BOOT_ENABLE);
2073 spin_unlock_irq(&phba->hbalock);
2077 * If the driver FCF record has boot flag set and the
2078 * new hba FCF record does not have boot flag, read
2079 * the next FCF record.
2081 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2082 spin_unlock_irq(&phba->hbalock);
2086 * If the new hba FCF record has lower priority value
2087 * than the driver FCF record, use the new record.
2089 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2090 /* Choose the new FCF record with lower priority */
2091 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2092 "2838 Update current FCF record "
2093 "(x%x) with new FCF record (x%x)\n",
2095 bf_get(lpfc_fcf_record_fcf_index,
2097 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2098 addr_mode, vlan_id, 0);
2099 /* Reset running random FCF selection count */
2100 phba->fcf.eligible_fcf_cnt = 1;
2101 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2102 /* Update running random FCF selection count */
2103 phba->fcf.eligible_fcf_cnt++;
2104 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2105 phba->fcf.eligible_fcf_cnt);
2106 if (select_new_fcf) {
2107 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2108 "2839 Update current FCF record "
2109 "(x%x) with new FCF record (x%x)\n",
2111 bf_get(lpfc_fcf_record_fcf_index,
2113 /* Choose the new FCF by random selection */
2114 __lpfc_update_fcf_record(phba, fcf_rec,
2116 addr_mode, vlan_id, 0);
2119 spin_unlock_irq(&phba->hbalock);
2123 * This is the first suitable FCF record, choose this record for
2124 * initial best-fit FCF.
2127 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2128 "2840 Update initial FCF candidate "
2130 bf_get(lpfc_fcf_record_fcf_index,
2132 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2133 addr_mode, vlan_id, (boot_flag ?
2135 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2136 /* Setup initial running random FCF selection count */
2137 phba->fcf.eligible_fcf_cnt = 1;
2138 /* Seeding the random number generator for random selection */
2139 seed = (uint32_t)(0xFFFFFFFF & jiffies);
2142 spin_unlock_irq(&phba->hbalock);
2146 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2147 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2148 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2150 * Case of FCF fast failover scan
2154 * It has not found any suitable FCF record, cancel
2155 * FCF scan inprogress, and do nothing
2157 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2158 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2159 "2782 No suitable FCF found: "
2161 phba->fcoe_eventtag_at_fcf_scan,
2162 bf_get(lpfc_fcf_record_fcf_index,
2164 spin_lock_irq(&phba->hbalock);
2165 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2166 phba->hba_flag &= ~FCF_TS_INPROG;
2167 spin_unlock_irq(&phba->hbalock);
2168 /* Unregister in-use FCF and rescan */
2169 lpfc_printf_log(phba, KERN_INFO,
2171 "2864 On devloss tmo "
2172 "unreg in-use FCF and "
2173 "rescan FCF table\n");
2174 lpfc_unregister_fcf_rescan(phba);
2178 * Let next new FCF event trigger fast failover
2180 phba->hba_flag &= ~FCF_TS_INPROG;
2181 spin_unlock_irq(&phba->hbalock);
2185 * It has found a suitable FCF record that is not
2186 * the same as in-use FCF record, unregister the
2187 * in-use FCF record, replace the in-use FCF record
2188 * with the new FCF record, mark FCF fast failover
2189 * completed, and then start register the new FCF
2193 /* Unregister the current in-use FCF record */
2194 lpfc_unregister_fcf(phba);
2196 /* Replace in-use record with the new record */
2197 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2198 "2842 Replace in-use FCF (x%x) "
2199 "with failover FCF (x%x)\n",
2200 phba->fcf.current_rec.fcf_indx,
2201 phba->fcf.failover_rec.fcf_indx);
2202 memcpy(&phba->fcf.current_rec,
2203 &phba->fcf.failover_rec,
2204 sizeof(struct lpfc_fcf_rec));
2206 * Mark the fast FCF failover rediscovery completed
2207 * and the start of the first round of the roundrobin
2210 spin_lock_irq(&phba->hbalock);
2211 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2212 spin_unlock_irq(&phba->hbalock);
2213 /* Register to the new FCF record */
2214 lpfc_register_fcf(phba);
2217 * In case of transaction period to fast FCF failover,
2218 * do nothing when search to the end of the FCF table.
2220 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2221 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2224 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2226 * In case the current in-use FCF record no
2227 * longer existed during FCF discovery that
2228 * was not triggered by fast FCF failover
2229 * process, treat it as fast FCF failover.
2231 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2232 "2841 In-use FCF record (x%x) "
2233 "not reported, entering fast "
2234 "FCF failover mode scanning.\n",
2235 phba->fcf.current_rec.fcf_indx);
2236 spin_lock_irq(&phba->hbalock);
2237 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2238 spin_unlock_irq(&phba->hbalock);
2239 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2240 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2241 LPFC_FCOE_FCF_GET_FIRST);
2244 /* Register to the new FCF record */
2245 lpfc_register_fcf(phba);
2248 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2252 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2253 lpfc_register_fcf(phba);
2259 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2260 * @phba: pointer to lpfc hba data structure.
2261 * @mboxq: pointer to mailbox object.
2263 * This is the callback function for FLOGI failure roundrobin FCF failover
2264 * read FCF record mailbox command from the eligible FCF record bmask for
2265 * performing the failover. If the FCF read back is not valid/available, it
2266 * fails through to retrying FLOGI to the currently registered FCF again.
2267 * Otherwise, if the FCF read back is valid and available, it will set the
2268 * newly read FCF record to the failover FCF record, unregister currently
2269 * registered FCF record, copy the failover FCF record to the current
2270 * FCF record, and then register the current FCF record before proceeding
2271 * to trying FLOGI on the new failover FCF.
2274 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2276 struct fcf_record *new_fcf_record;
2277 uint32_t boot_flag, addr_mode;
2278 uint16_t next_fcf_index, fcf_index;
2279 uint16_t current_fcf_index;
2283 /* If link state is not up, stop the roundrobin failover process */
2284 if (phba->link_state < LPFC_LINK_UP) {
2285 spin_lock_irq(&phba->hbalock);
2286 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2287 phba->hba_flag &= ~FCF_RR_INPROG;
2288 spin_unlock_irq(&phba->hbalock);
2292 /* Parse the FCF record from the non-embedded mailbox command */
2293 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2295 if (!new_fcf_record) {
2296 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2297 "2766 Mailbox command READ_FCF_RECORD "
2298 "failed to retrieve a FCF record.\n");
2302 /* Get the needed parameters from FCF record */
2303 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2304 &addr_mode, &vlan_id);
2306 /* Log the FCF record information if turned on */
2307 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2310 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2312 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2313 "2848 Remove ineligible FCF (x%x) from "
2314 "from roundrobin bmask\n", fcf_index);
2315 /* Clear roundrobin bmask bit for ineligible FCF */
2316 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2317 /* Perform next round of roundrobin FCF failover */
2318 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2319 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2325 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2326 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2327 "2760 Perform FLOGI roundrobin FCF failover: "
2328 "FCF (x%x) back to FCF (x%x)\n",
2329 phba->fcf.current_rec.fcf_indx, fcf_index);
2330 /* Wait 500 ms before retrying FLOGI to current FCF */
2332 lpfc_initial_flogi(phba->pport);
2336 /* Upload new FCF record to the failover FCF record */
2337 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2338 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2339 phba->fcf.failover_rec.fcf_indx, fcf_index);
2340 spin_lock_irq(&phba->hbalock);
2341 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2342 new_fcf_record, addr_mode, vlan_id,
2343 (boot_flag ? BOOT_ENABLE : 0));
2344 spin_unlock_irq(&phba->hbalock);
2346 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2348 /* Unregister the current in-use FCF record */
2349 lpfc_unregister_fcf(phba);
2351 /* Replace in-use record with the new record */
2352 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2353 sizeof(struct lpfc_fcf_rec));
2355 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2356 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2357 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2360 lpfc_register_fcf(phba);
2362 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2366 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2367 * @phba: pointer to lpfc hba data structure.
2368 * @mboxq: pointer to mailbox object.
2370 * This is the callback function of read FCF record mailbox command for
2371 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2372 * failover when a new FCF event happened. If the FCF read back is
2373 * valid/available and it passes the connection list check, it updates
2374 * the bmask for the eligible FCF record for roundrobin failover.
2377 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2379 struct fcf_record *new_fcf_record;
2380 uint32_t boot_flag, addr_mode;
2381 uint16_t fcf_index, next_fcf_index;
2385 /* If link state is not up, no need to proceed */
2386 if (phba->link_state < LPFC_LINK_UP)
2389 /* If FCF discovery period is over, no need to proceed */
2390 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2393 /* Parse the FCF record from the non-embedded mailbox command */
2394 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2396 if (!new_fcf_record) {
2397 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2398 "2767 Mailbox command READ_FCF_RECORD "
2399 "failed to retrieve a FCF record.\n");
2403 /* Check the connection list for eligibility */
2404 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2405 &addr_mode, &vlan_id);
2407 /* Log the FCF record information if turned on */
2408 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2414 /* Update the eligible FCF record index bmask */
2415 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2416 rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
2419 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2423 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2424 * @phba: pointer to lpfc hba data structure.
2425 * @mboxq: pointer to mailbox data structure.
2427 * This function handles completion of init vpi mailbox command.
2430 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2432 struct lpfc_vport *vport = mboxq->vport;
2433 struct lpfc_nodelist *ndlp;
2434 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2436 if (mboxq->u.mb.mbxStatus) {
2437 lpfc_printf_vlog(vport, KERN_ERR,
2439 "2609 Init VPI mailbox failed 0x%x\n",
2440 mboxq->u.mb.mbxStatus);
2441 mempool_free(mboxq, phba->mbox_mem_pool);
2442 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2445 spin_lock_irq(shost->host_lock);
2446 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2447 spin_unlock_irq(shost->host_lock);
2449 /* If this port is physical port or FDISC is done, do reg_vpi */
2450 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2451 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2453 lpfc_printf_vlog(vport, KERN_ERR,
2455 "2731 Cannot find fabric "
2456 "controller node\n");
2458 lpfc_register_new_vport(phba, vport, ndlp);
2459 mempool_free(mboxq, phba->mbox_mem_pool);
2463 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2464 lpfc_initial_fdisc(vport);
2466 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
2467 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2468 "2606 No NPIV Fabric support\n");
2470 mempool_free(mboxq, phba->mbox_mem_pool);
2475 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2476 * @vport: pointer to lpfc_vport data structure.
2478 * This function issue a init_vpi mailbox command to initialize
2479 * VPI for the vport.
2482 lpfc_issue_init_vpi(struct lpfc_vport *vport)
2484 LPFC_MBOXQ_t *mboxq;
2487 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2489 lpfc_printf_vlog(vport, KERN_ERR,
2490 LOG_MBOX, "2607 Failed to allocate "
2491 "init_vpi mailbox\n");
2494 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2495 mboxq->vport = vport;
2496 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2497 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2498 if (rc == MBX_NOT_FINISHED) {
2499 lpfc_printf_vlog(vport, KERN_ERR,
2500 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2501 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2506 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2507 * @phba: pointer to lpfc hba data structure.
2509 * This function loops through the list of vports on the @phba and issues an
2510 * FDISC if possible.
2513 lpfc_start_fdiscs(struct lpfc_hba *phba)
2515 struct lpfc_vport **vports;
2518 vports = lpfc_create_vport_work_array(phba);
2519 if (vports != NULL) {
2520 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2521 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2523 /* There are no vpi for this vport */
2524 if (vports[i]->vpi > phba->max_vpi) {
2525 lpfc_vport_set_state(vports[i],
2529 if (phba->fc_topology == TOPOLOGY_LOOP) {
2530 lpfc_vport_set_state(vports[i],
2534 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
2535 lpfc_issue_init_vpi(vports[i]);
2538 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2539 lpfc_initial_fdisc(vports[i]);
2541 lpfc_vport_set_state(vports[i],
2542 FC_VPORT_NO_FABRIC_SUPP);
2543 lpfc_printf_vlog(vports[i], KERN_ERR,
2546 "Fabric support\n");
2550 lpfc_destroy_vport_work_array(phba, vports);
2554 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2556 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2557 struct lpfc_vport *vport = mboxq->vport;
2558 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2560 if (mboxq->u.mb.mbxStatus) {
2561 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2562 "2018 REG_VFI mbxStatus error x%x "
2564 mboxq->u.mb.mbxStatus, vport->port_state);
2565 if (phba->fc_topology == TOPOLOGY_LOOP) {
2566 /* FLOGI failed, use loop map to make discovery list */
2567 lpfc_disc_list_loopmap(vport);
2568 /* Start discovery */
2569 lpfc_disc_start(vport);
2572 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2575 /* The VPI is implicitly registered when the VFI is registered */
2576 spin_lock_irq(shost->host_lock);
2577 vport->vpi_state |= LPFC_VPI_REGISTERED;
2578 vport->fc_flag |= FC_VFI_REGISTERED;
2579 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2580 spin_unlock_irq(shost->host_lock);
2582 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
2583 lpfc_start_fdiscs(phba);
2584 lpfc_do_scr_ns_plogi(phba, vport);
2588 mempool_free(mboxq, phba->mbox_mem_pool);
2589 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2595 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2597 MAILBOX_t *mb = &pmb->u.mb;
2598 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
2599 struct lpfc_vport *vport = pmb->vport;
2602 /* Check for error */
2603 if (mb->mbxStatus) {
2604 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
2605 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2606 "0319 READ_SPARAM mbxStatus error x%x "
2608 mb->mbxStatus, vport->port_state);
2609 lpfc_linkdown(phba);
2613 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
2614 sizeof (struct serv_parm));
2615 if (phba->cfg_soft_wwnn)
2616 u64_to_wwn(phba->cfg_soft_wwnn,
2617 vport->fc_sparam.nodeName.u.wwn);
2618 if (phba->cfg_soft_wwpn)
2619 u64_to_wwn(phba->cfg_soft_wwpn,
2620 vport->fc_sparam.portName.u.wwn);
2621 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
2622 sizeof(vport->fc_nodename));
2623 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
2624 sizeof(vport->fc_portname));
2625 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2626 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
2627 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
2630 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2632 mempool_free(pmb, phba->mbox_mem_pool);
2636 pmb->context1 = NULL;
2637 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2639 lpfc_issue_clear_la(phba, vport);
2640 mempool_free(pmb, phba->mbox_mem_pool);
2645 lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
2647 struct lpfc_vport *vport = phba->pport;
2648 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
2650 struct lpfc_dmabuf *mp;
2652 struct fcf_record *fcf_record;
2654 spin_lock_irq(&phba->hbalock);
2655 switch (la->UlnkSpeed) {
2657 phba->fc_linkspeed = LA_1GHZ_LINK;
2660 phba->fc_linkspeed = LA_2GHZ_LINK;
2663 phba->fc_linkspeed = LA_4GHZ_LINK;
2666 phba->fc_linkspeed = LA_8GHZ_LINK;
2669 phba->fc_linkspeed = LA_10GHZ_LINK;
2672 phba->fc_linkspeed = LA_UNKNW_LINK;
2676 phba->fc_topology = la->topology;
2677 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
2679 if (phba->fc_topology == TOPOLOGY_LOOP) {
2680 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
2682 /* if npiv is enabled and this adapter supports npiv log
2683 * a message that npiv is not supported in this topology
2685 if (phba->cfg_enable_npiv && phba->max_vpi)
2686 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2687 "1309 Link Up Event npiv not supported in loop "
2689 /* Get Loop Map information */
2691 vport->fc_flag |= FC_LBIT;
2693 vport->fc_myDID = la->granted_AL_PA;
2694 i = la->un.lilpBde64.tus.f.bdeSize;
2697 phba->alpa_map[0] = 0;
2699 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
2710 numalpa = phba->alpa_map[0];
2712 while (j < numalpa) {
2713 memset(un.pamap, 0, 16);
2714 for (k = 1; j < numalpa; k++) {
2716 phba->alpa_map[j + 1];
2721 /* Link Up Event ALPA map */
2722 lpfc_printf_log(phba,
2725 "1304 Link Up Event "
2726 "ALPA map Data: x%x "
2728 un.pa.wd1, un.pa.wd2,
2729 un.pa.wd3, un.pa.wd4);
2734 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
2735 if (phba->max_vpi && phba->cfg_enable_npiv &&
2736 (phba->sli_rev == 3))
2737 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
2739 vport->fc_myDID = phba->fc_pref_DID;
2740 vport->fc_flag |= FC_LBIT;
2742 spin_unlock_irq(&phba->hbalock);
2745 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2749 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
2751 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2754 sparam_mbox->vport = vport;
2755 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
2756 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
2757 if (rc == MBX_NOT_FINISHED) {
2758 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
2759 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2761 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2765 if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) {
2766 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2769 vport->port_state = LPFC_LOCAL_CFG_LINK;
2770 lpfc_config_link(phba, cfglink_mbox);
2771 cfglink_mbox->vport = vport;
2772 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
2773 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
2774 if (rc == MBX_NOT_FINISHED) {
2775 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
2779 vport->port_state = LPFC_VPORT_UNKNOWN;
2781 * Add the driver's default FCF record at FCF index 0 now. This
2782 * is phase 1 implementation that support FCF index 0 and driver
2785 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
2786 fcf_record = kzalloc(sizeof(struct fcf_record),
2788 if (unlikely(!fcf_record)) {
2789 lpfc_printf_log(phba, KERN_ERR,
2791 "2554 Could not allocate memmory for "
2797 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
2798 LPFC_FCOE_FCF_DEF_INDEX);
2799 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
2801 lpfc_printf_log(phba, KERN_ERR,
2803 "2013 Could not manually add FCF "
2804 "record 0, status %d\n", rc);
2812 * The driver is expected to do FIP/FCF. Call the port
2813 * and get the FCF Table.
2815 spin_lock_irq(&phba->hbalock);
2816 if (phba->hba_flag & FCF_TS_INPROG) {
2817 spin_unlock_irq(&phba->hbalock);
2820 /* This is the initial FCF discovery scan */
2821 phba->fcf.fcf_flag |= FCF_INIT_DISC;
2822 spin_unlock_irq(&phba->hbalock);
2823 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2824 "2778 Start FCF table scan at linkup\n");
2825 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2826 LPFC_FCOE_FCF_GET_FIRST);
2828 spin_lock_irq(&phba->hbalock);
2829 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
2830 spin_unlock_irq(&phba->hbalock);
2833 /* Reset FCF roundrobin bmask for new discovery */
2834 memset(phba->fcf.fcf_rr_bmask, 0,
2835 sizeof(*phba->fcf.fcf_rr_bmask));
2840 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2841 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2842 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2843 vport->port_state, sparam_mbox, cfglink_mbox);
2844 lpfc_issue_clear_la(phba, vport);
2849 lpfc_enable_la(struct lpfc_hba *phba)
2852 struct lpfc_sli *psli = &phba->sli;
2853 spin_lock_irq(&phba->hbalock);
2854 psli->sli_flag |= LPFC_PROCESS_LA;
2855 if (phba->sli_rev <= LPFC_SLI_REV3) {
2856 control = readl(phba->HCregaddr);
2857 control |= HC_LAINT_ENA;
2858 writel(control, phba->HCregaddr);
2859 readl(phba->HCregaddr); /* flush */
2861 spin_unlock_irq(&phba->hbalock);
2865 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
2867 lpfc_linkdown(phba);
2868 lpfc_enable_la(phba);
2869 lpfc_unregister_unused_fcf(phba);
2870 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2875 * This routine handles processing a READ_LA mailbox
2876 * command upon completion. It is setup in the LPFC_MBOXQ
2877 * as the completion routine when the command is
2878 * handed off to the SLI layer.
2881 lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2883 struct lpfc_vport *vport = pmb->vport;
2884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2886 MAILBOX_t *mb = &pmb->u.mb;
2887 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2889 /* Unblock ELS traffic */
2890 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
2891 /* Check for error */
2892 if (mb->mbxStatus) {
2893 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
2894 "1307 READ_LA mbox error x%x state x%x\n",
2895 mb->mbxStatus, vport->port_state);
2896 lpfc_mbx_issue_link_down(phba);
2897 phba->link_state = LPFC_HBA_ERROR;
2898 goto lpfc_mbx_cmpl_read_la_free_mbuf;
2901 la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
2903 memcpy(&phba->alpa_map[0], mp->virt, 128);
2905 spin_lock_irq(shost->host_lock);
2907 vport->fc_flag |= FC_BYPASSED_MODE;
2909 vport->fc_flag &= ~FC_BYPASSED_MODE;
2910 spin_unlock_irq(shost->host_lock);
2912 if ((phba->fc_eventTag < la->eventTag) ||
2913 (phba->fc_eventTag == la->eventTag)) {
2914 phba->fc_stat.LinkMultiEvent++;
2915 if (la->attType == AT_LINK_UP)
2916 if (phba->fc_eventTag != 0)
2917 lpfc_linkdown(phba);
2920 phba->fc_eventTag = la->eventTag;
2921 spin_lock_irq(&phba->hbalock);
2923 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
2925 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
2926 spin_unlock_irq(&phba->hbalock);
2928 phba->link_events++;
2929 if (la->attType == AT_LINK_UP && (!la->mm)) {
2930 phba->fc_stat.LinkUp++;
2931 if (phba->link_flag & LS_LOOPBACK_MODE) {
2932 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2933 "1306 Link Up Event in loop back mode "
2934 "x%x received Data: x%x x%x x%x x%x\n",
2935 la->eventTag, phba->fc_eventTag,
2936 la->granted_AL_PA, la->UlnkSpeed,
2939 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2940 "1303 Link Up Event x%x received "
2941 "Data: x%x x%x x%x x%x x%x x%x %d\n",
2942 la->eventTag, phba->fc_eventTag,
2943 la->granted_AL_PA, la->UlnkSpeed,
2946 phba->wait_4_mlo_maint_flg);
2948 lpfc_mbx_process_link_up(phba, la);
2949 } else if (la->attType == AT_LINK_DOWN) {
2950 phba->fc_stat.LinkDown++;
2951 if (phba->link_flag & LS_LOOPBACK_MODE) {
2952 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2953 "1308 Link Down Event in loop back mode "
2955 "Data: x%x x%x x%x\n",
2956 la->eventTag, phba->fc_eventTag,
2957 phba->pport->port_state, vport->fc_flag);
2960 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2961 "1305 Link Down Event x%x received "
2962 "Data: x%x x%x x%x x%x x%x\n",
2963 la->eventTag, phba->fc_eventTag,
2964 phba->pport->port_state, vport->fc_flag,
2967 lpfc_mbx_issue_link_down(phba);
2969 if (la->mm && la->attType == AT_LINK_UP) {
2970 if (phba->link_state != LPFC_LINK_DOWN) {
2971 phba->fc_stat.LinkDown++;
2972 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2973 "1312 Link Down Event x%x received "
2974 "Data: x%x x%x x%x\n",
2975 la->eventTag, phba->fc_eventTag,
2976 phba->pport->port_state, vport->fc_flag);
2977 lpfc_mbx_issue_link_down(phba);
2979 lpfc_enable_la(phba);
2981 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2982 "1310 Menlo Maint Mode Link up Event x%x rcvd "
2983 "Data: x%x x%x x%x\n",
2984 la->eventTag, phba->fc_eventTag,
2985 phba->pport->port_state, vport->fc_flag);
2987 * The cmnd that triggered this will be waiting for this
2990 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
2991 if (phba->wait_4_mlo_maint_flg) {
2992 phba->wait_4_mlo_maint_flg = 0;
2993 wake_up_interruptible(&phba->wait_4_mlo_m_q);
2999 lpfc_issue_clear_la(phba, vport);
3000 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3001 "1311 fa %d\n", la->fa);
3004 lpfc_mbx_cmpl_read_la_free_mbuf:
3005 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3007 mempool_free(pmb, phba->mbox_mem_pool);
3012 * This routine handles processing a REG_LOGIN mailbox
3013 * command upon completion. It is setup in the LPFC_MBOXQ
3014 * as the completion routine when the command is
3015 * handed off to the SLI layer.
3018 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3020 struct lpfc_vport *vport = pmb->vport;
3021 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3022 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3023 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3025 pmb->context1 = NULL;
3026 pmb->context2 = NULL;
3028 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3029 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3031 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3032 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3033 /* We rcvd a rscn after issuing this
3034 * mbox reg login, we may have cycled
3035 * back through the state and be
3036 * back at reg login state so this
3037 * mbox needs to be ignored becase
3038 * there is another reg login in
3041 spin_lock_irq(shost->host_lock);
3042 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3043 spin_unlock_irq(shost->host_lock);
3044 if (phba->sli_rev == LPFC_SLI_REV4)
3045 lpfc_sli4_free_rpi(phba,
3046 pmb->u.mb.un.varRegLogin.rpi);
3049 /* Good status, call state machine */
3050 lpfc_disc_state_machine(vport, ndlp, pmb,
3051 NLP_EVT_CMPL_REG_LOGIN);
3053 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3055 mempool_free(pmb, phba->mbox_mem_pool);
3056 /* decrement the node reference count held for this callback
3065 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3067 MAILBOX_t *mb = &pmb->u.mb;
3068 struct lpfc_vport *vport = pmb->vport;
3069 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3071 switch (mb->mbxStatus) {
3074 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3075 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3078 /* If VPI is busy, reset the HBA */
3080 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3081 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3082 vport->vpi, mb->mbxStatus);
3083 if (!(phba->pport->load_flag & FC_UNLOADING))
3084 lpfc_workq_post_event(phba, NULL, NULL,
3085 LPFC_EVT_RESET_HBA);
3087 spin_lock_irq(shost->host_lock);
3088 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3089 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3090 spin_unlock_irq(shost->host_lock);
3091 vport->unreg_vpi_cmpl = VPORT_OK;
3092 mempool_free(pmb, phba->mbox_mem_pool);
3094 * This shost reference might have been taken at the beginning of
3095 * lpfc_vport_delete()
3097 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3098 scsi_host_put(shost);
3102 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3104 struct lpfc_hba *phba = vport->phba;
3108 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3112 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3113 mbox->vport = vport;
3114 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3115 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3116 if (rc == MBX_NOT_FINISHED) {
3117 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3118 "1800 Could not issue unreg_vpi\n");
3119 mempool_free(mbox, phba->mbox_mem_pool);
3120 vport->unreg_vpi_cmpl = VPORT_ERROR;
3127 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3129 struct lpfc_vport *vport = pmb->vport;
3130 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3131 MAILBOX_t *mb = &pmb->u.mb;
3133 switch (mb->mbxStatus) {
3137 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3138 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3140 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3141 spin_lock_irq(shost->host_lock);
3142 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3143 spin_unlock_irq(shost->host_lock);
3144 vport->fc_myDID = 0;
3148 spin_lock_irq(shost->host_lock);
3149 vport->vpi_state |= LPFC_VPI_REGISTERED;
3150 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3151 spin_unlock_irq(shost->host_lock);
3152 vport->num_disc_nodes = 0;
3153 /* go thru NPR list and issue ELS PLOGIs */
3154 if (vport->fc_npr_cnt)
3155 lpfc_els_disc_plogi(vport);
3157 if (!vport->num_disc_nodes) {
3158 spin_lock_irq(shost->host_lock);
3159 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3160 spin_unlock_irq(shost->host_lock);
3161 lpfc_can_disctmo(vport);
3163 vport->port_state = LPFC_VPORT_READY;
3166 mempool_free(pmb, phba->mbox_mem_pool);
3171 * lpfc_create_static_vport - Read HBA config region to create static vports.
3172 * @phba: pointer to lpfc hba data structure.
3174 * This routine issue a DUMP mailbox command for config region 22 to get
3175 * the list of static vports to be created. The function create vports
3176 * based on the information returned from the HBA.
3179 lpfc_create_static_vport(struct lpfc_hba *phba)
3181 LPFC_MBOXQ_t *pmb = NULL;
3183 struct static_vport_info *vport_info;
3185 struct fc_vport_identifiers vport_id;
3186 struct fc_vport *new_fc_vport;
3187 struct Scsi_Host *shost;
3188 struct lpfc_vport *vport;
3189 uint16_t offset = 0;
3190 uint8_t *vport_buff;
3191 struct lpfc_dmabuf *mp;
3192 uint32_t byte_count = 0;
3194 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3196 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3197 "0542 lpfc_create_static_vport failed to"
3198 " allocate mailbox memory\n");
3204 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3206 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3207 "0543 lpfc_create_static_vport failed to"
3208 " allocate vport_info\n");
3209 mempool_free(pmb, phba->mbox_mem_pool);
3213 vport_buff = (uint8_t *) vport_info;
3215 if (lpfc_dump_static_vport(phba, pmb, offset))
3218 pmb->vport = phba->pport;
3219 rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
3221 if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
3222 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3223 "0544 lpfc_create_static_vport failed to"
3224 " issue dump mailbox command ret 0x%x "
3230 if (phba->sli_rev == LPFC_SLI_REV4) {
3231 byte_count = pmb->u.mqe.un.mb_words[5];
3232 mp = (struct lpfc_dmabuf *) pmb->context2;
3233 if (byte_count > sizeof(struct static_vport_info) -
3235 byte_count = sizeof(struct static_vport_info)
3237 memcpy(vport_buff + offset, mp->virt, byte_count);
3238 offset += byte_count;
3240 if (mb->un.varDmp.word_cnt >
3241 sizeof(struct static_vport_info) - offset)
3242 mb->un.varDmp.word_cnt =
3243 sizeof(struct static_vport_info)
3245 byte_count = mb->un.varDmp.word_cnt;
3246 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3247 vport_buff + offset,
3250 offset += byte_count;
3253 } while (byte_count &&
3254 offset < sizeof(struct static_vport_info));
3257 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3258 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3259 != VPORT_INFO_REV)) {
3260 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3261 "0545 lpfc_create_static_vport bad"
3262 " information header 0x%x 0x%x\n",
3263 le32_to_cpu(vport_info->signature),
3264 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3269 shost = lpfc_shost_from_vport(phba->pport);
3271 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3272 memset(&vport_id, 0, sizeof(vport_id));
3273 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3274 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3275 if (!vport_id.port_name || !vport_id.node_name)
3278 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3279 vport_id.vport_type = FC_PORTTYPE_NPIV;
3280 vport_id.disable = false;
3281 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3283 if (!new_fc_vport) {
3284 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3285 "0546 lpfc_create_static_vport failed to"
3290 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3291 vport->vport_flag |= STATIC_VPORT;
3296 if (rc != MBX_TIMEOUT) {
3297 if (pmb->context2) {
3298 mp = (struct lpfc_dmabuf *) pmb->context2;
3299 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3302 mempool_free(pmb, phba->mbox_mem_pool);
3309 * This routine handles processing a Fabric REG_LOGIN mailbox
3310 * command upon completion. It is setup in the LPFC_MBOXQ
3311 * as the completion routine when the command is
3312 * handed off to the SLI layer.
3315 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3317 struct lpfc_vport *vport = pmb->vport;
3318 MAILBOX_t *mb = &pmb->u.mb;
3319 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3320 struct lpfc_nodelist *ndlp;
3322 ndlp = (struct lpfc_nodelist *) pmb->context2;
3323 pmb->context1 = NULL;
3324 pmb->context2 = NULL;
3326 if (mb->mbxStatus) {
3327 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3328 "0258 Register Fabric login error: 0x%x\n",
3330 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3332 mempool_free(pmb, phba->mbox_mem_pool);
3334 if (phba->fc_topology == TOPOLOGY_LOOP) {
3335 /* FLOGI failed, use loop map to make discovery list */
3336 lpfc_disc_list_loopmap(vport);
3338 /* Start discovery */
3339 lpfc_disc_start(vport);
3340 /* Decrement the reference count to ndlp after the
3341 * reference to the ndlp are done.
3347 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3348 /* Decrement the reference count to ndlp after the reference
3349 * to the ndlp are done.
3355 ndlp->nlp_rpi = mb->un.varWords[0];
3356 ndlp->nlp_flag |= NLP_RPI_VALID;
3357 ndlp->nlp_type |= NLP_FABRIC;
3358 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3360 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3361 /* when physical port receive logo donot start
3362 * vport discovery */
3363 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3364 lpfc_start_fdiscs(phba);
3366 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
3367 lpfc_do_scr_ns_plogi(phba, vport);
3370 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3372 mempool_free(pmb, phba->mbox_mem_pool);
3374 /* Drop the reference count from the mbox at the end after
3375 * all the current reference to the ndlp have been done.
3382 * This routine handles processing a NameServer REG_LOGIN mailbox
3383 * command upon completion. It is setup in the LPFC_MBOXQ
3384 * as the completion routine when the command is
3385 * handed off to the SLI layer.
3388 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3390 MAILBOX_t *mb = &pmb->u.mb;
3391 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3392 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3393 struct lpfc_vport *vport = pmb->vport;
3395 pmb->context1 = NULL;
3396 pmb->context2 = NULL;
3398 if (mb->mbxStatus) {
3400 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3401 "0260 Register NameServer error: 0x%x\n",
3403 /* decrement the node reference count held for this
3404 * callback function.
3407 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3409 mempool_free(pmb, phba->mbox_mem_pool);
3411 /* If no other thread is using the ndlp, free it */
3412 lpfc_nlp_not_used(ndlp);
3414 if (phba->fc_topology == TOPOLOGY_LOOP) {
3416 * RegLogin failed, use loop map to make discovery
3419 lpfc_disc_list_loopmap(vport);
3421 /* Start discovery */
3422 lpfc_disc_start(vport);
3425 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3429 ndlp->nlp_rpi = mb->un.varWords[0];
3430 ndlp->nlp_flag |= NLP_RPI_VALID;
3431 ndlp->nlp_type |= NLP_FABRIC;
3432 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3434 if (vport->port_state < LPFC_VPORT_READY) {
3435 /* Link up discovery requires Fabric registration. */
3436 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
3437 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3438 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3439 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3440 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3442 /* Issue SCR just before NameServer GID_FT Query */
3443 lpfc_issue_els_scr(vport, SCR_DID, 0);
3446 vport->fc_ns_retry = 0;
3447 /* Good status, issue CT Request to NameServer */
3448 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
3449 /* Cannot issue NameServer Query, so finish up discovery */
3453 /* decrement the node reference count held for this
3454 * callback function.
3457 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3459 mempool_free(pmb, phba->mbox_mem_pool);
3465 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3467 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3468 struct fc_rport *rport;
3469 struct lpfc_rport_data *rdata;
3470 struct fc_rport_identifiers rport_ids;
3471 struct lpfc_hba *phba = vport->phba;
3473 /* Remote port has reappeared. Re-register w/ FC transport */
3474 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3475 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
3476 rport_ids.port_id = ndlp->nlp_DID;
3477 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3480 * We leave our node pointer in rport->dd_data when we unregister a
3481 * FCP target port. But fc_remote_port_add zeros the space to which
3482 * rport->dd_data points. So, if we're reusing a previously
3483 * registered port, drop the reference that we took the last time we
3484 * registered the port.
3486 if (ndlp->rport && ndlp->rport->dd_data &&
3487 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
3490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3491 "rport add: did:x%x flg:x%x type x%x",
3492 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3494 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
3495 if (!rport || !get_device(&rport->dev)) {
3496 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3497 "Warning: fc_remote_port_add failed\n");
3501 /* initialize static port data */
3502 rport->maxframe_size = ndlp->nlp_maxframe;
3503 rport->supported_classes = ndlp->nlp_class_sup;
3504 rdata = rport->dd_data;
3505 rdata->pnode = lpfc_nlp_get(ndlp);
3507 if (ndlp->nlp_type & NLP_FCP_TARGET)
3508 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3509 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3510 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3513 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3514 fc_remote_port_rolechg(rport, rport_ids.roles);
3516 if ((rport->scsi_target_id != -1) &&
3517 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
3518 ndlp->nlp_sid = rport->scsi_target_id;
3524 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
3526 struct fc_rport *rport = ndlp->rport;
3528 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
3529 "rport delete: did:x%x flg:x%x type x%x",
3530 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3532 fc_remote_port_delete(rport);
3538 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
3540 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3542 spin_lock_irq(shost->host_lock);
3544 case NLP_STE_UNUSED_NODE:
3545 vport->fc_unused_cnt += count;
3547 case NLP_STE_PLOGI_ISSUE:
3548 vport->fc_plogi_cnt += count;
3550 case NLP_STE_ADISC_ISSUE:
3551 vport->fc_adisc_cnt += count;
3553 case NLP_STE_REG_LOGIN_ISSUE:
3554 vport->fc_reglogin_cnt += count;
3556 case NLP_STE_PRLI_ISSUE:
3557 vport->fc_prli_cnt += count;
3559 case NLP_STE_UNMAPPED_NODE:
3560 vport->fc_unmap_cnt += count;
3562 case NLP_STE_MAPPED_NODE:
3563 vport->fc_map_cnt += count;
3565 case NLP_STE_NPR_NODE:
3566 vport->fc_npr_cnt += count;
3569 spin_unlock_irq(shost->host_lock);
3573 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3574 int old_state, int new_state)
3576 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3578 if (new_state == NLP_STE_UNMAPPED_NODE) {
3579 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3580 ndlp->nlp_type |= NLP_FC_NODE;
3582 if (new_state == NLP_STE_MAPPED_NODE)
3583 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3584 if (new_state == NLP_STE_NPR_NODE)
3585 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
3587 /* Transport interface */
3588 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
3589 old_state == NLP_STE_UNMAPPED_NODE)) {
3590 vport->phba->nport_event_cnt++;
3591 lpfc_unregister_remote_port(ndlp);
3594 if (new_state == NLP_STE_MAPPED_NODE ||
3595 new_state == NLP_STE_UNMAPPED_NODE) {
3596 vport->phba->nport_event_cnt++;
3598 * Tell the fc transport about the port, if we haven't
3599 * already. If we have, and it's a scsi entity, be
3600 * sure to unblock any attached scsi devices
3602 lpfc_register_remote_port(vport, ndlp);
3604 if ((new_state == NLP_STE_MAPPED_NODE) &&
3605 (vport->stat_data_enabled)) {
3607 * A new target is discovered, if there is no buffer for
3608 * statistical data collection allocate buffer.
3610 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
3611 sizeof(struct lpfc_scsicmd_bkt),
3614 if (!ndlp->lat_data)
3615 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3616 "0286 lpfc_nlp_state_cleanup failed to "
3617 "allocate statistical data buffer DID "
3618 "0x%x\n", ndlp->nlp_DID);
3621 * if we added to Mapped list, but the remote port
3622 * registration failed or assigned a target id outside
3623 * our presentable range - move the node to the
3626 if (new_state == NLP_STE_MAPPED_NODE &&
3628 ndlp->rport->scsi_target_id == -1 ||
3629 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
3630 spin_lock_irq(shost->host_lock);
3631 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
3632 spin_unlock_irq(shost->host_lock);
3633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3638 lpfc_nlp_state_name(char *buffer, size_t size, int state)
3640 static char *states[] = {
3641 [NLP_STE_UNUSED_NODE] = "UNUSED",
3642 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
3643 [NLP_STE_ADISC_ISSUE] = "ADISC",
3644 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
3645 [NLP_STE_PRLI_ISSUE] = "PRLI",
3646 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
3647 [NLP_STE_MAPPED_NODE] = "MAPPED",
3648 [NLP_STE_NPR_NODE] = "NPR",
3651 if (state < NLP_STE_MAX_STATE && states[state])
3652 strlcpy(buffer, states[state], size);
3654 snprintf(buffer, size, "unknown (%d)", state);
3659 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3663 int old_state = ndlp->nlp_state;
3664 char name1[16], name2[16];
3666 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3667 "0904 NPort state transition x%06x, %s -> %s\n",
3669 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
3670 lpfc_nlp_state_name(name2, sizeof(name2), state));
3672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3673 "node statechg did:x%x old:%d ste:%d",
3674 ndlp->nlp_DID, old_state, state);
3676 if (old_state == NLP_STE_NPR_NODE &&
3677 state != NLP_STE_NPR_NODE)
3678 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3679 if (old_state == NLP_STE_UNMAPPED_NODE) {
3680 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
3681 ndlp->nlp_type &= ~NLP_FC_NODE;
3684 if (list_empty(&ndlp->nlp_listp)) {
3685 spin_lock_irq(shost->host_lock);
3686 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3687 spin_unlock_irq(shost->host_lock);
3688 } else if (old_state)
3689 lpfc_nlp_counters(vport, old_state, -1);
3691 ndlp->nlp_state = state;
3692 lpfc_nlp_counters(vport, state, 1);
3693 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
3697 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3699 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3701 if (list_empty(&ndlp->nlp_listp)) {
3702 spin_lock_irq(shost->host_lock);
3703 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3704 spin_unlock_irq(shost->host_lock);
3709 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3711 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3713 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3714 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
3715 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3716 spin_lock_irq(shost->host_lock);
3717 list_del_init(&ndlp->nlp_listp);
3718 spin_unlock_irq(shost->host_lock);
3719 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
3720 NLP_STE_UNUSED_NODE);
3724 lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3726 lpfc_cancel_retry_delay_tmo(vport, ndlp);
3727 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
3728 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3729 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
3730 NLP_STE_UNUSED_NODE);
3733 * lpfc_initialize_node - Initialize all fields of node object
3734 * @vport: Pointer to Virtual Port object.
3735 * @ndlp: Pointer to FC node object.
3736 * @did: FC_ID of the node.
3738 * This function is always called when node object need to be initialized.
3739 * It initializes all the fields of the node object. Although the reference
3740 * to phba from @ndlp can be obtained indirectly through it's reference to
3741 * @vport, a direct reference to phba is taken here by @ndlp. This is due
3742 * to the life-span of the @ndlp might go beyond the existence of @vport as
3743 * the final release of ndlp is determined by its reference count. And, the
3744 * operation on @ndlp needs the reference to phba.
3747 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3750 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
3751 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
3752 init_timer(&ndlp->nlp_delayfunc);
3753 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
3754 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
3755 ndlp->nlp_DID = did;
3756 ndlp->vport = vport;
3757 ndlp->phba = vport->phba;
3758 ndlp->nlp_sid = NLP_NO_SID;
3759 kref_init(&ndlp->kref);
3760 NLP_INT_NODE_ACT(ndlp);
3761 atomic_set(&ndlp->cmd_pending, 0);
3762 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
3765 struct lpfc_nodelist *
3766 lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3769 struct lpfc_hba *phba = vport->phba;
3771 unsigned long flags;
3776 spin_lock_irqsave(&phba->ndlp_lock, flags);
3777 /* The ndlp should not be in memory free mode */
3778 if (NLP_CHK_FREE_REQ(ndlp)) {
3779 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3780 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3781 "0277 lpfc_enable_node: ndlp:x%p "
3782 "usgmap:x%x refcnt:%d\n",
3783 (void *)ndlp, ndlp->nlp_usg_map,
3784 atomic_read(&ndlp->kref.refcount));
3787 /* The ndlp should not already be in active mode */
3788 if (NLP_CHK_NODE_ACT(ndlp)) {
3789 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3790 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3791 "0278 lpfc_enable_node: ndlp:x%p "
3792 "usgmap:x%x refcnt:%d\n",
3793 (void *)ndlp, ndlp->nlp_usg_map,
3794 atomic_read(&ndlp->kref.refcount));
3798 /* Keep the original DID */
3799 did = ndlp->nlp_DID;
3801 /* re-initialize ndlp except of ndlp linked list pointer */
3802 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
3803 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
3804 lpfc_initialize_node(vport, ndlp, did);
3806 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3808 if (state != NLP_STE_UNUSED_NODE)
3809 lpfc_nlp_set_state(vport, ndlp, state);
3811 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3812 "node enable: did:x%x",
3813 ndlp->nlp_DID, 0, 0);
3818 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3821 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
3822 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
3823 * the ndlp from the vport. The ndlp marked as UNUSED on the list
3824 * until ALL other outstanding threads have completed. We check
3825 * that the ndlp not already in the UNUSED state before we proceed.
3827 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3829 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
3835 * Start / ReStart rescue timer for Discovery / RSCN handling
3838 lpfc_set_disctmo(struct lpfc_vport *vport)
3840 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3841 struct lpfc_hba *phba = vport->phba;
3844 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
3845 /* For FAN, timeout should be greater than edtov */
3846 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
3848 /* Normal discovery timeout should be > than ELS/CT timeout
3849 * FC spec states we need 3 * ratov for CT requests
3851 tmo = ((phba->fc_ratov * 3) + 3);
3855 if (!timer_pending(&vport->fc_disctmo)) {
3856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3857 "set disc timer: tmo:x%x state:x%x flg:x%x",
3858 tmo, vport->port_state, vport->fc_flag);
3861 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
3862 spin_lock_irq(shost->host_lock);
3863 vport->fc_flag |= FC_DISC_TMO;
3864 spin_unlock_irq(shost->host_lock);
3866 /* Start Discovery Timer state <hba_state> */
3867 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3868 "0247 Start Discovery Timer state x%x "
3869 "Data: x%x x%lx x%x x%x\n",
3870 vport->port_state, tmo,
3871 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
3872 vport->fc_adisc_cnt);
3878 * Cancel rescue timer for Discovery / RSCN handling
3881 lpfc_can_disctmo(struct lpfc_vport *vport)
3883 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3884 unsigned long iflags;
3886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3887 "can disc timer: state:x%x rtry:x%x flg:x%x",
3888 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
3890 /* Turn off discovery timer if its running */
3891 if (vport->fc_flag & FC_DISC_TMO) {
3892 spin_lock_irqsave(shost->host_lock, iflags);
3893 vport->fc_flag &= ~FC_DISC_TMO;
3894 spin_unlock_irqrestore(shost->host_lock, iflags);
3895 del_timer_sync(&vport->fc_disctmo);
3896 spin_lock_irqsave(&vport->work_port_lock, iflags);
3897 vport->work_port_events &= ~WORKER_DISC_TMO;
3898 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
3901 /* Cancel Discovery Timer state <hba_state> */
3902 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3903 "0248 Cancel Discovery Timer state x%x "
3904 "Data: x%x x%x x%x\n",
3905 vport->port_state, vport->fc_flag,
3906 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
3911 * Check specified ring for outstanding IOCB on the SLI queue
3912 * Return true if iocb matches the specified nport
3915 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
3916 struct lpfc_sli_ring *pring,
3917 struct lpfc_iocbq *iocb,
3918 struct lpfc_nodelist *ndlp)
3920 struct lpfc_sli *psli = &phba->sli;
3921 IOCB_t *icmd = &iocb->iocb;
3922 struct lpfc_vport *vport = ndlp->vport;
3924 if (iocb->vport != vport)
3927 if (pring->ringno == LPFC_ELS_RING) {
3928 switch (icmd->ulpCommand) {
3929 case CMD_GEN_REQUEST64_CR:
3930 if (iocb->context_un.ndlp == ndlp)
3932 case CMD_ELS_REQUEST64_CR:
3933 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
3935 case CMD_XMIT_ELS_RSP64_CX:
3936 if (iocb->context1 == (uint8_t *) ndlp)
3939 } else if (pring->ringno == psli->extra_ring) {
3941 } else if (pring->ringno == psli->fcp_ring) {
3942 /* Skip match check if waiting to relogin to FCP target */
3943 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3944 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
3947 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
3950 } else if (pring->ringno == psli->next_ring) {
3957 * Free resources / clean up outstanding I/Os
3958 * associated with nlp_rpi in the LPFC_NODELIST entry.
3961 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
3963 LIST_HEAD(completions);
3964 struct lpfc_sli *psli;
3965 struct lpfc_sli_ring *pring;
3966 struct lpfc_iocbq *iocb, *next_iocb;
3969 lpfc_fabric_abort_nport(ndlp);
3972 * Everything that matches on txcmplq will be returned
3973 * by firmware with a no rpi error.
3976 if (ndlp->nlp_flag & NLP_RPI_VALID) {
3977 /* Now process each ring */
3978 for (i = 0; i < psli->num_rings; i++) {
3979 pring = &psli->ring[i];
3981 spin_lock_irq(&phba->hbalock);
3982 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
3985 * Check to see if iocb matches the nport we are
3988 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
3990 /* It matches, so deque and call compl
3992 list_move_tail(&iocb->list,
3997 spin_unlock_irq(&phba->hbalock);
4001 /* Cancel all the IOCBs from the completions list */
4002 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4009 * Free rpi associated with LPFC_NODELIST entry.
4010 * This routine is called from lpfc_freenode(), when we are removing
4011 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4012 * LOGO that completes successfully, and we are waiting to PLOGI back
4013 * to the remote NPort. In addition, it is called after we receive
4014 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4015 * we are waiting to PLOGI back to the remote NPort.
4018 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4020 struct lpfc_hba *phba = vport->phba;
4024 if (ndlp->nlp_flag & NLP_RPI_VALID) {
4025 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4027 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
4028 mbox->vport = vport;
4029 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4030 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4031 if (rc == MBX_NOT_FINISHED)
4032 mempool_free(mbox, phba->mbox_mem_pool);
4034 lpfc_no_rpi(phba, ndlp);
4037 ndlp->nlp_flag &= ~NLP_RPI_VALID;
4038 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4045 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4046 * @phba: pointer to lpfc hba data structure.
4048 * This routine is invoked to unregister all the currently registered RPIs
4052 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4054 struct lpfc_vport **vports;
4055 struct lpfc_nodelist *ndlp;
4056 struct Scsi_Host *shost;
4059 vports = lpfc_create_vport_work_array(phba);
4060 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4061 shost = lpfc_shost_from_vport(vports[i]);
4062 spin_lock_irq(shost->host_lock);
4063 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
4064 if (ndlp->nlp_flag & NLP_RPI_VALID) {
4065 /* The mempool_alloc might sleep */
4066 spin_unlock_irq(shost->host_lock);
4067 lpfc_unreg_rpi(vports[i], ndlp);
4068 spin_lock_irq(shost->host_lock);
4071 spin_unlock_irq(shost->host_lock);
4073 lpfc_destroy_vport_work_array(phba, vports);
4077 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4079 struct lpfc_hba *phba = vport->phba;
4083 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4085 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
4086 mbox->vport = vport;
4087 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4088 mbox->context1 = NULL;
4089 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4090 if (rc != MBX_TIMEOUT)
4091 mempool_free(mbox, phba->mbox_mem_pool);
4093 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4094 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4095 "1836 Could not issue "
4096 "unreg_login(all_rpis) status %d\n", rc);
4101 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4103 struct lpfc_hba *phba = vport->phba;
4107 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4109 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
4110 mbox->vport = vport;
4111 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4112 mbox->context1 = NULL;
4113 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4114 if (rc != MBX_TIMEOUT)
4115 mempool_free(mbox, phba->mbox_mem_pool);
4117 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4118 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4119 "1815 Could not issue "
4120 "unreg_did (default rpis) status %d\n",
4126 * Free resources associated with LPFC_NODELIST entry
4127 * so it can be freed.
4130 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4132 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4133 struct lpfc_hba *phba = vport->phba;
4134 LPFC_MBOXQ_t *mb, *nextmb;
4135 struct lpfc_dmabuf *mp;
4137 /* Cleanup node for NPort <nlp_DID> */
4138 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4139 "0900 Cleanup node for NPort x%x "
4140 "Data: x%x x%x x%x\n",
4141 ndlp->nlp_DID, ndlp->nlp_flag,
4142 ndlp->nlp_state, ndlp->nlp_rpi);
4143 if (NLP_CHK_FREE_REQ(ndlp)) {
4144 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4145 "0280 lpfc_cleanup_node: ndlp:x%p "
4146 "usgmap:x%x refcnt:%d\n",
4147 (void *)ndlp, ndlp->nlp_usg_map,
4148 atomic_read(&ndlp->kref.refcount));
4149 lpfc_dequeue_node(vport, ndlp);
4151 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4152 "0281 lpfc_cleanup_node: ndlp:x%p "
4153 "usgmap:x%x refcnt:%d\n",
4154 (void *)ndlp, ndlp->nlp_usg_map,
4155 atomic_read(&ndlp->kref.refcount));
4156 lpfc_disable_node(vport, ndlp);
4159 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4160 if ((mb = phba->sli.mbox_active)) {
4161 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4162 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4163 mb->context2 = NULL;
4164 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4168 spin_lock_irq(&phba->hbalock);
4169 /* Cleanup REG_LOGIN completions which are not yet processed */
4170 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4171 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
4172 (ndlp != (struct lpfc_nodelist *) mb->context2))
4175 mb->context2 = NULL;
4176 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4179 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
4180 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4181 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4182 mp = (struct lpfc_dmabuf *) (mb->context1);
4184 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
4187 list_del(&mb->list);
4188 if (phba->sli_rev == LPFC_SLI_REV4)
4189 lpfc_sli4_free_rpi(phba,
4190 mb->u.mb.un.varRegLogin.rpi);
4191 mempool_free(mb, phba->mbox_mem_pool);
4192 /* We shall not invoke the lpfc_nlp_put to decrement
4193 * the ndlp reference count as we are in the process
4194 * of lpfc_nlp_release.
4198 spin_unlock_irq(&phba->hbalock);
4200 lpfc_els_abort(phba, ndlp);
4202 spin_lock_irq(shost->host_lock);
4203 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
4204 spin_unlock_irq(shost->host_lock);
4206 ndlp->nlp_last_elscmd = 0;
4207 del_timer_sync(&ndlp->nlp_delayfunc);
4209 list_del_init(&ndlp->els_retry_evt.evt_listp);
4210 list_del_init(&ndlp->dev_loss_evt.evt_listp);
4212 lpfc_unreg_rpi(vport, ndlp);
4218 * Check to see if we can free the nlp back to the freelist.
4219 * If we are in the middle of using the nlp in the discovery state
4220 * machine, defer the free till we reach the end of the state machine.
4223 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4225 struct lpfc_hba *phba = vport->phba;
4226 struct lpfc_rport_data *rdata;
4230 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4231 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
4232 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
4233 !(ndlp->nlp_flag & NLP_RPI_VALID)) {
4234 /* For this case we need to cleanup the default rpi
4235 * allocated by the firmware.
4237 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4239 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
4240 (uint8_t *) &vport->fc_sparam, mbox, 0);
4242 mempool_free(mbox, phba->mbox_mem_pool);
4245 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4246 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4247 mbox->vport = vport;
4248 mbox->context2 = NULL;
4249 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4250 if (rc == MBX_NOT_FINISHED) {
4251 mempool_free(mbox, phba->mbox_mem_pool);
4256 lpfc_cleanup_node(vport, ndlp);
4259 * We can get here with a non-NULL ndlp->rport because when we
4260 * unregister a rport we don't break the rport/node linkage. So if we
4261 * do, make sure we don't leaving any dangling pointers behind.
4264 rdata = ndlp->rport->dd_data;
4265 rdata->pnode = NULL;
4271 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4274 D_ID mydid, ndlpdid, matchdid;
4276 if (did == Bcast_DID)
4279 /* First check for Direct match */
4280 if (ndlp->nlp_DID == did)
4283 /* Next check for area/domain identically equals 0 match */
4284 mydid.un.word = vport->fc_myDID;
4285 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
4289 matchdid.un.word = did;
4290 ndlpdid.un.word = ndlp->nlp_DID;
4291 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4292 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4293 (mydid.un.b.area == matchdid.un.b.area)) {
4294 if ((ndlpdid.un.b.domain == 0) &&
4295 (ndlpdid.un.b.area == 0)) {
4296 if (ndlpdid.un.b.id)
4302 matchdid.un.word = ndlp->nlp_DID;
4303 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4304 (mydid.un.b.area == ndlpdid.un.b.area)) {
4305 if ((matchdid.un.b.domain == 0) &&
4306 (matchdid.un.b.area == 0)) {
4307 if (matchdid.un.b.id)
4315 /* Search for a nodelist entry */
4316 static struct lpfc_nodelist *
4317 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4319 struct lpfc_nodelist *ndlp;
4322 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4323 if (lpfc_matchdid(vport, ndlp, did)) {
4324 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4325 ((uint32_t) ndlp->nlp_xri << 16) |
4326 ((uint32_t) ndlp->nlp_type << 8) |
4327 ((uint32_t) ndlp->nlp_rpi & 0xff));
4328 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4329 "0929 FIND node DID "
4330 "Data: x%p x%x x%x x%x\n",
4331 ndlp, ndlp->nlp_DID,
4332 ndlp->nlp_flag, data1);
4337 /* FIND node did <did> NOT FOUND */
4338 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4339 "0932 FIND node did x%x NOT FOUND.\n", did);
4343 struct lpfc_nodelist *
4344 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4346 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4347 struct lpfc_nodelist *ndlp;
4349 spin_lock_irq(shost->host_lock);
4350 ndlp = __lpfc_findnode_did(vport, did);
4351 spin_unlock_irq(shost->host_lock);
4355 struct lpfc_nodelist *
4356 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
4358 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4359 struct lpfc_nodelist *ndlp;
4361 ndlp = lpfc_findnode_did(vport, did);
4363 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4364 lpfc_rscn_payload_check(vport, did) == 0)
4366 ndlp = (struct lpfc_nodelist *)
4367 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
4370 lpfc_nlp_init(vport, ndlp, did);
4371 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4372 spin_lock_irq(shost->host_lock);
4373 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4374 spin_unlock_irq(shost->host_lock);
4376 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4377 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4380 spin_lock_irq(shost->host_lock);
4381 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4382 spin_unlock_irq(shost->host_lock);
4386 if ((vport->fc_flag & FC_RSCN_MODE) &&
4387 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
4388 if (lpfc_rscn_payload_check(vport, did)) {
4389 /* If we've already recieved a PLOGI from this NPort
4390 * we don't need to try to discover it again.
4392 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
4395 /* Since this node is marked for discovery,
4396 * delay timeout is not needed.
4398 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4399 spin_lock_irq(shost->host_lock);
4400 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4401 spin_unlock_irq(shost->host_lock);
4405 /* If we've already recieved a PLOGI from this NPort,
4406 * or we are already in the process of discovery on it,
4407 * we don't need to try to discover it again.
4409 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
4410 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4411 ndlp->nlp_flag & NLP_RCV_PLOGI)
4413 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4414 spin_lock_irq(shost->host_lock);
4415 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4416 spin_unlock_irq(shost->host_lock);
4421 /* Build a list of nodes to discover based on the loopmap */
4423 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
4425 struct lpfc_hba *phba = vport->phba;
4427 uint32_t alpa, index;
4429 if (!lpfc_is_link_up(phba))
4432 if (phba->fc_topology != TOPOLOGY_LOOP)
4435 /* Check for loop map present or not */
4436 if (phba->alpa_map[0]) {
4437 for (j = 1; j <= phba->alpa_map[0]; j++) {
4438 alpa = phba->alpa_map[j];
4439 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
4441 lpfc_setup_disc_node(vport, alpa);
4444 /* No alpamap, so try all alpa's */
4445 for (j = 0; j < FC_MAXLOOP; j++) {
4446 /* If cfg_scan_down is set, start from highest
4447 * ALPA (0xef) to lowest (0x1).
4449 if (vport->cfg_scan_down)
4452 index = FC_MAXLOOP - j - 1;
4453 alpa = lpfcAlpaArray[index];
4454 if ((vport->fc_myDID & 0xff) == alpa)
4456 lpfc_setup_disc_node(vport, alpa);
4463 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
4466 struct lpfc_sli *psli = &phba->sli;
4467 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
4468 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
4469 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
4473 * if it's not a physical port or if we already send
4474 * clear_la then don't send it.
4476 if ((phba->link_state >= LPFC_CLEAR_LA) ||
4477 (vport->port_type != LPFC_PHYSICAL_PORT) ||
4478 (phba->sli_rev == LPFC_SLI_REV4))
4481 /* Link up discovery */
4482 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
4483 phba->link_state = LPFC_CLEAR_LA;
4484 lpfc_clear_la(phba, mbox);
4485 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
4486 mbox->vport = vport;
4487 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4488 if (rc == MBX_NOT_FINISHED) {
4489 mempool_free(mbox, phba->mbox_mem_pool);
4490 lpfc_disc_flush_list(vport);
4491 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4492 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4493 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4494 phba->link_state = LPFC_HBA_ERROR;
4499 /* Reg_vpi to tell firmware to resume normal operations */
4501 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4503 LPFC_MBOXQ_t *regvpimbox;
4505 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4507 lpfc_reg_vpi(vport, regvpimbox);
4508 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
4509 regvpimbox->vport = vport;
4510 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
4511 == MBX_NOT_FINISHED) {
4512 mempool_free(regvpimbox, phba->mbox_mem_pool);
4517 /* Start Link up / RSCN discovery on NPR nodes */
4519 lpfc_disc_start(struct lpfc_vport *vport)
4521 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4522 struct lpfc_hba *phba = vport->phba;
4524 uint32_t clear_la_pending;
4527 if (!lpfc_is_link_up(phba))
4530 if (phba->link_state == LPFC_CLEAR_LA)
4531 clear_la_pending = 1;
4533 clear_la_pending = 0;
4535 if (vport->port_state < LPFC_VPORT_READY)
4536 vport->port_state = LPFC_DISC_AUTH;
4538 lpfc_set_disctmo(vport);
4540 if (vport->fc_prevDID == vport->fc_myDID)
4545 vport->fc_prevDID = vport->fc_myDID;
4546 vport->num_disc_nodes = 0;
4548 /* Start Discovery state <hba_state> */
4549 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4550 "0202 Start Discovery hba state x%x "
4551 "Data: x%x x%x x%x\n",
4552 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
4553 vport->fc_adisc_cnt);
4555 /* First do ADISCs - if any */
4556 num_sent = lpfc_els_disc_adisc(vport);
4562 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
4563 * continue discovery.
4565 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4566 !(vport->fc_flag & FC_PT2PT) &&
4567 !(vport->fc_flag & FC_RSCN_MODE) &&
4568 (phba->sli_rev < LPFC_SLI_REV4)) {
4569 lpfc_issue_reg_vpi(phba, vport);
4574 * For SLI2, we need to set port_state to READY and continue
4577 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
4578 /* If we get here, there is nothing to ADISC */
4579 if (vport->port_type == LPFC_PHYSICAL_PORT)
4580 lpfc_issue_clear_la(phba, vport);
4582 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
4583 vport->num_disc_nodes = 0;
4584 /* go thru NPR nodes and issue ELS PLOGIs */
4585 if (vport->fc_npr_cnt)
4586 lpfc_els_disc_plogi(vport);
4588 if (!vport->num_disc_nodes) {
4589 spin_lock_irq(shost->host_lock);
4590 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4591 spin_unlock_irq(shost->host_lock);
4592 lpfc_can_disctmo(vport);
4595 vport->port_state = LPFC_VPORT_READY;
4597 /* Next do PLOGIs - if any */
4598 num_sent = lpfc_els_disc_plogi(vport);
4603 if (vport->fc_flag & FC_RSCN_MODE) {
4604 /* Check to see if more RSCNs came in while we
4605 * were processing this one.
4607 if ((vport->fc_rscn_id_cnt == 0) &&
4608 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
4609 spin_lock_irq(shost->host_lock);
4610 vport->fc_flag &= ~FC_RSCN_MODE;
4611 spin_unlock_irq(shost->host_lock);
4612 lpfc_can_disctmo(vport);
4614 lpfc_els_handle_rscn(vport);
4621 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
4622 * ring the match the sppecified nodelist.
4625 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
4627 LIST_HEAD(completions);
4628 struct lpfc_sli *psli;
4630 struct lpfc_iocbq *iocb, *next_iocb;
4631 struct lpfc_sli_ring *pring;
4634 pring = &psli->ring[LPFC_ELS_RING];
4636 /* Error matching iocb on txq or txcmplq
4637 * First check the txq.
4639 spin_lock_irq(&phba->hbalock);
4640 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4641 if (iocb->context1 != ndlp) {
4645 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
4646 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
4648 list_move_tail(&iocb->list, &completions);
4653 /* Next check the txcmplq */
4654 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
4655 if (iocb->context1 != ndlp) {
4659 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
4660 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
4661 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
4664 spin_unlock_irq(&phba->hbalock);
4666 /* Cancel all the IOCBs from the completions list */
4667 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4672 lpfc_disc_flush_list(struct lpfc_vport *vport)
4674 struct lpfc_nodelist *ndlp, *next_ndlp;
4675 struct lpfc_hba *phba = vport->phba;
4677 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
4678 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
4680 if (!NLP_CHK_NODE_ACT(ndlp))
4682 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4683 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
4684 lpfc_free_tx(phba, ndlp);
4691 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
4693 lpfc_els_flush_rscn(vport);
4694 lpfc_els_flush_cmd(vport);
4695 lpfc_disc_flush_list(vport);
4698 /*****************************************************************************/
4700 * NAME: lpfc_disc_timeout
4702 * FUNCTION: Fibre Channel driver discovery timeout routine.
4704 * EXECUTION ENVIRONMENT: interrupt only
4712 /*****************************************************************************/
4714 lpfc_disc_timeout(unsigned long ptr)
4716 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4717 struct lpfc_hba *phba = vport->phba;
4718 uint32_t tmo_posted;
4719 unsigned long flags = 0;
4721 if (unlikely(!phba))
4724 spin_lock_irqsave(&vport->work_port_lock, flags);
4725 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
4727 vport->work_port_events |= WORKER_DISC_TMO;
4728 spin_unlock_irqrestore(&vport->work_port_lock, flags);
4731 lpfc_worker_wake_up(phba);
4736 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
4738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4739 struct lpfc_hba *phba = vport->phba;
4740 struct lpfc_sli *psli = &phba->sli;
4741 struct lpfc_nodelist *ndlp, *next_ndlp;
4742 LPFC_MBOXQ_t *initlinkmbox;
4743 int rc, clrlaerr = 0;
4745 if (!(vport->fc_flag & FC_DISC_TMO))
4748 spin_lock_irq(shost->host_lock);
4749 vport->fc_flag &= ~FC_DISC_TMO;
4750 spin_unlock_irq(shost->host_lock);
4752 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4753 "disc timeout: state:x%x rtry:x%x flg:x%x",
4754 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4756 switch (vport->port_state) {
4758 case LPFC_LOCAL_CFG_LINK:
4759 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
4763 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
4764 "0221 FAN timeout\n");
4765 /* Start discovery by sending FLOGI, clean up old rpis */
4766 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
4768 if (!NLP_CHK_NODE_ACT(ndlp))
4770 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
4772 if (ndlp->nlp_type & NLP_FABRIC) {
4773 /* Clean up the ndlp on Fabric connections */
4774 lpfc_drop_node(vport, ndlp);
4776 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
4777 /* Fail outstanding IO now since device
4778 * is marked for PLOGI.
4780 lpfc_unreg_rpi(vport, ndlp);
4783 if (vport->port_state != LPFC_FLOGI) {
4784 lpfc_initial_flogi(vport);
4791 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
4792 /* Initial FLOGI timeout */
4793 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4794 "0222 Initial %s timeout\n",
4795 vport->vpi ? "FDISC" : "FLOGI");
4797 /* Assume no Fabric and go on with discovery.
4798 * Check for outstanding ELS FLOGI to abort.
4801 /* FLOGI failed, so just use loop map to make discovery list */
4802 lpfc_disc_list_loopmap(vport);
4804 /* Start discovery */
4805 lpfc_disc_start(vport);
4808 case LPFC_FABRIC_CFG_LINK:
4809 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
4811 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4812 "0223 Timeout while waiting for "
4813 "NameServer login\n");
4814 /* Next look for NameServer ndlp */
4815 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4816 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4817 lpfc_els_abort(phba, ndlp);
4819 /* ReStart discovery */
4823 /* Check for wait for NameServer Rsp timeout */
4824 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4825 "0224 NameServer Query timeout "
4827 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
4829 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
4830 /* Try it one more time */
4831 vport->fc_ns_retry++;
4832 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
4833 vport->fc_ns_retry, 0);
4837 vport->fc_ns_retry = 0;
4841 * Discovery is over.
4842 * set port_state to PORT_READY if SLI2.
4843 * cmpl_reg_vpi will set port_state to READY for SLI3.
4845 if (phba->sli_rev < LPFC_SLI_REV4) {
4846 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4847 lpfc_issue_reg_vpi(phba, vport);
4848 else { /* NPIV Not enabled */
4849 lpfc_issue_clear_la(phba, vport);
4850 vport->port_state = LPFC_VPORT_READY;
4854 /* Setup and issue mailbox INITIALIZE LINK command */
4855 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4856 if (!initlinkmbox) {
4857 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4858 "0206 Device Discovery "
4859 "completion error\n");
4860 phba->link_state = LPFC_HBA_ERROR;
4864 lpfc_linkdown(phba);
4865 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
4866 phba->cfg_link_speed);
4867 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4868 initlinkmbox->vport = vport;
4869 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4870 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
4871 lpfc_set_loopback_flag(phba);
4872 if (rc == MBX_NOT_FINISHED)
4873 mempool_free(initlinkmbox, phba->mbox_mem_pool);
4877 case LPFC_DISC_AUTH:
4878 /* Node Authentication timeout */
4879 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4880 "0227 Node Authentication timeout\n");
4881 lpfc_disc_flush_list(vport);
4884 * set port_state to PORT_READY if SLI2.
4885 * cmpl_reg_vpi will set port_state to READY for SLI3.
4887 if (phba->sli_rev < LPFC_SLI_REV4) {
4888 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4889 lpfc_issue_reg_vpi(phba, vport);
4890 else { /* NPIV Not enabled */
4891 lpfc_issue_clear_la(phba, vport);
4892 vport->port_state = LPFC_VPORT_READY;
4897 case LPFC_VPORT_READY:
4898 if (vport->fc_flag & FC_RSCN_MODE) {
4899 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4900 "0231 RSCN timeout Data: x%x "
4902 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
4904 /* Cleanup any outstanding ELS commands */
4905 lpfc_els_flush_cmd(vport);
4907 lpfc_els_flush_rscn(vport);
4908 lpfc_disc_flush_list(vport);
4913 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4914 "0273 Unexpected discovery timeout, "
4915 "vport State x%x\n", vport->port_state);
4919 switch (phba->link_state) {
4921 /* CLEAR LA timeout */
4922 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4923 "0228 CLEAR LA timeout\n");
4928 lpfc_issue_clear_la(phba, vport);
4930 case LPFC_LINK_UNKNOWN:
4931 case LPFC_WARM_START:
4932 case LPFC_INIT_START:
4933 case LPFC_INIT_MBX_CMDS:
4934 case LPFC_LINK_DOWN:
4935 case LPFC_HBA_ERROR:
4936 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4937 "0230 Unexpected timeout, hba link "
4938 "state x%x\n", phba->link_state);
4942 case LPFC_HBA_READY:
4947 lpfc_disc_flush_list(vport);
4948 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
4949 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
4950 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
4951 vport->port_state = LPFC_VPORT_READY;
4958 * This routine handles processing a NameServer REG_LOGIN mailbox
4959 * command upon completion. It is setup in the LPFC_MBOXQ
4960 * as the completion routine when the command is
4961 * handed off to the SLI layer.
4964 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4966 MAILBOX_t *mb = &pmb->u.mb;
4967 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
4968 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4969 struct lpfc_vport *vport = pmb->vport;
4971 pmb->context1 = NULL;
4972 pmb->context2 = NULL;
4974 ndlp->nlp_rpi = mb->un.varWords[0];
4975 ndlp->nlp_flag |= NLP_RPI_VALID;
4976 ndlp->nlp_type |= NLP_FABRIC;
4977 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4980 * Start issuing Fabric-Device Management Interface (FDMI) command to
4981 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
4982 * fdmi-on=2 (supporting RPA/hostnmae)
4985 if (vport->cfg_fdmi_on == 1)
4986 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
4988 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
4990 /* decrement the node reference count held for this callback
4994 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4996 mempool_free(pmb, phba->mbox_mem_pool);
5002 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5004 uint16_t *rpi = param;
5006 return ndlp->nlp_rpi == *rpi;
5010 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5012 return memcmp(&ndlp->nlp_portname, param,
5013 sizeof(ndlp->nlp_portname)) == 0;
5016 static struct lpfc_nodelist *
5017 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
5019 struct lpfc_nodelist *ndlp;
5021 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5022 if (filter(ndlp, param))
5029 * This routine looks up the ndlp lists for the given RPI. If rpi found it
5030 * returns the node list element pointer else return NULL.
5032 struct lpfc_nodelist *
5033 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5035 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
5039 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
5040 * returns the node element list pointer else return NULL.
5042 struct lpfc_nodelist *
5043 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
5045 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5046 struct lpfc_nodelist *ndlp;
5048 spin_lock_irq(shost->host_lock);
5049 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5050 spin_unlock_irq(shost->host_lock);
5055 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5058 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
5060 lpfc_initialize_node(vport, ndlp, did);
5061 INIT_LIST_HEAD(&ndlp->nlp_listp);
5063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5064 "node init: did:x%x",
5065 ndlp->nlp_DID, 0, 0);
5070 /* This routine releases all resources associated with a specifc NPort's ndlp
5071 * and mempool_free's the nodelist.
5074 lpfc_nlp_release(struct kref *kref)
5076 struct lpfc_hba *phba;
5077 unsigned long flags;
5078 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5081 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5082 "node release: did:x%x flg:x%x type:x%x",
5083 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5085 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5086 "0279 lpfc_nlp_release: ndlp:x%p "
5087 "usgmap:x%x refcnt:%d\n",
5088 (void *)ndlp, ndlp->nlp_usg_map,
5089 atomic_read(&ndlp->kref.refcount));
5091 /* remove ndlp from action. */
5092 lpfc_nlp_remove(ndlp->vport, ndlp);
5094 /* clear the ndlp active flag for all release cases */
5096 spin_lock_irqsave(&phba->ndlp_lock, flags);
5097 NLP_CLR_NODE_ACT(ndlp);
5098 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5100 /* free ndlp memory for final ndlp release */
5101 if (NLP_CHK_FREE_REQ(ndlp)) {
5102 kfree(ndlp->lat_data);
5103 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
5107 /* This routine bumps the reference count for a ndlp structure to ensure
5108 * that one discovery thread won't free a ndlp while another discovery thread
5111 struct lpfc_nodelist *
5112 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5114 struct lpfc_hba *phba;
5115 unsigned long flags;
5118 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5119 "node get: did:x%x flg:x%x refcnt:x%x",
5120 ndlp->nlp_DID, ndlp->nlp_flag,
5121 atomic_read(&ndlp->kref.refcount));
5122 /* The check of ndlp usage to prevent incrementing the
5123 * ndlp reference count that is in the process of being
5127 spin_lock_irqsave(&phba->ndlp_lock, flags);
5128 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5129 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5130 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5131 "0276 lpfc_nlp_get: ndlp:x%p "
5132 "usgmap:x%x refcnt:%d\n",
5133 (void *)ndlp, ndlp->nlp_usg_map,
5134 atomic_read(&ndlp->kref.refcount));
5137 kref_get(&ndlp->kref);
5138 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5143 /* This routine decrements the reference count for a ndlp structure. If the
5144 * count goes to 0, this indicates the the associated nodelist should be
5145 * freed. Returning 1 indicates the ndlp resource has been released; on the
5146 * other hand, returning 0 indicates the ndlp resource has not been released
5150 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
5152 struct lpfc_hba *phba;
5153 unsigned long flags;
5158 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5159 "node put: did:x%x flg:x%x refcnt:x%x",
5160 ndlp->nlp_DID, ndlp->nlp_flag,
5161 atomic_read(&ndlp->kref.refcount));
5163 spin_lock_irqsave(&phba->ndlp_lock, flags);
5164 /* Check the ndlp memory free acknowledge flag to avoid the
5165 * possible race condition that kref_put got invoked again
5166 * after previous one has done ndlp memory free.
5168 if (NLP_CHK_FREE_ACK(ndlp)) {
5169 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5170 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5171 "0274 lpfc_nlp_put: ndlp:x%p "
5172 "usgmap:x%x refcnt:%d\n",
5173 (void *)ndlp, ndlp->nlp_usg_map,
5174 atomic_read(&ndlp->kref.refcount));
5177 /* Check the ndlp inactivate log flag to avoid the possible
5178 * race condition that kref_put got invoked again after ndlp
5179 * is already in inactivating state.
5181 if (NLP_CHK_IACT_REQ(ndlp)) {
5182 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5183 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5184 "0275 lpfc_nlp_put: ndlp:x%p "
5185 "usgmap:x%x refcnt:%d\n",
5186 (void *)ndlp, ndlp->nlp_usg_map,
5187 atomic_read(&ndlp->kref.refcount));
5190 /* For last put, mark the ndlp usage flags to make sure no
5191 * other kref_get and kref_put on the same ndlp shall get
5192 * in between the process when the final kref_put has been
5193 * invoked on this ndlp.
5195 if (atomic_read(&ndlp->kref.refcount) == 1) {
5196 /* Indicate ndlp is put to inactive state. */
5197 NLP_SET_IACT_REQ(ndlp);
5198 /* Acknowledge ndlp memory free has been seen. */
5199 if (NLP_CHK_FREE_REQ(ndlp))
5200 NLP_SET_FREE_ACK(ndlp);
5202 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5203 /* Note, the kref_put returns 1 when decrementing a reference
5204 * count that was 1, it invokes the release callback function,
5205 * but it still left the reference count as 1 (not actually
5206 * performs the last decrementation). Otherwise, it actually
5207 * decrements the reference count and returns 0.
5209 return kref_put(&ndlp->kref, lpfc_nlp_release);
5212 /* This routine free's the specified nodelist if it is not in use
5213 * by any other discovery thread. This routine returns 1 if the
5214 * ndlp has been freed. A return value of 0 indicates the ndlp is
5215 * not yet been released.
5218 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5220 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5221 "node not used: did:x%x flg:x%x refcnt:x%x",
5222 ndlp->nlp_DID, ndlp->nlp_flag,
5223 atomic_read(&ndlp->kref.refcount));
5224 if (atomic_read(&ndlp->kref.refcount) == 1)
5225 if (lpfc_nlp_put(ndlp))
5231 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5232 * @phba: Pointer to hba context object.
5234 * This function iterate through all FC nodes associated
5235 * will all vports to check if there is any node with
5236 * fc_rports associated with it. If there is an fc_rport
5237 * associated with the node, then the node is either in
5238 * discovered state or its devloss_timer is pending.
5241 lpfc_fcf_inuse(struct lpfc_hba *phba)
5243 struct lpfc_vport **vports;
5245 struct lpfc_nodelist *ndlp;
5246 struct Scsi_Host *shost;
5248 vports = lpfc_create_vport_work_array(phba);
5250 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5251 shost = lpfc_shost_from_vport(vports[i]);
5252 spin_lock_irq(shost->host_lock);
5253 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5254 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5255 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5257 spin_unlock_irq(shost->host_lock);
5260 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5261 "2624 RPI %x DID %x flg %x still "
5263 ndlp->nlp_rpi, ndlp->nlp_DID,
5265 if (ndlp->nlp_flag & NLP_RPI_VALID)
5269 spin_unlock_irq(shost->host_lock);
5272 lpfc_destroy_vport_work_array(phba, vports);
5277 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5278 * @phba: Pointer to hba context object.
5279 * @mboxq: Pointer to mailbox object.
5281 * This function frees memory associated with the mailbox command.
5284 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5286 struct lpfc_vport *vport = mboxq->vport;
5287 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5289 if (mboxq->u.mb.mbxStatus) {
5290 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5291 "2555 UNREG_VFI mbxStatus error x%x "
5293 mboxq->u.mb.mbxStatus, vport->port_state);
5295 spin_lock_irq(shost->host_lock);
5296 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5297 spin_unlock_irq(shost->host_lock);
5298 mempool_free(mboxq, phba->mbox_mem_pool);
5303 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5304 * @phba: Pointer to hba context object.
5305 * @mboxq: Pointer to mailbox object.
5307 * This function frees memory associated with the mailbox command.
5310 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5312 struct lpfc_vport *vport = mboxq->vport;
5314 if (mboxq->u.mb.mbxStatus) {
5315 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5316 "2550 UNREG_FCFI mbxStatus error x%x "
5318 mboxq->u.mb.mbxStatus, vport->port_state);
5320 mempool_free(mboxq, phba->mbox_mem_pool);
5325 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
5326 * @phba: Pointer to hba context object.
5328 * This function prepare the HBA for unregistering the currently registered
5329 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
5333 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
5336 struct lpfc_vport **vports;
5337 struct lpfc_nodelist *ndlp;
5338 struct Scsi_Host *shost;
5341 /* Unregister RPIs */
5342 if (lpfc_fcf_inuse(phba))
5343 lpfc_unreg_hba_rpis(phba);
5345 /* At this point, all discovery is aborted */
5346 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5348 /* Unregister VPIs */
5349 vports = lpfc_create_vport_work_array(phba);
5350 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
5351 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5352 /* Stop FLOGI/FDISC retries */
5353 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
5355 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
5356 lpfc_cleanup_pending_mbox(vports[i]);
5357 lpfc_mbx_unreg_vpi(vports[i]);
5358 shost = lpfc_shost_from_vport(vports[i]);
5359 spin_lock_irq(shost->host_lock);
5360 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
5361 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
5362 spin_unlock_irq(shost->host_lock);
5364 lpfc_destroy_vport_work_array(phba, vports);
5366 /* Cleanup any outstanding ELS commands */
5367 lpfc_els_flush_all_cmd(phba);
5369 /* Unregister VFI */
5370 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5372 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5373 "2556 UNREG_VFI mbox allocation failed"
5374 "HBA state x%x\n", phba->pport->port_state);
5378 lpfc_unreg_vfi(mbox, phba->pport);
5379 mbox->vport = phba->pport;
5380 mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
5382 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5383 if (rc == MBX_NOT_FINISHED) {
5384 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5385 "2557 UNREG_VFI issue mbox failed rc x%x "
5387 rc, phba->pport->port_state);
5388 mempool_free(mbox, phba->mbox_mem_pool);
5392 shost = lpfc_shost_from_vport(phba->pport);
5393 spin_lock_irq(shost->host_lock);
5394 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5395 spin_unlock_irq(shost->host_lock);
5401 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
5402 * @phba: Pointer to hba context object.
5404 * This function issues synchronous unregister FCF mailbox command to HBA to
5405 * unregister the currently registered FCF record. The driver does not reset
5406 * the driver FCF usage state flags.
5408 * Return 0 if successfully issued, none-zero otherwise.
5411 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
5416 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5418 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5419 "2551 UNREG_FCFI mbox allocation failed"
5420 "HBA state x%x\n", phba->pport->port_state);
5423 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
5424 mbox->vport = phba->pport;
5425 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
5426 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5428 if (rc == MBX_NOT_FINISHED) {
5429 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5430 "2552 Unregister FCFI command failed rc x%x "
5432 rc, phba->pport->port_state);
5439 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
5440 * @phba: Pointer to hba context object.
5442 * This function unregisters the currently reigstered FCF. This function
5443 * also tries to find another FCF for discovery by rescan the HBA FCF table.
5446 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
5450 /* Preparation for unregistering fcf */
5451 rc = lpfc_unregister_fcf_prep(phba);
5453 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5454 "2748 Failed to prepare for unregistering "
5455 "HBA's FCF record: rc=%d\n", rc);
5459 /* Now, unregister FCF record and reset HBA FCF state */
5460 rc = lpfc_sli4_unregister_fcf(phba);
5463 /* Reset HBA FCF states after successful unregister FCF */
5464 phba->fcf.fcf_flag = 0;
5465 phba->fcf.current_rec.flag = 0;
5468 * If driver is not unloading, check if there is any other
5469 * FCF record that can be used for discovery.
5471 if ((phba->pport->load_flag & FC_UNLOADING) ||
5472 (phba->link_state < LPFC_LINK_UP))
5475 /* This is considered as the initial FCF discovery scan */
5476 spin_lock_irq(&phba->hbalock);
5477 phba->fcf.fcf_flag |= FCF_INIT_DISC;
5478 spin_unlock_irq(&phba->hbalock);
5480 /* Reset FCF roundrobin bmask for new discovery */
5481 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
5483 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
5486 spin_lock_irq(&phba->hbalock);
5487 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
5488 spin_unlock_irq(&phba->hbalock);
5489 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5490 "2553 lpfc_unregister_unused_fcf failed "
5491 "to read FCF record HBA state x%x\n",
5492 phba->pport->port_state);
5497 * lpfc_unregister_fcf - Unregister the currently registered fcf record
5498 * @phba: Pointer to hba context object.
5500 * This function just unregisters the currently reigstered FCF. It does not
5501 * try to find another FCF for discovery.
5504 lpfc_unregister_fcf(struct lpfc_hba *phba)
5508 /* Preparation for unregistering fcf */
5509 rc = lpfc_unregister_fcf_prep(phba);
5511 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5512 "2749 Failed to prepare for unregistering "
5513 "HBA's FCF record: rc=%d\n", rc);
5517 /* Now, unregister FCF record and reset HBA FCF state */
5518 rc = lpfc_sli4_unregister_fcf(phba);
5521 /* Set proper HBA FCF states after successful unregister FCF */
5522 spin_lock_irq(&phba->hbalock);
5523 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
5524 spin_unlock_irq(&phba->hbalock);
5528 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
5529 * @phba: Pointer to hba context object.
5531 * This function check if there are any connected remote port for the FCF and
5532 * if all the devices are disconnected, this function unregister FCFI.
5533 * This function also tries to use another FCF for discovery.
5536 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
5539 * If HBA is not running in FIP mode, if HBA does not support
5540 * FCoE, if FCF discovery is ongoing, or if FCF has not been
5541 * registered, do nothing.
5543 spin_lock_irq(&phba->hbalock);
5544 if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
5545 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
5546 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
5547 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
5548 (phba->pport->port_state == LPFC_FLOGI)) {
5549 spin_unlock_irq(&phba->hbalock);
5552 spin_unlock_irq(&phba->hbalock);
5554 if (lpfc_fcf_inuse(phba))
5557 lpfc_unregister_fcf_rescan(phba);
5561 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
5562 * @phba: Pointer to hba context object.
5563 * @buff: Buffer containing the FCF connection table as in the config
5565 * This function create driver data structure for the FCF connection
5566 * record table read from config region 23.
5569 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
5572 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5573 struct lpfc_fcf_conn_hdr *conn_hdr;
5574 struct lpfc_fcf_conn_rec *conn_rec;
5575 uint32_t record_count;
5578 /* Free the current connect table */
5579 list_for_each_entry_safe(conn_entry, next_conn_entry,
5580 &phba->fcf_conn_rec_list, list) {
5581 list_del_init(&conn_entry->list);
5585 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
5586 record_count = conn_hdr->length * sizeof(uint32_t)/
5587 sizeof(struct lpfc_fcf_conn_rec);
5589 conn_rec = (struct lpfc_fcf_conn_rec *)
5590 (buff + sizeof(struct lpfc_fcf_conn_hdr));
5592 for (i = 0; i < record_count; i++) {
5593 if (!(conn_rec[i].flags & FCFCNCT_VALID))
5595 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
5598 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5599 "2566 Failed to allocate connection"
5604 memcpy(&conn_entry->conn_rec, &conn_rec[i],
5605 sizeof(struct lpfc_fcf_conn_rec));
5606 conn_entry->conn_rec.vlan_tag =
5607 le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
5608 conn_entry->conn_rec.flags =
5609 le16_to_cpu(conn_entry->conn_rec.flags);
5610 list_add_tail(&conn_entry->list,
5611 &phba->fcf_conn_rec_list);
5616 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
5617 * @phba: Pointer to hba context object.
5618 * @buff: Buffer containing the FCoE parameter data structure.
5620 * This function update driver data structure with config
5621 * parameters read from config region 23.
5624 lpfc_read_fcoe_param(struct lpfc_hba *phba,
5627 struct lpfc_fip_param_hdr *fcoe_param_hdr;
5628 struct lpfc_fcoe_params *fcoe_param;
5630 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
5632 fcoe_param = (struct lpfc_fcoe_params *)
5633 (buff + sizeof(struct lpfc_fip_param_hdr));
5635 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
5636 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
5639 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
5640 phba->valid_vlan = 1;
5641 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
5645 phba->fc_map[0] = fcoe_param->fc_map[0];
5646 phba->fc_map[1] = fcoe_param->fc_map[1];
5647 phba->fc_map[2] = fcoe_param->fc_map[2];
5652 * lpfc_get_rec_conf23 - Get a record type in config region data.
5653 * @buff: Buffer containing config region 23 data.
5654 * @size: Size of the data buffer.
5655 * @rec_type: Record type to be searched.
5657 * This function searches config region data to find the begining
5658 * of the record specified by record_type. If record found, this
5659 * function return pointer to the record else return NULL.
5662 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
5664 uint32_t offset = 0, rec_length;
5666 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
5667 (size < sizeof(uint32_t)))
5670 rec_length = buff[offset + 1];
5673 * One TLV record has one word header and number of data words
5674 * specified in the rec_length field of the record header.
5676 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
5678 if (buff[offset] == rec_type)
5679 return &buff[offset];
5681 if (buff[offset] == LPFC_REGION23_LAST_REC)
5684 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
5685 rec_length = buff[offset + 1];
5691 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
5692 * @phba: Pointer to lpfc_hba data structure.
5693 * @buff: Buffer containing config region 23 data.
5694 * @size: Size of the data buffer.
5696 * This function parses the FCoE config parameters in config region 23 and
5697 * populate driver data structure with the parameters.
5700 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
5704 uint32_t offset = 0, rec_length;
5708 * If data size is less than 2 words signature and version cannot be
5711 if (size < 2*sizeof(uint32_t))
5714 /* Check the region signature first */
5715 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
5716 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5717 "2567 Config region 23 has bad signature\n");
5723 /* Check the data structure version */
5724 if (buff[offset] != LPFC_REGION23_VERSION) {
5725 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5726 "2568 Config region 23 has bad version\n");
5731 rec_length = buff[offset + 1];
5733 /* Read FCoE param record */
5734 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5735 size - offset, FCOE_PARAM_TYPE);
5737 lpfc_read_fcoe_param(phba, rec_ptr);
5739 /* Read FCF connection table */
5740 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5741 size - offset, FCOE_CONN_TBL_TYPE);
5743 lpfc_read_fcf_conn_tbl(phba, rec_ptr);