1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2016 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>
28 #include <linux/lockdep.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
38 #include "lpfc_disc.h"
40 #include "lpfc_sli4.h"
41 #include "lpfc_scsi.h"
43 #include "lpfc_logmsg.h"
44 #include "lpfc_crtn.h"
45 #include "lpfc_vport.h"
46 #include "lpfc_debugfs.h"
48 /* AlpaArray for assignment of scsid for scan-down and bind_method */
49 static uint8_t lpfcAlpaArray[] = {
50 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
51 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
52 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
53 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
54 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
55 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
56 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
57 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
58 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
59 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
60 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
61 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
62 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
65 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
66 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
67 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
68 static int lpfc_fcf_inuse(struct lpfc_hba *);
71 lpfc_terminate_rport_io(struct fc_rport *rport)
73 struct lpfc_rport_data *rdata;
74 struct lpfc_nodelist * ndlp;
75 struct lpfc_hba *phba;
77 rdata = rport->dd_data;
80 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
81 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
82 printk(KERN_ERR "Cannot find remote node"
83 " to terminate I/O Data x%x\n",
90 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
91 "rport terminate: sid:x%x did:x%x flg:x%x",
92 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
94 if (ndlp->nlp_sid != NLP_NO_SID) {
95 lpfc_sli_abort_iocb(ndlp->vport,
96 &phba->sli.ring[phba->sli.fcp_ring],
97 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
102 * This function will be called when dev_loss_tmo fire.
105 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
107 struct lpfc_rport_data *rdata;
108 struct lpfc_nodelist * ndlp;
109 struct lpfc_vport *vport;
110 struct Scsi_Host *shost;
111 struct lpfc_hba *phba;
112 struct lpfc_work_evt *evtp;
116 rdata = rport->dd_data;
118 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
125 "rport devlosscb: sid:x%x did:x%x flg:x%x",
126 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
128 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
129 "3181 dev_loss_callbk x%06x, rport %p flg x%x\n",
130 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
132 /* Don't defer this if we are in the process of deleting the vport
133 * or unloading the driver. The unload will cleanup the node
134 * appropriately we just need to cleanup the ndlp rport info here.
136 if (vport->load_flag & FC_UNLOADING) {
137 put_node = rdata->pnode != NULL;
138 put_rport = ndlp->rport != NULL;
144 put_device(&rport->dev);
148 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
151 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
152 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
153 "6789 rport name %llx != node port name %llx",
155 wwn_to_u64(ndlp->nlp_portname.u.wwn));
157 evtp = &ndlp->dev_loss_evt;
159 if (!list_empty(&evtp->evt_listp)) {
160 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
161 "6790 rport name %llx dev_loss_evt pending",
166 shost = lpfc_shost_from_vport(vport);
167 spin_lock_irq(shost->host_lock);
168 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
169 spin_unlock_irq(shost->host_lock);
171 /* We need to hold the node by incrementing the reference
172 * count until this queued work is done
174 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
176 spin_lock_irq(&phba->hbalock);
177 if (evtp->evt_arg1) {
178 evtp->evt = LPFC_EVT_DEV_LOSS;
179 list_add_tail(&evtp->evt_listp, &phba->work_list);
180 lpfc_worker_wake_up(phba);
182 spin_unlock_irq(&phba->hbalock);
188 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
189 * @ndlp: Pointer to remote node object.
191 * This function is called from the worker thread when devloss timeout timer
192 * expires. For SLI4 host, this routine shall return 1 when at lease one
193 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
194 * routine shall return 0 when there is no remote node is still in use of FCF
195 * when devloss timeout happened to this @ndlp.
198 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
200 struct lpfc_rport_data *rdata;
201 struct fc_rport *rport;
202 struct lpfc_vport *vport;
203 struct lpfc_hba *phba;
204 struct Scsi_Host *shost;
212 shost = lpfc_shost_from_vport(vport);
214 spin_lock_irq(shost->host_lock);
215 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
216 spin_unlock_irq(shost->host_lock);
221 name = (uint8_t *) &ndlp->nlp_portname;
224 if (phba->sli_rev == LPFC_SLI_REV4)
225 fcf_inuse = lpfc_fcf_inuse(phba);
227 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
228 "rport devlosstmo:did:x%x type:x%x id:x%x",
229 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
231 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
232 "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n",
233 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
236 * lpfc_nlp_remove if reached with dangling rport drops the
237 * reference. To make sure that does not happen clear rport
238 * pointer in ndlp before lpfc_nlp_put.
240 rdata = rport->dd_data;
242 /* Don't defer this if we are in the process of deleting the vport
243 * or unloading the driver. The unload will cleanup the node
244 * appropriately we just need to cleanup the ndlp rport info here.
246 if (vport->load_flag & FC_UNLOADING) {
247 if (ndlp->nlp_sid != NLP_NO_SID) {
248 /* flush the target */
249 lpfc_sli_abort_iocb(vport,
250 &phba->sli.ring[phba->sli.fcp_ring],
251 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
253 put_node = rdata->pnode != NULL;
258 put_device(&rport->dev);
263 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
264 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
265 "0284 Devloss timeout Ignored on "
266 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
268 *name, *(name+1), *(name+2), *(name+3),
269 *(name+4), *(name+5), *(name+6), *(name+7),
274 put_node = rdata->pnode != NULL;
279 put_device(&rport->dev);
281 if (ndlp->nlp_type & NLP_FABRIC)
284 if (ndlp->nlp_sid != NLP_NO_SID) {
286 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
287 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
291 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
292 "0203 Devloss timeout on "
293 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
294 "NPort x%06x Data: x%x x%x x%x\n",
295 *name, *(name+1), *(name+2), *(name+3),
296 *(name+4), *(name+5), *(name+6), *(name+7),
297 ndlp->nlp_DID, ndlp->nlp_flag,
298 ndlp->nlp_state, ndlp->nlp_rpi);
300 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
301 "0204 Devloss timeout on "
302 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
303 "NPort x%06x Data: x%x x%x x%x\n",
304 *name, *(name+1), *(name+2), *(name+3),
305 *(name+4), *(name+5), *(name+6), *(name+7),
306 ndlp->nlp_DID, ndlp->nlp_flag,
307 ndlp->nlp_state, ndlp->nlp_rpi);
310 if (!(vport->load_flag & FC_UNLOADING) &&
311 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
312 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
313 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
314 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
315 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
316 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
322 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
323 * @phba: Pointer to hba context object.
324 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
325 * @nlp_did: remote node identifer with devloss timeout.
327 * This function is called from the worker thread after invoking devloss
328 * timeout handler and releasing the reference count for the ndlp with
329 * which the devloss timeout was handled for SLI4 host. For the devloss
330 * timeout of the last remote node which had been in use of FCF, when this
331 * routine is invoked, it shall be guaranteed that none of the remote are
332 * in-use of FCF. When devloss timeout to the last remote using the FCF,
333 * if the FIP engine is neither in FCF table scan process nor roundrobin
334 * failover process, the in-use FCF shall be unregistered. If the FIP
335 * engine is in FCF discovery process, the devloss timeout state shall
336 * be set for either the FCF table scan process or roundrobin failover
337 * process to unregister the in-use FCF.
340 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
343 /* If devloss timeout happened to a remote node when FCF had no
344 * longer been in-use, do nothing.
349 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
350 spin_lock_irq(&phba->hbalock);
351 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
352 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
353 spin_unlock_irq(&phba->hbalock);
356 phba->hba_flag |= HBA_DEVLOSS_TMO;
357 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
358 "2847 Last remote node (x%x) using "
359 "FCF devloss tmo\n", nlp_did);
361 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
362 spin_unlock_irq(&phba->hbalock);
363 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
364 "2868 Devloss tmo to FCF rediscovery "
368 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
369 spin_unlock_irq(&phba->hbalock);
370 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
371 "2869 Devloss tmo to idle FIP engine, "
372 "unreg in-use FCF and rescan.\n");
373 /* Unregister in-use FCF and rescan */
374 lpfc_unregister_fcf_rescan(phba);
377 spin_unlock_irq(&phba->hbalock);
378 if (phba->hba_flag & FCF_TS_INPROG)
379 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
380 "2870 FCF table scan in progress\n");
381 if (phba->hba_flag & FCF_RR_INPROG)
382 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
383 "2871 FLOGI roundrobin FCF failover "
386 lpfc_unregister_unused_fcf(phba);
390 * lpfc_alloc_fast_evt - Allocates data structure for posting event
391 * @phba: Pointer to hba context object.
393 * This function is called from the functions which need to post
394 * events from interrupt context. This function allocates data
395 * structure required for posting event. It also keeps track of
396 * number of events pending and prevent event storm when there are
399 struct lpfc_fast_path_event *
400 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
401 struct lpfc_fast_path_event *ret;
403 /* If there are lot of fast event do not exhaust memory due to this */
404 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
407 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
410 atomic_inc(&phba->fast_event_count);
411 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
412 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
418 * lpfc_free_fast_evt - Frees event data structure
419 * @phba: Pointer to hba context object.
420 * @evt: Event object which need to be freed.
422 * This function frees the data structure required for posting
426 lpfc_free_fast_evt(struct lpfc_hba *phba,
427 struct lpfc_fast_path_event *evt) {
429 atomic_dec(&phba->fast_event_count);
434 * lpfc_send_fastpath_evt - Posts events generated from fast path
435 * @phba: Pointer to hba context object.
436 * @evtp: Event data structure.
438 * This function is called from worker thread, when the interrupt
439 * context need to post an event. This function posts the event
440 * to fc transport netlink interface.
443 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
444 struct lpfc_work_evt *evtp)
446 unsigned long evt_category, evt_sub_category;
447 struct lpfc_fast_path_event *fast_evt_data;
449 uint32_t evt_data_size;
450 struct Scsi_Host *shost;
452 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
455 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
456 evt_sub_category = (unsigned long) fast_evt_data->un.
457 fabric_evt.subcategory;
458 shost = lpfc_shost_from_vport(fast_evt_data->vport);
459 if (evt_category == FC_REG_FABRIC_EVENT) {
460 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
461 evt_data = (char *) &fast_evt_data->un.read_check_error;
462 evt_data_size = sizeof(fast_evt_data->un.
464 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
465 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
466 evt_data = (char *) &fast_evt_data->un.fabric_evt;
467 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
469 lpfc_free_fast_evt(phba, fast_evt_data);
472 } else if (evt_category == FC_REG_SCSI_EVENT) {
473 switch (evt_sub_category) {
474 case LPFC_EVENT_QFULL:
475 case LPFC_EVENT_DEVBSY:
476 evt_data = (char *) &fast_evt_data->un.scsi_evt;
477 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
479 case LPFC_EVENT_CHECK_COND:
480 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
481 evt_data_size = sizeof(fast_evt_data->un.
484 case LPFC_EVENT_VARQUEDEPTH:
485 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
486 evt_data_size = sizeof(fast_evt_data->un.
490 lpfc_free_fast_evt(phba, fast_evt_data);
494 lpfc_free_fast_evt(phba, fast_evt_data);
498 fc_host_post_vendor_event(shost,
499 fc_get_event_number(),
504 lpfc_free_fast_evt(phba, fast_evt_data);
509 lpfc_work_list_done(struct lpfc_hba *phba)
511 struct lpfc_work_evt *evtp = NULL;
512 struct lpfc_nodelist *ndlp;
517 spin_lock_irq(&phba->hbalock);
518 while (!list_empty(&phba->work_list)) {
519 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
521 spin_unlock_irq(&phba->hbalock);
524 case LPFC_EVT_ELS_RETRY:
525 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
526 lpfc_els_retry_delay_handler(ndlp);
527 free_evt = 0; /* evt is part of ndlp */
528 /* decrement the node reference count held
529 * for this queued work
533 case LPFC_EVT_DEV_LOSS:
534 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
535 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
537 /* decrement the node reference count held for
540 nlp_did = ndlp->nlp_DID;
542 if (phba->sli_rev == LPFC_SLI_REV4)
543 lpfc_sli4_post_dev_loss_tmo_handler(phba,
547 case LPFC_EVT_ONLINE:
548 if (phba->link_state < LPFC_LINK_DOWN)
549 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
551 *(int *) (evtp->evt_arg1) = 0;
552 complete((struct completion *)(evtp->evt_arg2));
554 case LPFC_EVT_OFFLINE_PREP:
555 if (phba->link_state >= LPFC_LINK_DOWN)
556 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
557 *(int *)(evtp->evt_arg1) = 0;
558 complete((struct completion *)(evtp->evt_arg2));
560 case LPFC_EVT_OFFLINE:
562 lpfc_sli_brdrestart(phba);
563 *(int *)(evtp->evt_arg1) =
564 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
565 lpfc_unblock_mgmt_io(phba);
566 complete((struct completion *)(evtp->evt_arg2));
568 case LPFC_EVT_WARM_START:
570 lpfc_reset_barrier(phba);
571 lpfc_sli_brdreset(phba);
572 lpfc_hba_down_post(phba);
573 *(int *)(evtp->evt_arg1) =
574 lpfc_sli_brdready(phba, HS_MBRDY);
575 lpfc_unblock_mgmt_io(phba);
576 complete((struct completion *)(evtp->evt_arg2));
580 *(int *)(evtp->evt_arg1)
581 = (phba->pport->stopped)
582 ? 0 : lpfc_sli_brdkill(phba);
583 lpfc_unblock_mgmt_io(phba);
584 complete((struct completion *)(evtp->evt_arg2));
586 case LPFC_EVT_FASTPATH_MGMT_EVT:
587 lpfc_send_fastpath_evt(phba, evtp);
590 case LPFC_EVT_RESET_HBA:
591 if (!(phba->pport->load_flag & FC_UNLOADING))
592 lpfc_reset_hba(phba);
597 spin_lock_irq(&phba->hbalock);
599 spin_unlock_irq(&phba->hbalock);
604 lpfc_work_done(struct lpfc_hba *phba)
606 struct lpfc_sli_ring *pring;
607 uint32_t ha_copy, status, control, work_port_events;
608 struct lpfc_vport **vports;
609 struct lpfc_vport *vport;
612 spin_lock_irq(&phba->hbalock);
613 ha_copy = phba->work_ha;
615 spin_unlock_irq(&phba->hbalock);
617 /* First, try to post the next mailbox command to SLI4 device */
618 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
619 lpfc_sli4_post_async_mbox(phba);
621 if (ha_copy & HA_ERATT)
622 /* Handle the error attention event */
623 lpfc_handle_eratt(phba);
625 if (ha_copy & HA_MBATT)
626 lpfc_sli_handle_mb_event(phba);
628 if (ha_copy & HA_LATT)
629 lpfc_handle_latt(phba);
631 /* Process SLI4 events */
632 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
633 if (phba->hba_flag & HBA_RRQ_ACTIVE)
634 lpfc_handle_rrq_active(phba);
635 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
636 lpfc_sli4_fcp_xri_abort_event_proc(phba);
637 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
638 lpfc_sli4_els_xri_abort_event_proc(phba);
639 if (phba->hba_flag & ASYNC_EVENT)
640 lpfc_sli4_async_event_proc(phba);
641 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
642 spin_lock_irq(&phba->hbalock);
643 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
644 spin_unlock_irq(&phba->hbalock);
645 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
647 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
648 lpfc_sli4_fcf_redisc_event_proc(phba);
651 vports = lpfc_create_vport_work_array(phba);
653 for (i = 0; i <= phba->max_vports; i++) {
655 * We could have no vports in array if unloading, so if
656 * this happens then just use the pport
658 if (vports[i] == NULL && i == 0)
664 spin_lock_irq(&vport->work_port_lock);
665 work_port_events = vport->work_port_events;
666 vport->work_port_events &= ~work_port_events;
667 spin_unlock_irq(&vport->work_port_lock);
668 if (work_port_events & WORKER_DISC_TMO)
669 lpfc_disc_timeout_handler(vport);
670 if (work_port_events & WORKER_ELS_TMO)
671 lpfc_els_timeout_handler(vport);
672 if (work_port_events & WORKER_HB_TMO)
673 lpfc_hb_timeout_handler(phba);
674 if (work_port_events & WORKER_MBOX_TMO)
675 lpfc_mbox_timeout_handler(phba);
676 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
677 lpfc_unblock_fabric_iocbs(phba);
678 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
679 lpfc_ramp_down_queue_handler(phba);
680 if (work_port_events & WORKER_DELAYED_DISC_TMO)
681 lpfc_delayed_disc_timeout_handler(vport);
683 lpfc_destroy_vport_work_array(phba, vports);
685 pring = &phba->sli.ring[LPFC_ELS_RING];
686 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
687 status >>= (4*LPFC_ELS_RING);
688 if ((status & HA_RXMASK) ||
689 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
690 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
691 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
692 pring->flag |= LPFC_DEFERRED_RING_EVENT;
693 /* Preserve legacy behavior. */
694 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
695 set_bit(LPFC_DATA_READY, &phba->data_flags);
697 if (phba->link_state >= LPFC_LINK_UP) {
698 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
699 lpfc_sli_handle_slow_ring_event(phba, pring,
704 if ((phba->sli_rev == LPFC_SLI_REV4) &&
705 (!list_empty(&pring->txq)))
706 lpfc_drain_txq(phba);
708 * Turn on Ring interrupts
710 if (phba->sli_rev <= LPFC_SLI_REV3) {
711 spin_lock_irq(&phba->hbalock);
712 control = readl(phba->HCregaddr);
713 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
714 lpfc_debugfs_slow_ring_trc(phba,
715 "WRK Enable ring: cntl:x%x hacopy:x%x",
716 control, ha_copy, 0);
718 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
719 writel(control, phba->HCregaddr);
720 readl(phba->HCregaddr); /* flush */
722 lpfc_debugfs_slow_ring_trc(phba,
723 "WRK Ring ok: cntl:x%x hacopy:x%x",
724 control, ha_copy, 0);
726 spin_unlock_irq(&phba->hbalock);
729 lpfc_work_list_done(phba);
733 lpfc_do_work(void *p)
735 struct lpfc_hba *phba = p;
738 set_user_nice(current, MIN_NICE);
739 current->flags |= PF_NOFREEZE;
740 phba->data_flags = 0;
742 while (!kthread_should_stop()) {
743 /* wait and check worker queue activities */
744 rc = wait_event_interruptible(phba->work_waitq,
745 (test_and_clear_bit(LPFC_DATA_READY,
747 || kthread_should_stop()));
748 /* Signal wakeup shall terminate the worker thread */
750 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
751 "0433 Wakeup on signal: rc=x%x\n", rc);
755 /* Attend pending lpfc data processing */
756 lpfc_work_done(phba);
758 phba->worker_thread = NULL;
759 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
760 "0432 Worker thread stopped.\n");
765 * This is only called to handle FC worker events. Since this a rare
766 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
767 * embedding it in the IOCB.
770 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
773 struct lpfc_work_evt *evtp;
777 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
778 * be queued to worker thread for processing
780 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
784 evtp->evt_arg1 = arg1;
785 evtp->evt_arg2 = arg2;
788 spin_lock_irqsave(&phba->hbalock, flags);
789 list_add_tail(&evtp->evt_listp, &phba->work_list);
790 spin_unlock_irqrestore(&phba->hbalock, flags);
792 lpfc_worker_wake_up(phba);
798 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
800 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
801 struct lpfc_hba *phba = vport->phba;
802 struct lpfc_nodelist *ndlp, *next_ndlp;
804 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
805 if (!NLP_CHK_NODE_ACT(ndlp))
807 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
809 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
810 ((vport->port_type == LPFC_NPIV_PORT) &&
811 (ndlp->nlp_DID == NameServer_DID)))
812 lpfc_unreg_rpi(vport, ndlp);
814 /* Leave Fabric nodes alone on link down */
815 if ((phba->sli_rev < LPFC_SLI_REV4) &&
816 (!remove && ndlp->nlp_type & NLP_FABRIC))
818 lpfc_disc_state_machine(vport, ndlp, NULL,
821 : NLP_EVT_DEVICE_RECOVERY);
823 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
824 if (phba->sli_rev == LPFC_SLI_REV4)
825 lpfc_sli4_unreg_all_rpis(vport);
826 lpfc_mbx_unreg_vpi(vport);
827 spin_lock_irq(shost->host_lock);
828 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
829 spin_unlock_irq(shost->host_lock);
834 lpfc_port_link_failure(struct lpfc_vport *vport)
836 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
838 /* Cleanup any outstanding received buffers */
839 lpfc_cleanup_rcv_buffers(vport);
841 /* Cleanup any outstanding RSCN activity */
842 lpfc_els_flush_rscn(vport);
844 /* Cleanup any outstanding ELS commands */
845 lpfc_els_flush_cmd(vport);
847 lpfc_cleanup_rpis(vport, 0);
849 /* Turn off discovery timer if its running */
850 lpfc_can_disctmo(vport);
854 lpfc_linkdown_port(struct lpfc_vport *vport)
856 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
858 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
861 "Link Down: state:x%x rtry:x%x flg:x%x",
862 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
864 lpfc_port_link_failure(vport);
866 /* Stop delayed Nport discovery */
867 spin_lock_irq(shost->host_lock);
868 vport->fc_flag &= ~FC_DISC_DELAYED;
869 spin_unlock_irq(shost->host_lock);
870 del_timer_sync(&vport->delayed_disc_tmo);
874 lpfc_linkdown(struct lpfc_hba *phba)
876 struct lpfc_vport *vport = phba->pport;
877 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
878 struct lpfc_vport **vports;
882 if (phba->link_state == LPFC_LINK_DOWN)
885 /* Block all SCSI stack I/Os */
886 lpfc_scsi_dev_block(phba);
888 spin_lock_irq(&phba->hbalock);
889 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
890 spin_unlock_irq(&phba->hbalock);
891 if (phba->link_state > LPFC_LINK_DOWN) {
892 phba->link_state = LPFC_LINK_DOWN;
893 spin_lock_irq(shost->host_lock);
894 phba->pport->fc_flag &= ~FC_LBIT;
895 spin_unlock_irq(shost->host_lock);
897 vports = lpfc_create_vport_work_array(phba);
899 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
900 /* Issue a LINK DOWN event to all nodes */
901 lpfc_linkdown_port(vports[i]);
903 lpfc_destroy_vport_work_array(phba, vports);
905 /* Clean up any SLI3 firmware default rpi's */
906 if (phba->sli_rev > LPFC_SLI_REV3)
909 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
911 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
913 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
914 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
915 == MBX_NOT_FINISHED) {
916 mempool_free(mb, phba->mbox_mem_pool);
921 /* Setup myDID for link up if we are in pt2pt mode */
922 if (phba->pport->fc_flag & FC_PT2PT) {
923 phba->pport->fc_myDID = 0;
924 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
926 lpfc_config_link(phba, mb);
927 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
929 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
930 == MBX_NOT_FINISHED) {
931 mempool_free(mb, phba->mbox_mem_pool);
934 spin_lock_irq(shost->host_lock);
935 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
936 spin_unlock_irq(shost->host_lock);
943 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
945 struct lpfc_nodelist *ndlp;
947 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
948 if (!NLP_CHK_NODE_ACT(ndlp))
950 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
952 if (ndlp->nlp_type & NLP_FABRIC) {
953 /* On Linkup its safe to clean up the ndlp
954 * from Fabric connections.
956 if (ndlp->nlp_DID != Fabric_DID)
957 lpfc_unreg_rpi(vport, ndlp);
958 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
959 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
960 /* Fail outstanding IO now since device is
963 lpfc_unreg_rpi(vport, ndlp);
969 lpfc_linkup_port(struct lpfc_vport *vport)
971 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
972 struct lpfc_hba *phba = vport->phba;
974 if ((vport->load_flag & FC_UNLOADING) != 0)
977 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
978 "Link Up: top:x%x speed:x%x flg:x%x",
979 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
981 /* If NPIV is not enabled, only bring the physical port up */
982 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
983 (vport != phba->pport))
986 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
988 spin_lock_irq(shost->host_lock);
989 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
990 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
991 vport->fc_flag |= FC_NDISC_ACTIVE;
992 vport->fc_ns_retry = 0;
993 spin_unlock_irq(shost->host_lock);
995 if (vport->fc_flag & FC_LBIT)
996 lpfc_linkup_cleanup_nodes(vport);
1001 lpfc_linkup(struct lpfc_hba *phba)
1003 struct lpfc_vport **vports;
1006 phba->link_state = LPFC_LINK_UP;
1008 /* Unblock fabric iocbs if they are blocked */
1009 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1010 del_timer_sync(&phba->fabric_block_timer);
1012 vports = lpfc_create_vport_work_array(phba);
1014 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1015 lpfc_linkup_port(vports[i]);
1016 lpfc_destroy_vport_work_array(phba, vports);
1022 * This routine handles processing a CLEAR_LA mailbox
1023 * command upon completion. It is setup in the LPFC_MBOXQ
1024 * as the completion routine when the command is
1025 * handed off to the SLI layer.
1028 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1030 struct lpfc_vport *vport = pmb->vport;
1031 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1032 struct lpfc_sli *psli = &phba->sli;
1033 MAILBOX_t *mb = &pmb->u.mb;
1036 /* Since we don't do discovery right now, turn these off here */
1037 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1038 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1039 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1041 /* Check for error */
1042 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1043 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1044 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1045 "0320 CLEAR_LA mbxStatus error x%x hba "
1047 mb->mbxStatus, vport->port_state);
1048 phba->link_state = LPFC_HBA_ERROR;
1052 if (vport->port_type == LPFC_PHYSICAL_PORT)
1053 phba->link_state = LPFC_HBA_READY;
1055 spin_lock_irq(&phba->hbalock);
1056 psli->sli_flag |= LPFC_PROCESS_LA;
1057 control = readl(phba->HCregaddr);
1058 control |= HC_LAINT_ENA;
1059 writel(control, phba->HCregaddr);
1060 readl(phba->HCregaddr); /* flush */
1061 spin_unlock_irq(&phba->hbalock);
1062 mempool_free(pmb, phba->mbox_mem_pool);
1066 /* Device Discovery completes */
1067 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1068 "0225 Device Discovery completes\n");
1069 mempool_free(pmb, phba->mbox_mem_pool);
1071 spin_lock_irq(shost->host_lock);
1072 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1073 spin_unlock_irq(shost->host_lock);
1075 lpfc_can_disctmo(vport);
1077 /* turn on Link Attention interrupts */
1079 spin_lock_irq(&phba->hbalock);
1080 psli->sli_flag |= LPFC_PROCESS_LA;
1081 control = readl(phba->HCregaddr);
1082 control |= HC_LAINT_ENA;
1083 writel(control, phba->HCregaddr);
1084 readl(phba->HCregaddr); /* flush */
1085 spin_unlock_irq(&phba->hbalock);
1092 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1094 struct lpfc_vport *vport = pmb->vport;
1096 if (pmb->u.mb.mbxStatus)
1099 mempool_free(pmb, phba->mbox_mem_pool);
1101 /* don't perform discovery for SLI4 loopback diagnostic test */
1102 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1103 !(phba->hba_flag & HBA_FCOE_MODE) &&
1104 (phba->link_flag & LS_LOOPBACK_MODE))
1107 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1108 vport->fc_flag & FC_PUBLIC_LOOP &&
1109 !(vport->fc_flag & FC_LBIT)) {
1110 /* Need to wait for FAN - use discovery timer
1111 * for timeout. port_state is identically
1112 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1114 lpfc_set_disctmo(vport);
1118 /* Start discovery by sending a FLOGI. port_state is identically
1119 * LPFC_FLOGI while waiting for FLOGI cmpl
1121 if (vport->port_state != LPFC_FLOGI)
1122 lpfc_initial_flogi(vport);
1123 else if (vport->fc_flag & FC_PT2PT)
1124 lpfc_disc_start(vport);
1128 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1129 "0306 CONFIG_LINK mbxStatus error x%x "
1131 pmb->u.mb.mbxStatus, vport->port_state);
1132 mempool_free(pmb, phba->mbox_mem_pool);
1134 lpfc_linkdown(phba);
1136 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1137 "0200 CONFIG_LINK bad hba state x%x\n",
1140 lpfc_issue_clear_la(phba, vport);
1145 * lpfc_sli4_clear_fcf_rr_bmask
1146 * @phba pointer to the struct lpfc_hba for this port.
1147 * This fucnction resets the round robin bit mask and clears the
1148 * fcf priority list. The list deletions are done while holding the
1149 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1150 * from the lpfc_fcf_pri record.
1153 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1155 struct lpfc_fcf_pri *fcf_pri;
1156 struct lpfc_fcf_pri *next_fcf_pri;
1157 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1158 spin_lock_irq(&phba->hbalock);
1159 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1160 &phba->fcf.fcf_pri_list, list) {
1161 list_del_init(&fcf_pri->list);
1162 fcf_pri->fcf_rec.flag = 0;
1164 spin_unlock_irq(&phba->hbalock);
1167 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1169 struct lpfc_vport *vport = mboxq->vport;
1171 if (mboxq->u.mb.mbxStatus) {
1172 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1173 "2017 REG_FCFI mbxStatus error x%x "
1175 mboxq->u.mb.mbxStatus, vport->port_state);
1179 /* Start FCoE discovery by sending a FLOGI. */
1180 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1181 /* Set the FCFI registered flag */
1182 spin_lock_irq(&phba->hbalock);
1183 phba->fcf.fcf_flag |= FCF_REGISTERED;
1184 spin_unlock_irq(&phba->hbalock);
1186 /* If there is a pending FCoE event, restart FCF table scan. */
1187 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1188 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1191 /* Mark successful completion of FCF table scan */
1192 spin_lock_irq(&phba->hbalock);
1193 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1194 phba->hba_flag &= ~FCF_TS_INPROG;
1195 if (vport->port_state != LPFC_FLOGI) {
1196 phba->hba_flag |= FCF_RR_INPROG;
1197 spin_unlock_irq(&phba->hbalock);
1198 lpfc_issue_init_vfi(vport);
1201 spin_unlock_irq(&phba->hbalock);
1205 spin_lock_irq(&phba->hbalock);
1206 phba->hba_flag &= ~FCF_RR_INPROG;
1207 spin_unlock_irq(&phba->hbalock);
1209 mempool_free(mboxq, phba->mbox_mem_pool);
1213 * lpfc_fab_name_match - Check if the fcf fabric name match.
1214 * @fab_name: pointer to fabric name.
1215 * @new_fcf_record: pointer to fcf record.
1217 * This routine compare the fcf record's fabric name with provided
1218 * fabric name. If the fabric name are identical this function
1219 * returns 1 else return 0.
1222 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1224 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1226 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1228 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1230 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1232 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1234 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1236 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1238 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1244 * lpfc_sw_name_match - Check if the fcf switch name match.
1245 * @fab_name: pointer to fabric name.
1246 * @new_fcf_record: pointer to fcf record.
1248 * This routine compare the fcf record's switch name with provided
1249 * switch name. If the switch name are identical this function
1250 * returns 1 else return 0.
1253 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1255 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1257 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1259 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1261 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1263 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1265 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1267 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1269 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1275 * lpfc_mac_addr_match - Check if the fcf mac address match.
1276 * @mac_addr: pointer to mac address.
1277 * @new_fcf_record: pointer to fcf record.
1279 * This routine compare the fcf record's mac address with HBA's
1280 * FCF mac address. If the mac addresses are identical this function
1281 * returns 1 else return 0.
1284 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1286 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1288 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1290 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1292 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1294 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1296 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1302 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1304 return (curr_vlan_id == new_vlan_id);
1308 * lpfc_update_fcf_record - Update driver fcf record
1309 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1310 * @phba: pointer to lpfc hba data structure.
1311 * @fcf_index: Index for the lpfc_fcf_record.
1312 * @new_fcf_record: pointer to hba fcf record.
1314 * This routine updates the driver FCF priority record from the new HBA FCF
1315 * record. This routine is called with the host lock held.
1318 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1319 struct fcf_record *new_fcf_record
1322 struct lpfc_fcf_pri *fcf_pri;
1324 lockdep_assert_held(&phba->hbalock);
1326 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1327 fcf_pri->fcf_rec.fcf_index = fcf_index;
1328 /* FCF record priority */
1329 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1334 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1335 * @fcf: pointer to driver fcf record.
1336 * @new_fcf_record: pointer to fcf record.
1338 * This routine copies the FCF information from the FCF
1339 * record to lpfc_hba data structure.
1342 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1343 struct fcf_record *new_fcf_record)
1346 fcf_rec->fabric_name[0] =
1347 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1348 fcf_rec->fabric_name[1] =
1349 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1350 fcf_rec->fabric_name[2] =
1351 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1352 fcf_rec->fabric_name[3] =
1353 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1354 fcf_rec->fabric_name[4] =
1355 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1356 fcf_rec->fabric_name[5] =
1357 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1358 fcf_rec->fabric_name[6] =
1359 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1360 fcf_rec->fabric_name[7] =
1361 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1363 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1364 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1365 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1366 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1367 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1368 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1369 /* FCF record index */
1370 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1371 /* FCF record priority */
1372 fcf_rec->priority = new_fcf_record->fip_priority;
1374 fcf_rec->switch_name[0] =
1375 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1376 fcf_rec->switch_name[1] =
1377 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1378 fcf_rec->switch_name[2] =
1379 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1380 fcf_rec->switch_name[3] =
1381 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1382 fcf_rec->switch_name[4] =
1383 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1384 fcf_rec->switch_name[5] =
1385 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1386 fcf_rec->switch_name[6] =
1387 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1388 fcf_rec->switch_name[7] =
1389 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1393 * lpfc_update_fcf_record - Update driver fcf record
1394 * @phba: pointer to lpfc hba data structure.
1395 * @fcf_rec: pointer to driver fcf record.
1396 * @new_fcf_record: pointer to hba fcf record.
1397 * @addr_mode: address mode to be set to the driver fcf record.
1398 * @vlan_id: vlan tag to be set to the driver fcf record.
1399 * @flag: flag bits to be set to the driver fcf record.
1401 * This routine updates the driver FCF record from the new HBA FCF record
1402 * together with the address mode, vlan_id, and other informations. This
1403 * routine is called with the host lock held.
1406 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1407 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1408 uint16_t vlan_id, uint32_t flag)
1410 lockdep_assert_held(&phba->hbalock);
1412 /* Copy the fields from the HBA's FCF record */
1413 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1414 /* Update other fields of driver FCF record */
1415 fcf_rec->addr_mode = addr_mode;
1416 fcf_rec->vlan_id = vlan_id;
1417 fcf_rec->flag |= (flag | RECORD_VALID);
1418 __lpfc_update_fcf_record_pri(phba,
1419 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1424 * lpfc_register_fcf - Register the FCF with hba.
1425 * @phba: pointer to lpfc hba data structure.
1427 * This routine issues a register fcfi mailbox command to register
1431 lpfc_register_fcf(struct lpfc_hba *phba)
1433 LPFC_MBOXQ_t *fcf_mbxq;
1436 spin_lock_irq(&phba->hbalock);
1437 /* If the FCF is not available do nothing. */
1438 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1439 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1440 spin_unlock_irq(&phba->hbalock);
1444 /* The FCF is already registered, start discovery */
1445 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1446 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1447 phba->hba_flag &= ~FCF_TS_INPROG;
1448 if (phba->pport->port_state != LPFC_FLOGI &&
1449 phba->pport->fc_flag & FC_FABRIC) {
1450 phba->hba_flag |= FCF_RR_INPROG;
1451 spin_unlock_irq(&phba->hbalock);
1452 lpfc_initial_flogi(phba->pport);
1455 spin_unlock_irq(&phba->hbalock);
1458 spin_unlock_irq(&phba->hbalock);
1460 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1462 spin_lock_irq(&phba->hbalock);
1463 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1464 spin_unlock_irq(&phba->hbalock);
1468 lpfc_reg_fcfi(phba, fcf_mbxq);
1469 fcf_mbxq->vport = phba->pport;
1470 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1471 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1472 if (rc == MBX_NOT_FINISHED) {
1473 spin_lock_irq(&phba->hbalock);
1474 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1475 spin_unlock_irq(&phba->hbalock);
1476 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1483 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1484 * @phba: pointer to lpfc hba data structure.
1485 * @new_fcf_record: pointer to fcf record.
1486 * @boot_flag: Indicates if this record used by boot bios.
1487 * @addr_mode: The address mode to be used by this FCF
1488 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1490 * This routine compare the fcf record with connect list obtained from the
1491 * config region to decide if this FCF can be used for SAN discovery. It returns
1492 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1493 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1494 * is used by boot bios and addr_mode will indicate the addressing mode to be
1495 * used for this FCF when the function returns.
1496 * If the FCF record need to be used with a particular vlan id, the vlan is
1497 * set in the vlan_id on return of the function. If not VLAN tagging need to
1498 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1501 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1502 struct fcf_record *new_fcf_record,
1503 uint32_t *boot_flag, uint32_t *addr_mode,
1506 struct lpfc_fcf_conn_entry *conn_entry;
1507 int i, j, fcf_vlan_id = 0;
1509 /* Find the lowest VLAN id in the FCF record */
1510 for (i = 0; i < 512; i++) {
1511 if (new_fcf_record->vlan_bitmap[i]) {
1512 fcf_vlan_id = i * 8;
1514 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1522 /* FCF not valid/available or solicitation in progress */
1523 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1524 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1525 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1528 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1530 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1532 if (phba->valid_vlan)
1533 *vlan_id = phba->vlan_id;
1535 *vlan_id = LPFC_FCOE_NULL_VID;
1540 * If there are no FCF connection table entry, driver connect to all
1543 if (list_empty(&phba->fcf_conn_rec_list)) {
1545 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1549 * When there are no FCF connect entries, use driver's default
1550 * addressing mode - FPMA.
1552 if (*addr_mode & LPFC_FCF_FPMA)
1553 *addr_mode = LPFC_FCF_FPMA;
1555 /* If FCF record report a vlan id use that vlan id */
1557 *vlan_id = fcf_vlan_id;
1559 *vlan_id = LPFC_FCOE_NULL_VID;
1563 list_for_each_entry(conn_entry,
1564 &phba->fcf_conn_rec_list, list) {
1565 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1568 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1569 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1572 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1573 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1576 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1578 * If the vlan bit map does not have the bit set for the
1579 * vlan id to be used, then it is not a match.
1581 if (!(new_fcf_record->vlan_bitmap
1582 [conn_entry->conn_rec.vlan_tag / 8] &
1583 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1588 * If connection record does not support any addressing mode,
1589 * skip the FCF record.
1591 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1592 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1596 * Check if the connection record specifies a required
1599 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1600 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1603 * If SPMA required but FCF not support this continue.
1605 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1606 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1607 new_fcf_record) & LPFC_FCF_SPMA))
1611 * If FPMA required but FCF not support this continue.
1613 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1614 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1615 new_fcf_record) & LPFC_FCF_FPMA))
1620 * This fcf record matches filtering criteria.
1622 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1628 * If user did not specify any addressing mode, or if the
1629 * preferred addressing mode specified by user is not supported
1630 * by FCF, allow fabric to pick the addressing mode.
1632 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1635 * If the user specified a required address mode, assign that
1638 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1639 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1640 *addr_mode = (conn_entry->conn_rec.flags &
1642 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1644 * If the user specified a preferred address mode, use the
1645 * addr mode only if FCF support the addr_mode.
1647 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1648 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1649 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1650 (*addr_mode & LPFC_FCF_SPMA))
1651 *addr_mode = LPFC_FCF_SPMA;
1652 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1653 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1654 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1655 (*addr_mode & LPFC_FCF_FPMA))
1656 *addr_mode = LPFC_FCF_FPMA;
1658 /* If matching connect list has a vlan id, use it */
1659 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1660 *vlan_id = conn_entry->conn_rec.vlan_tag;
1662 * If no vlan id is specified in connect list, use the vlan id
1665 else if (fcf_vlan_id)
1666 *vlan_id = fcf_vlan_id;
1668 *vlan_id = LPFC_FCOE_NULL_VID;
1677 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1678 * @phba: pointer to lpfc hba data structure.
1679 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1681 * This function check if there is any fcoe event pending while driver
1682 * scan FCF entries. If there is any pending event, it will restart the
1683 * FCF saning and return 1 else return 0.
1686 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1689 * If the Link is up and no FCoE events while in the
1690 * FCF discovery, no need to restart FCF discovery.
1692 if ((phba->link_state >= LPFC_LINK_UP) &&
1693 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1696 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1697 "2768 Pending link or FCF event during current "
1698 "handling of the previous event: link_state:x%x, "
1699 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1700 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1701 phba->fcoe_eventtag);
1703 spin_lock_irq(&phba->hbalock);
1704 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1705 spin_unlock_irq(&phba->hbalock);
1707 if (phba->link_state >= LPFC_LINK_UP) {
1708 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1709 "2780 Restart FCF table scan due to "
1710 "pending FCF event:evt_tag_at_scan:x%x, "
1711 "evt_tag_current:x%x\n",
1712 phba->fcoe_eventtag_at_fcf_scan,
1713 phba->fcoe_eventtag);
1714 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1717 * Do not continue FCF discovery and clear FCF_TS_INPROG
1720 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1721 "2833 Stop FCF discovery process due to link "
1722 "state change (x%x)\n", phba->link_state);
1723 spin_lock_irq(&phba->hbalock);
1724 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1725 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1726 spin_unlock_irq(&phba->hbalock);
1729 /* Unregister the currently registered FCF if required */
1731 spin_lock_irq(&phba->hbalock);
1732 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1733 spin_unlock_irq(&phba->hbalock);
1734 lpfc_sli4_unregister_fcf(phba);
1740 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1741 * @phba: pointer to lpfc hba data structure.
1742 * @fcf_cnt: number of eligible fcf record seen so far.
1744 * This function makes an running random selection decision on FCF record to
1745 * use through a sequence of @fcf_cnt eligible FCF records with equal
1746 * probability. To perform integer manunipulation of random numbers with
1747 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1748 * from prandom_u32() are taken as the random random number generated.
1750 * Returns true when outcome is for the newly read FCF record should be
1751 * chosen; otherwise, return false when outcome is for keeping the previously
1752 * chosen FCF record.
1755 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1759 /* Get 16-bit uniform random number */
1760 rand_num = 0xFFFF & prandom_u32();
1762 /* Decision with probability 1/fcf_cnt */
1763 if ((fcf_cnt * rand_num) < 0xFFFF)
1770 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1771 * @phba: pointer to lpfc hba data structure.
1772 * @mboxq: pointer to mailbox object.
1773 * @next_fcf_index: pointer to holder of next fcf index.
1775 * This routine parses the non-embedded fcf mailbox command by performing the
1776 * necessarily error checking, non-embedded read FCF record mailbox command
1777 * SGE parsing, and endianness swapping.
1779 * Returns the pointer to the new FCF record in the non-embedded mailbox
1780 * command DMA memory if successfully, other NULL.
1782 static struct fcf_record *
1783 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1784 uint16_t *next_fcf_index)
1787 struct lpfc_mbx_sge sge;
1788 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1789 uint32_t shdr_status, shdr_add_status, if_type;
1790 union lpfc_sli4_cfg_shdr *shdr;
1791 struct fcf_record *new_fcf_record;
1793 /* Get the first SGE entry from the non-embedded DMA memory. This
1794 * routine only uses a single SGE.
1796 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1797 if (unlikely(!mboxq->sge_array)) {
1798 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1799 "2524 Failed to get the non-embedded SGE "
1800 "virtual address\n");
1803 virt_addr = mboxq->sge_array->addr[0];
1805 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1806 lpfc_sli_pcimem_bcopy(shdr, shdr,
1807 sizeof(union lpfc_sli4_cfg_shdr));
1808 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1809 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
1810 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1811 if (shdr_status || shdr_add_status) {
1812 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
1813 if_type == LPFC_SLI_INTF_IF_TYPE_2)
1814 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1815 "2726 READ_FCF_RECORD Indicates empty "
1818 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1819 "2521 READ_FCF_RECORD mailbox failed "
1820 "with status x%x add_status x%x, "
1821 "mbx\n", shdr_status, shdr_add_status);
1825 /* Interpreting the returned information of the FCF record */
1826 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1827 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1828 sizeof(struct lpfc_mbx_read_fcf_tbl));
1829 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1830 new_fcf_record = (struct fcf_record *)(virt_addr +
1831 sizeof(struct lpfc_mbx_read_fcf_tbl));
1832 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1833 offsetof(struct fcf_record, vlan_bitmap));
1834 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1835 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
1837 return new_fcf_record;
1841 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1842 * @phba: pointer to lpfc hba data structure.
1843 * @fcf_record: pointer to the fcf record.
1844 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1845 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1847 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1851 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1852 struct fcf_record *fcf_record,
1854 uint16_t next_fcf_index)
1856 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1857 "2764 READ_FCF_RECORD:\n"
1858 "\tFCF_Index : x%x\n"
1859 "\tFCF_Avail : x%x\n"
1860 "\tFCF_Valid : x%x\n"
1862 "\tFIP_Priority : x%x\n"
1863 "\tMAC_Provider : x%x\n"
1864 "\tLowest VLANID : x%x\n"
1865 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1866 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1867 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1868 "\tNext_FCF_Index: x%x\n",
1869 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1870 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1871 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1872 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
1873 fcf_record->fip_priority,
1874 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1876 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1877 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1878 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1879 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1880 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1881 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1882 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1883 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1884 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1885 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1886 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1887 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1888 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1889 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1890 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1891 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1892 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1893 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1894 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1895 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1896 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1897 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1902 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1903 * @phba: pointer to lpfc hba data structure.
1904 * @fcf_rec: pointer to an existing FCF record.
1905 * @new_fcf_record: pointer to a new FCF record.
1906 * @new_vlan_id: vlan id from the new FCF record.
1908 * This function performs matching test of a new FCF record against an existing
1909 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1910 * will not be used as part of the FCF record matching criteria.
1912 * Returns true if all the fields matching, otherwise returns false.
1915 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1916 struct lpfc_fcf_rec *fcf_rec,
1917 struct fcf_record *new_fcf_record,
1918 uint16_t new_vlan_id)
1920 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1921 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1923 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1925 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1927 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1929 if (fcf_rec->priority != new_fcf_record->fip_priority)
1935 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1936 * @vport: Pointer to vport object.
1937 * @fcf_index: index to next fcf.
1939 * This function processing the roundrobin fcf failover to next fcf index.
1940 * When this function is invoked, there will be a current fcf registered
1942 * Return: 0 for continue retrying flogi on currently registered fcf;
1943 * 1 for stop flogi on currently registered fcf;
1945 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1947 struct lpfc_hba *phba = vport->phba;
1950 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1951 spin_lock_irq(&phba->hbalock);
1952 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1953 spin_unlock_irq(&phba->hbalock);
1954 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1955 "2872 Devloss tmo with no eligible "
1956 "FCF, unregister in-use FCF (x%x) "
1957 "and rescan FCF table\n",
1958 phba->fcf.current_rec.fcf_indx);
1959 lpfc_unregister_fcf_rescan(phba);
1960 goto stop_flogi_current_fcf;
1962 /* Mark the end to FLOGI roundrobin failover */
1963 phba->hba_flag &= ~FCF_RR_INPROG;
1964 /* Allow action to new fcf asynchronous event */
1965 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1966 spin_unlock_irq(&phba->hbalock);
1967 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1968 "2865 No FCF available, stop roundrobin FCF "
1969 "failover and change port state:x%x/x%x\n",
1970 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1971 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1973 if (!phba->fcf.fcf_redisc_attempted) {
1974 lpfc_unregister_fcf(phba);
1976 rc = lpfc_sli4_redisc_fcf_table(phba);
1978 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1979 "3195 Rediscover FCF table\n");
1980 phba->fcf.fcf_redisc_attempted = 1;
1981 lpfc_sli4_clear_fcf_rr_bmask(phba);
1983 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1984 "3196 Rediscover FCF table "
1985 "failed. Status:x%x\n", rc);
1988 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1989 "3197 Already rediscover FCF table "
1990 "attempted. No more retry\n");
1992 goto stop_flogi_current_fcf;
1994 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1995 "2794 Try FLOGI roundrobin FCF failover to "
1996 "(x%x)\n", fcf_index);
1997 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1999 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2000 "2761 FLOGI roundrobin FCF failover "
2001 "failed (rc:x%x) to read FCF (x%x)\n",
2002 rc, phba->fcf.current_rec.fcf_indx);
2004 goto stop_flogi_current_fcf;
2008 stop_flogi_current_fcf:
2009 lpfc_can_disctmo(vport);
2014 * lpfc_sli4_fcf_pri_list_del
2015 * @phba: pointer to lpfc hba data structure.
2016 * @fcf_index the index of the fcf record to delete
2017 * This routine checks the on list flag of the fcf_index to be deleted.
2018 * If it is one the list then it is removed from the list, and the flag
2019 * is cleared. This routine grab the hbalock before removing the fcf
2020 * record from the list.
2022 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2025 struct lpfc_fcf_pri *new_fcf_pri;
2027 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2028 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2029 "3058 deleting idx x%x pri x%x flg x%x\n",
2030 fcf_index, new_fcf_pri->fcf_rec.priority,
2031 new_fcf_pri->fcf_rec.flag);
2032 spin_lock_irq(&phba->hbalock);
2033 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2034 if (phba->fcf.current_rec.priority ==
2035 new_fcf_pri->fcf_rec.priority)
2036 phba->fcf.eligible_fcf_cnt--;
2037 list_del_init(&new_fcf_pri->list);
2038 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2040 spin_unlock_irq(&phba->hbalock);
2044 * lpfc_sli4_set_fcf_flogi_fail
2045 * @phba: pointer to lpfc hba data structure.
2046 * @fcf_index the index of the fcf record to update
2047 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2048 * flag so the the round robin slection for the particular priority level
2049 * will try a different fcf record that does not have this bit set.
2050 * If the fcf record is re-read for any reason this flag is cleared brfore
2051 * adding it to the priority list.
2054 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2056 struct lpfc_fcf_pri *new_fcf_pri;
2057 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2058 spin_lock_irq(&phba->hbalock);
2059 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2060 spin_unlock_irq(&phba->hbalock);
2064 * lpfc_sli4_fcf_pri_list_add
2065 * @phba: pointer to lpfc hba data structure.
2066 * @fcf_index the index of the fcf record to add
2067 * This routine checks the priority of the fcf_index to be added.
2068 * If it is a lower priority than the current head of the fcf_pri list
2069 * then it is added to the list in the right order.
2070 * If it is the same priority as the current head of the list then it
2071 * is added to the head of the list and its bit in the rr_bmask is set.
2072 * If the fcf_index to be added is of a higher priority than the current
2073 * head of the list then the rr_bmask is cleared, its bit is set in the
2074 * rr_bmask and it is added to the head of the list.
2076 * 0=success 1=failure
2078 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2080 struct fcf_record *new_fcf_record)
2082 uint16_t current_fcf_pri;
2083 uint16_t last_index;
2084 struct lpfc_fcf_pri *fcf_pri;
2085 struct lpfc_fcf_pri *next_fcf_pri;
2086 struct lpfc_fcf_pri *new_fcf_pri;
2089 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2090 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2091 "3059 adding idx x%x pri x%x flg x%x\n",
2092 fcf_index, new_fcf_record->fip_priority,
2093 new_fcf_pri->fcf_rec.flag);
2094 spin_lock_irq(&phba->hbalock);
2095 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2096 list_del_init(&new_fcf_pri->list);
2097 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2098 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2099 if (list_empty(&phba->fcf.fcf_pri_list)) {
2100 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2101 ret = lpfc_sli4_fcf_rr_index_set(phba,
2102 new_fcf_pri->fcf_rec.fcf_index);
2106 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2107 LPFC_SLI4_FCF_TBL_INDX_MAX);
2108 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2109 ret = 0; /* Empty rr list */
2112 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2113 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2114 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2115 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2116 memset(phba->fcf.fcf_rr_bmask, 0,
2117 sizeof(*phba->fcf.fcf_rr_bmask));
2118 /* fcfs_at_this_priority_level = 1; */
2119 phba->fcf.eligible_fcf_cnt = 1;
2121 /* fcfs_at_this_priority_level++; */
2122 phba->fcf.eligible_fcf_cnt++;
2123 ret = lpfc_sli4_fcf_rr_index_set(phba,
2124 new_fcf_pri->fcf_rec.fcf_index);
2128 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2129 &phba->fcf.fcf_pri_list, list) {
2130 if (new_fcf_pri->fcf_rec.priority <=
2131 fcf_pri->fcf_rec.priority) {
2132 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2133 list_add(&new_fcf_pri->list,
2134 &phba->fcf.fcf_pri_list);
2136 list_add(&new_fcf_pri->list,
2137 &((struct lpfc_fcf_pri *)
2138 fcf_pri->list.prev)->list);
2141 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2142 || new_fcf_pri->fcf_rec.priority <
2143 next_fcf_pri->fcf_rec.priority) {
2144 list_add(&new_fcf_pri->list, &fcf_pri->list);
2148 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2154 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2155 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2156 spin_unlock_irq(&phba->hbalock);
2161 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2162 * @phba: pointer to lpfc hba data structure.
2163 * @mboxq: pointer to mailbox object.
2165 * This function iterates through all the fcf records available in
2166 * HBA and chooses the optimal FCF record for discovery. After finding
2167 * the FCF for discovery it registers the FCF record and kicks start
2169 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2170 * use an FCF record which matches fabric name and mac address of the
2171 * currently used FCF record.
2172 * If the driver supports only one FCF, it will try to use the FCF record
2173 * used by BOOT_BIOS.
2176 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2178 struct fcf_record *new_fcf_record;
2179 uint32_t boot_flag, addr_mode;
2180 uint16_t fcf_index, next_fcf_index;
2181 struct lpfc_fcf_rec *fcf_rec = NULL;
2183 bool select_new_fcf;
2186 /* If there is pending FCoE event restart FCF table scan */
2187 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2188 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2192 /* Parse the FCF record from the non-embedded mailbox command */
2193 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2195 if (!new_fcf_record) {
2196 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2197 "2765 Mailbox command READ_FCF_RECORD "
2198 "failed to retrieve a FCF record.\n");
2199 /* Let next new FCF event trigger fast failover */
2200 spin_lock_irq(&phba->hbalock);
2201 phba->hba_flag &= ~FCF_TS_INPROG;
2202 spin_unlock_irq(&phba->hbalock);
2203 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2207 /* Check the FCF record against the connection list */
2208 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2209 &addr_mode, &vlan_id);
2211 /* Log the FCF record information if turned on */
2212 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2216 * If the fcf record does not match with connect list entries
2217 * read the next entry; otherwise, this is an eligible FCF
2218 * record for roundrobin FCF failover.
2221 lpfc_sli4_fcf_pri_list_del(phba,
2222 bf_get(lpfc_fcf_record_fcf_index,
2224 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2225 "2781 FCF (x%x) failed connection "
2226 "list check: (x%x/x%x/%x)\n",
2227 bf_get(lpfc_fcf_record_fcf_index,
2229 bf_get(lpfc_fcf_record_fcf_avail,
2231 bf_get(lpfc_fcf_record_fcf_valid,
2233 bf_get(lpfc_fcf_record_fcf_sol,
2235 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2236 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2237 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2238 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2239 phba->fcf.current_rec.fcf_indx) {
2240 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2241 "2862 FCF (x%x) matches property "
2242 "of in-use FCF (x%x)\n",
2243 bf_get(lpfc_fcf_record_fcf_index,
2245 phba->fcf.current_rec.fcf_indx);
2249 * In case the current in-use FCF record becomes
2250 * invalid/unavailable during FCF discovery that
2251 * was not triggered by fast FCF failover process,
2252 * treat it as fast FCF failover.
2254 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2255 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2256 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2257 "2835 Invalid in-use FCF "
2258 "(x%x), enter FCF failover "
2260 phba->fcf.current_rec.fcf_indx);
2261 spin_lock_irq(&phba->hbalock);
2262 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2263 spin_unlock_irq(&phba->hbalock);
2264 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2265 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2266 LPFC_FCOE_FCF_GET_FIRST);
2272 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2273 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2280 * If this is not the first FCF discovery of the HBA, use last
2281 * FCF record for the discovery. The condition that a rescan
2282 * matches the in-use FCF record: fabric name, switch name, mac
2283 * address, and vlan_id.
2285 spin_lock_irq(&phba->hbalock);
2286 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2287 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2288 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2289 new_fcf_record, vlan_id)) {
2290 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2291 phba->fcf.current_rec.fcf_indx) {
2292 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2293 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2294 /* Stop FCF redisc wait timer */
2295 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2297 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2298 /* Fast failover, mark completed */
2299 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2300 spin_unlock_irq(&phba->hbalock);
2301 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2302 "2836 New FCF matches in-use "
2303 "FCF (x%x), port_state:x%x, "
2305 phba->fcf.current_rec.fcf_indx,
2306 phba->pport->port_state,
2307 phba->pport->fc_flag);
2310 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2311 "2863 New FCF (x%x) matches "
2312 "property of in-use FCF (x%x)\n",
2313 bf_get(lpfc_fcf_record_fcf_index,
2315 phba->fcf.current_rec.fcf_indx);
2318 * Read next FCF record from HBA searching for the matching
2319 * with in-use record only if not during the fast failover
2320 * period. In case of fast failover period, it shall try to
2321 * determine whether the FCF record just read should be the
2324 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2325 spin_unlock_irq(&phba->hbalock);
2330 * Update on failover FCF record only if it's in FCF fast-failover
2331 * period; otherwise, update on current FCF record.
2333 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2334 fcf_rec = &phba->fcf.failover_rec;
2336 fcf_rec = &phba->fcf.current_rec;
2338 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2340 * If the driver FCF record does not have boot flag
2341 * set and new hba fcf record has boot flag set, use
2342 * the new hba fcf record.
2344 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2345 /* Choose this FCF record */
2346 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2347 "2837 Update current FCF record "
2348 "(x%x) with new FCF record (x%x)\n",
2350 bf_get(lpfc_fcf_record_fcf_index,
2352 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2353 addr_mode, vlan_id, BOOT_ENABLE);
2354 spin_unlock_irq(&phba->hbalock);
2358 * If the driver FCF record has boot flag set and the
2359 * new hba FCF record does not have boot flag, read
2360 * the next FCF record.
2362 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2363 spin_unlock_irq(&phba->hbalock);
2367 * If the new hba FCF record has lower priority value
2368 * than the driver FCF record, use the new record.
2370 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2371 /* Choose the new FCF record with lower priority */
2372 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2373 "2838 Update current FCF record "
2374 "(x%x) with new FCF record (x%x)\n",
2376 bf_get(lpfc_fcf_record_fcf_index,
2378 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2379 addr_mode, vlan_id, 0);
2380 /* Reset running random FCF selection count */
2381 phba->fcf.eligible_fcf_cnt = 1;
2382 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2383 /* Update running random FCF selection count */
2384 phba->fcf.eligible_fcf_cnt++;
2385 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2386 phba->fcf.eligible_fcf_cnt);
2387 if (select_new_fcf) {
2388 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2389 "2839 Update current FCF record "
2390 "(x%x) with new FCF record (x%x)\n",
2392 bf_get(lpfc_fcf_record_fcf_index,
2394 /* Choose the new FCF by random selection */
2395 __lpfc_update_fcf_record(phba, fcf_rec,
2397 addr_mode, vlan_id, 0);
2400 spin_unlock_irq(&phba->hbalock);
2404 * This is the first suitable FCF record, choose this record for
2405 * initial best-fit FCF.
2408 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2409 "2840 Update initial FCF candidate "
2411 bf_get(lpfc_fcf_record_fcf_index,
2413 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2414 addr_mode, vlan_id, (boot_flag ?
2416 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2417 /* Setup initial running random FCF selection count */
2418 phba->fcf.eligible_fcf_cnt = 1;
2420 spin_unlock_irq(&phba->hbalock);
2424 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2425 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2426 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2428 * Case of FCF fast failover scan
2432 * It has not found any suitable FCF record, cancel
2433 * FCF scan inprogress, and do nothing
2435 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2436 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2437 "2782 No suitable FCF found: "
2439 phba->fcoe_eventtag_at_fcf_scan,
2440 bf_get(lpfc_fcf_record_fcf_index,
2442 spin_lock_irq(&phba->hbalock);
2443 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2444 phba->hba_flag &= ~FCF_TS_INPROG;
2445 spin_unlock_irq(&phba->hbalock);
2446 /* Unregister in-use FCF and rescan */
2447 lpfc_printf_log(phba, KERN_INFO,
2449 "2864 On devloss tmo "
2450 "unreg in-use FCF and "
2451 "rescan FCF table\n");
2452 lpfc_unregister_fcf_rescan(phba);
2456 * Let next new FCF event trigger fast failover
2458 phba->hba_flag &= ~FCF_TS_INPROG;
2459 spin_unlock_irq(&phba->hbalock);
2463 * It has found a suitable FCF record that is not
2464 * the same as in-use FCF record, unregister the
2465 * in-use FCF record, replace the in-use FCF record
2466 * with the new FCF record, mark FCF fast failover
2467 * completed, and then start register the new FCF
2471 /* Unregister the current in-use FCF record */
2472 lpfc_unregister_fcf(phba);
2474 /* Replace in-use record with the new record */
2475 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2476 "2842 Replace in-use FCF (x%x) "
2477 "with failover FCF (x%x)\n",
2478 phba->fcf.current_rec.fcf_indx,
2479 phba->fcf.failover_rec.fcf_indx);
2480 memcpy(&phba->fcf.current_rec,
2481 &phba->fcf.failover_rec,
2482 sizeof(struct lpfc_fcf_rec));
2484 * Mark the fast FCF failover rediscovery completed
2485 * and the start of the first round of the roundrobin
2488 spin_lock_irq(&phba->hbalock);
2489 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2490 spin_unlock_irq(&phba->hbalock);
2491 /* Register to the new FCF record */
2492 lpfc_register_fcf(phba);
2495 * In case of transaction period to fast FCF failover,
2496 * do nothing when search to the end of the FCF table.
2498 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2499 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2502 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2503 phba->fcf.fcf_flag & FCF_IN_USE) {
2505 * In case the current in-use FCF record no
2506 * longer existed during FCF discovery that
2507 * was not triggered by fast FCF failover
2508 * process, treat it as fast FCF failover.
2510 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2511 "2841 In-use FCF record (x%x) "
2512 "not reported, entering fast "
2513 "FCF failover mode scanning.\n",
2514 phba->fcf.current_rec.fcf_indx);
2515 spin_lock_irq(&phba->hbalock);
2516 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2517 spin_unlock_irq(&phba->hbalock);
2518 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2519 LPFC_FCOE_FCF_GET_FIRST);
2522 /* Register to the new FCF record */
2523 lpfc_register_fcf(phba);
2526 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2530 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2531 lpfc_register_fcf(phba);
2537 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2538 * @phba: pointer to lpfc hba data structure.
2539 * @mboxq: pointer to mailbox object.
2541 * This is the callback function for FLOGI failure roundrobin FCF failover
2542 * read FCF record mailbox command from the eligible FCF record bmask for
2543 * performing the failover. If the FCF read back is not valid/available, it
2544 * fails through to retrying FLOGI to the currently registered FCF again.
2545 * Otherwise, if the FCF read back is valid and available, it will set the
2546 * newly read FCF record to the failover FCF record, unregister currently
2547 * registered FCF record, copy the failover FCF record to the current
2548 * FCF record, and then register the current FCF record before proceeding
2549 * to trying FLOGI on the new failover FCF.
2552 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2554 struct fcf_record *new_fcf_record;
2555 uint32_t boot_flag, addr_mode;
2556 uint16_t next_fcf_index, fcf_index;
2557 uint16_t current_fcf_index;
2561 /* If link state is not up, stop the roundrobin failover process */
2562 if (phba->link_state < LPFC_LINK_UP) {
2563 spin_lock_irq(&phba->hbalock);
2564 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2565 phba->hba_flag &= ~FCF_RR_INPROG;
2566 spin_unlock_irq(&phba->hbalock);
2570 /* Parse the FCF record from the non-embedded mailbox command */
2571 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2573 if (!new_fcf_record) {
2574 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2575 "2766 Mailbox command READ_FCF_RECORD "
2576 "failed to retrieve a FCF record. "
2577 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2578 phba->fcf.fcf_flag);
2579 lpfc_unregister_fcf_rescan(phba);
2583 /* Get the needed parameters from FCF record */
2584 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2585 &addr_mode, &vlan_id);
2587 /* Log the FCF record information if turned on */
2588 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2591 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2593 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2594 "2848 Remove ineligible FCF (x%x) from "
2595 "from roundrobin bmask\n", fcf_index);
2596 /* Clear roundrobin bmask bit for ineligible FCF */
2597 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2598 /* Perform next round of roundrobin FCF failover */
2599 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2600 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2606 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2607 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2608 "2760 Perform FLOGI roundrobin FCF failover: "
2609 "FCF (x%x) back to FCF (x%x)\n",
2610 phba->fcf.current_rec.fcf_indx, fcf_index);
2611 /* Wait 500 ms before retrying FLOGI to current FCF */
2613 lpfc_issue_init_vfi(phba->pport);
2617 /* Upload new FCF record to the failover FCF record */
2618 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2619 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2620 phba->fcf.failover_rec.fcf_indx, fcf_index);
2621 spin_lock_irq(&phba->hbalock);
2622 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2623 new_fcf_record, addr_mode, vlan_id,
2624 (boot_flag ? BOOT_ENABLE : 0));
2625 spin_unlock_irq(&phba->hbalock);
2627 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2629 /* Unregister the current in-use FCF record */
2630 lpfc_unregister_fcf(phba);
2632 /* Replace in-use record with the new record */
2633 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2634 sizeof(struct lpfc_fcf_rec));
2636 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2637 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2638 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2641 lpfc_register_fcf(phba);
2643 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2647 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2648 * @phba: pointer to lpfc hba data structure.
2649 * @mboxq: pointer to mailbox object.
2651 * This is the callback function of read FCF record mailbox command for
2652 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2653 * failover when a new FCF event happened. If the FCF read back is
2654 * valid/available and it passes the connection list check, it updates
2655 * the bmask for the eligible FCF record for roundrobin failover.
2658 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2660 struct fcf_record *new_fcf_record;
2661 uint32_t boot_flag, addr_mode;
2662 uint16_t fcf_index, next_fcf_index;
2666 /* If link state is not up, no need to proceed */
2667 if (phba->link_state < LPFC_LINK_UP)
2670 /* If FCF discovery period is over, no need to proceed */
2671 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2674 /* Parse the FCF record from the non-embedded mailbox command */
2675 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2677 if (!new_fcf_record) {
2678 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2679 "2767 Mailbox command READ_FCF_RECORD "
2680 "failed to retrieve a FCF record.\n");
2684 /* Check the connection list for eligibility */
2685 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2686 &addr_mode, &vlan_id);
2688 /* Log the FCF record information if turned on */
2689 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2695 /* Update the eligible FCF record index bmask */
2696 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2698 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2701 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2705 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2706 * @phba: pointer to lpfc hba data structure.
2707 * @mboxq: pointer to mailbox data structure.
2709 * This function handles completion of init vfi mailbox command.
2712 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2714 struct lpfc_vport *vport = mboxq->vport;
2717 * VFI not supported on interface type 0, just do the flogi
2718 * Also continue if the VFI is in use - just use the same one.
2720 if (mboxq->u.mb.mbxStatus &&
2721 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2722 LPFC_SLI_INTF_IF_TYPE_0) &&
2723 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2724 lpfc_printf_vlog(vport, KERN_ERR,
2726 "2891 Init VFI mailbox failed 0x%x\n",
2727 mboxq->u.mb.mbxStatus);
2728 mempool_free(mboxq, phba->mbox_mem_pool);
2729 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2733 lpfc_initial_flogi(vport);
2734 mempool_free(mboxq, phba->mbox_mem_pool);
2739 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2740 * @vport: pointer to lpfc_vport data structure.
2742 * This function issue a init_vfi mailbox command to initialize the VFI and
2743 * VPI for the physical port.
2746 lpfc_issue_init_vfi(struct lpfc_vport *vport)
2748 LPFC_MBOXQ_t *mboxq;
2750 struct lpfc_hba *phba = vport->phba;
2752 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2754 lpfc_printf_vlog(vport, KERN_ERR,
2755 LOG_MBOX, "2892 Failed to allocate "
2756 "init_vfi mailbox\n");
2759 lpfc_init_vfi(mboxq, vport);
2760 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2761 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2762 if (rc == MBX_NOT_FINISHED) {
2763 lpfc_printf_vlog(vport, KERN_ERR,
2764 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2765 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2770 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2771 * @phba: pointer to lpfc hba data structure.
2772 * @mboxq: pointer to mailbox data structure.
2774 * This function handles completion of init vpi mailbox command.
2777 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2779 struct lpfc_vport *vport = mboxq->vport;
2780 struct lpfc_nodelist *ndlp;
2781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2783 if (mboxq->u.mb.mbxStatus) {
2784 lpfc_printf_vlog(vport, KERN_ERR,
2786 "2609 Init VPI mailbox failed 0x%x\n",
2787 mboxq->u.mb.mbxStatus);
2788 mempool_free(mboxq, phba->mbox_mem_pool);
2789 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2792 spin_lock_irq(shost->host_lock);
2793 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2794 spin_unlock_irq(shost->host_lock);
2796 /* If this port is physical port or FDISC is done, do reg_vpi */
2797 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2798 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2800 lpfc_printf_vlog(vport, KERN_ERR,
2802 "2731 Cannot find fabric "
2803 "controller node\n");
2805 lpfc_register_new_vport(phba, vport, ndlp);
2806 mempool_free(mboxq, phba->mbox_mem_pool);
2810 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2811 lpfc_initial_fdisc(vport);
2813 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
2814 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2815 "2606 No NPIV Fabric support\n");
2817 mempool_free(mboxq, phba->mbox_mem_pool);
2822 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2823 * @vport: pointer to lpfc_vport data structure.
2825 * This function issue a init_vpi mailbox command to initialize
2826 * VPI for the vport.
2829 lpfc_issue_init_vpi(struct lpfc_vport *vport)
2831 LPFC_MBOXQ_t *mboxq;
2834 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2835 vpi = lpfc_alloc_vpi(vport->phba);
2837 lpfc_printf_vlog(vport, KERN_ERR,
2839 "3303 Failed to obtain vport vpi\n");
2840 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2846 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2848 lpfc_printf_vlog(vport, KERN_ERR,
2849 LOG_MBOX, "2607 Failed to allocate "
2850 "init_vpi mailbox\n");
2853 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2854 mboxq->vport = vport;
2855 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2856 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2857 if (rc == MBX_NOT_FINISHED) {
2858 lpfc_printf_vlog(vport, KERN_ERR,
2859 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2860 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2865 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2866 * @phba: pointer to lpfc hba data structure.
2868 * This function loops through the list of vports on the @phba and issues an
2869 * FDISC if possible.
2872 lpfc_start_fdiscs(struct lpfc_hba *phba)
2874 struct lpfc_vport **vports;
2877 vports = lpfc_create_vport_work_array(phba);
2878 if (vports != NULL) {
2879 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2880 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2882 /* There are no vpi for this vport */
2883 if (vports[i]->vpi > phba->max_vpi) {
2884 lpfc_vport_set_state(vports[i],
2888 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2889 lpfc_vport_set_state(vports[i],
2893 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
2894 lpfc_issue_init_vpi(vports[i]);
2897 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2898 lpfc_initial_fdisc(vports[i]);
2900 lpfc_vport_set_state(vports[i],
2901 FC_VPORT_NO_FABRIC_SUPP);
2902 lpfc_printf_vlog(vports[i], KERN_ERR,
2905 "Fabric support\n");
2909 lpfc_destroy_vport_work_array(phba, vports);
2913 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2915 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2916 struct lpfc_vport *vport = mboxq->vport;
2917 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2920 * VFI not supported for interface type 0, so ignore any mailbox
2921 * error (except VFI in use) and continue with the discovery.
2923 if (mboxq->u.mb.mbxStatus &&
2924 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2925 LPFC_SLI_INTF_IF_TYPE_0) &&
2926 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2927 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2928 "2018 REG_VFI mbxStatus error x%x "
2930 mboxq->u.mb.mbxStatus, vport->port_state);
2931 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2932 /* FLOGI failed, use loop map to make discovery list */
2933 lpfc_disc_list_loopmap(vport);
2934 /* Start discovery */
2935 lpfc_disc_start(vport);
2938 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2942 /* If the VFI is already registered, there is nothing else to do
2943 * Unless this was a VFI update and we are in PT2PT mode, then
2944 * we should drop through to set the port state to ready.
2946 if (vport->fc_flag & FC_VFI_REGISTERED)
2947 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2948 vport->fc_flag & FC_PT2PT))
2951 /* The VPI is implicitly registered when the VFI is registered */
2952 spin_lock_irq(shost->host_lock);
2953 vport->vpi_state |= LPFC_VPI_REGISTERED;
2954 vport->fc_flag |= FC_VFI_REGISTERED;
2955 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2956 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2957 spin_unlock_irq(shost->host_lock);
2959 /* In case SLI4 FC loopback test, we are ready */
2960 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2961 (phba->link_flag & LS_LOOPBACK_MODE)) {
2962 phba->link_state = LPFC_HBA_READY;
2966 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
2967 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
2968 "alpacnt:%d LinkState:%x topology:%x\n",
2969 vport->port_state, vport->fc_flag, vport->fc_myDID,
2970 vport->phba->alpa_map[0],
2971 phba->link_state, phba->fc_topology);
2973 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
2975 * For private loop or for NPort pt2pt,
2976 * just start discovery and we are done.
2978 if ((vport->fc_flag & FC_PT2PT) ||
2979 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2980 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
2982 /* Use loop map to make discovery list */
2983 lpfc_disc_list_loopmap(vport);
2984 /* Start discovery */
2985 if (vport->fc_flag & FC_PT2PT)
2986 vport->port_state = LPFC_VPORT_READY;
2988 lpfc_disc_start(vport);
2990 lpfc_start_fdiscs(phba);
2991 lpfc_do_scr_ns_plogi(phba, vport);
2996 mempool_free(mboxq, phba->mbox_mem_pool);
2998 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3005 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3007 MAILBOX_t *mb = &pmb->u.mb;
3008 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
3009 struct lpfc_vport *vport = pmb->vport;
3010 struct serv_parm *sp = &vport->fc_sparam;
3013 /* Check for error */
3014 if (mb->mbxStatus) {
3015 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3016 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3017 "0319 READ_SPARAM mbxStatus error x%x "
3019 mb->mbxStatus, vport->port_state);
3020 lpfc_linkdown(phba);
3024 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3025 sizeof (struct serv_parm));
3027 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3028 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3029 ed_tov = (ed_tov + 999999) / 1000000;
3031 phba->fc_edtov = ed_tov;
3032 phba->fc_ratov = (2 * ed_tov) / 1000;
3033 if (phba->fc_ratov < FF_DEF_RATOV) {
3034 /* RA_TOV should be atleast 10sec for initial flogi */
3035 phba->fc_ratov = FF_DEF_RATOV;
3038 lpfc_update_vport_wwn(vport);
3039 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3040 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3041 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3044 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3046 mempool_free(pmb, phba->mbox_mem_pool);
3050 pmb->context1 = NULL;
3051 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3053 lpfc_issue_clear_la(phba, vport);
3054 mempool_free(pmb, phba->mbox_mem_pool);
3059 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3061 struct lpfc_vport *vport = phba->pport;
3062 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3063 struct Scsi_Host *shost;
3065 struct lpfc_dmabuf *mp;
3067 struct fcf_record *fcf_record;
3068 uint32_t fc_flags = 0;
3070 spin_lock_irq(&phba->hbalock);
3071 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3073 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3074 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3075 case LPFC_LINK_SPEED_1GHZ:
3076 case LPFC_LINK_SPEED_2GHZ:
3077 case LPFC_LINK_SPEED_4GHZ:
3078 case LPFC_LINK_SPEED_8GHZ:
3079 case LPFC_LINK_SPEED_10GHZ:
3080 case LPFC_LINK_SPEED_16GHZ:
3081 case LPFC_LINK_SPEED_32GHZ:
3084 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3089 if (phba->fc_topology &&
3090 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3091 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3092 "3314 Toplogy changed was 0x%x is 0x%x\n",
3094 bf_get(lpfc_mbx_read_top_topology, la));
3095 phba->fc_topology_changed = 1;
3098 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3099 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
3101 shost = lpfc_shost_from_vport(vport);
3102 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3103 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3105 /* if npiv is enabled and this adapter supports npiv log
3106 * a message that npiv is not supported in this topology
3108 if (phba->cfg_enable_npiv && phba->max_vpi)
3109 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3110 "1309 Link Up Event npiv not supported in loop "
3112 /* Get Loop Map information */
3113 if (bf_get(lpfc_mbx_read_top_il, la))
3114 fc_flags |= FC_LBIT;
3116 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3117 i = la->lilpBde64.tus.f.bdeSize;
3120 phba->alpa_map[0] = 0;
3122 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3133 numalpa = phba->alpa_map[0];
3135 while (j < numalpa) {
3136 memset(un.pamap, 0, 16);
3137 for (k = 1; j < numalpa; k++) {
3139 phba->alpa_map[j + 1];
3144 /* Link Up Event ALPA map */
3145 lpfc_printf_log(phba,
3148 "1304 Link Up Event "
3149 "ALPA map Data: x%x "
3151 un.pa.wd1, un.pa.wd2,
3152 un.pa.wd3, un.pa.wd4);
3157 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3158 if (phba->max_vpi && phba->cfg_enable_npiv &&
3159 (phba->sli_rev >= LPFC_SLI_REV3))
3160 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3162 vport->fc_myDID = phba->fc_pref_DID;
3163 fc_flags |= FC_LBIT;
3165 spin_unlock_irq(&phba->hbalock);
3168 spin_lock_irq(shost->host_lock);
3169 vport->fc_flag |= fc_flags;
3170 spin_unlock_irq(shost->host_lock);
3174 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3178 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3180 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3183 sparam_mbox->vport = vport;
3184 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3185 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3186 if (rc == MBX_NOT_FINISHED) {
3187 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
3188 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3190 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3194 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3195 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3198 vport->port_state = LPFC_LOCAL_CFG_LINK;
3199 lpfc_config_link(phba, cfglink_mbox);
3200 cfglink_mbox->vport = vport;
3201 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3202 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3203 if (rc == MBX_NOT_FINISHED) {
3204 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3208 vport->port_state = LPFC_VPORT_UNKNOWN;
3210 * Add the driver's default FCF record at FCF index 0 now. This
3211 * is phase 1 implementation that support FCF index 0 and driver
3214 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3215 fcf_record = kzalloc(sizeof(struct fcf_record),
3217 if (unlikely(!fcf_record)) {
3218 lpfc_printf_log(phba, KERN_ERR,
3220 "2554 Could not allocate memory for "
3226 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3227 LPFC_FCOE_FCF_DEF_INDEX);
3228 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3230 lpfc_printf_log(phba, KERN_ERR,
3232 "2013 Could not manually add FCF "
3233 "record 0, status %d\n", rc);
3241 * The driver is expected to do FIP/FCF. Call the port
3242 * and get the FCF Table.
3244 spin_lock_irq(&phba->hbalock);
3245 if (phba->hba_flag & FCF_TS_INPROG) {
3246 spin_unlock_irq(&phba->hbalock);
3249 /* This is the initial FCF discovery scan */
3250 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3251 spin_unlock_irq(&phba->hbalock);
3252 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3253 "2778 Start FCF table scan at linkup\n");
3254 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3255 LPFC_FCOE_FCF_GET_FIRST);
3257 spin_lock_irq(&phba->hbalock);
3258 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3259 spin_unlock_irq(&phba->hbalock);
3262 /* Reset FCF roundrobin bmask for new discovery */
3263 lpfc_sli4_clear_fcf_rr_bmask(phba);
3268 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3269 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3270 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3271 vport->port_state, sparam_mbox, cfglink_mbox);
3272 lpfc_issue_clear_la(phba, vport);
3277 lpfc_enable_la(struct lpfc_hba *phba)
3280 struct lpfc_sli *psli = &phba->sli;
3281 spin_lock_irq(&phba->hbalock);
3282 psli->sli_flag |= LPFC_PROCESS_LA;
3283 if (phba->sli_rev <= LPFC_SLI_REV3) {
3284 control = readl(phba->HCregaddr);
3285 control |= HC_LAINT_ENA;
3286 writel(control, phba->HCregaddr);
3287 readl(phba->HCregaddr); /* flush */
3289 spin_unlock_irq(&phba->hbalock);
3293 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3295 lpfc_linkdown(phba);
3296 lpfc_enable_la(phba);
3297 lpfc_unregister_unused_fcf(phba);
3298 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3303 * This routine handles processing a READ_TOPOLOGY mailbox
3304 * command upon completion. It is setup in the LPFC_MBOXQ
3305 * as the completion routine when the command is
3306 * handed off to the SLI layer.
3309 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3311 struct lpfc_vport *vport = pmb->vport;
3312 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3313 struct lpfc_mbx_read_top *la;
3314 MAILBOX_t *mb = &pmb->u.mb;
3315 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3317 /* Unblock ELS traffic */
3318 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
3319 /* Check for error */
3320 if (mb->mbxStatus) {
3321 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3322 "1307 READ_LA mbox error x%x state x%x\n",
3323 mb->mbxStatus, vport->port_state);
3324 lpfc_mbx_issue_link_down(phba);
3325 phba->link_state = LPFC_HBA_ERROR;
3326 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3329 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3331 memcpy(&phba->alpa_map[0], mp->virt, 128);
3333 spin_lock_irq(shost->host_lock);
3334 if (bf_get(lpfc_mbx_read_top_pb, la))
3335 vport->fc_flag |= FC_BYPASSED_MODE;
3337 vport->fc_flag &= ~FC_BYPASSED_MODE;
3338 spin_unlock_irq(shost->host_lock);
3340 if (phba->fc_eventTag <= la->eventTag) {
3341 phba->fc_stat.LinkMultiEvent++;
3342 if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
3343 if (phba->fc_eventTag != 0)
3344 lpfc_linkdown(phba);
3347 phba->fc_eventTag = la->eventTag;
3348 if (phba->sli_rev < LPFC_SLI_REV4) {
3349 spin_lock_irq(&phba->hbalock);
3350 if (bf_get(lpfc_mbx_read_top_mm, la))
3351 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3353 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3354 spin_unlock_irq(&phba->hbalock);
3357 phba->link_events++;
3358 if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
3359 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3360 phba->fc_stat.LinkUp++;
3361 if (phba->link_flag & LS_LOOPBACK_MODE) {
3362 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3363 "1306 Link Up Event in loop back mode "
3364 "x%x received Data: x%x x%x x%x x%x\n",
3365 la->eventTag, phba->fc_eventTag,
3366 bf_get(lpfc_mbx_read_top_alpa_granted,
3368 bf_get(lpfc_mbx_read_top_link_spd, la),
3371 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3372 "1303 Link Up Event x%x received "
3373 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3374 la->eventTag, phba->fc_eventTag,
3375 bf_get(lpfc_mbx_read_top_alpa_granted,
3377 bf_get(lpfc_mbx_read_top_link_spd, la),
3379 bf_get(lpfc_mbx_read_top_mm, la),
3380 bf_get(lpfc_mbx_read_top_fa, la),
3381 phba->wait_4_mlo_maint_flg);
3383 lpfc_mbx_process_link_up(phba, la);
3384 } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
3385 LPFC_ATT_LINK_DOWN) {
3386 phba->fc_stat.LinkDown++;
3387 if (phba->link_flag & LS_LOOPBACK_MODE)
3388 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3389 "1308 Link Down Event in loop back mode "
3391 "Data: x%x x%x x%x\n",
3392 la->eventTag, phba->fc_eventTag,
3393 phba->pport->port_state, vport->fc_flag);
3395 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3396 "1305 Link Down Event x%x received "
3397 "Data: x%x x%x x%x x%x x%x\n",
3398 la->eventTag, phba->fc_eventTag,
3399 phba->pport->port_state, vport->fc_flag,
3400 bf_get(lpfc_mbx_read_top_mm, la),
3401 bf_get(lpfc_mbx_read_top_fa, la));
3402 lpfc_mbx_issue_link_down(phba);
3404 if ((phba->sli.sli_flag & LPFC_MENLO_MAINT) &&
3405 ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP))) {
3406 if (phba->link_state != LPFC_LINK_DOWN) {
3407 phba->fc_stat.LinkDown++;
3408 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3409 "1312 Link Down Event x%x received "
3410 "Data: x%x x%x x%x\n",
3411 la->eventTag, phba->fc_eventTag,
3412 phba->pport->port_state, vport->fc_flag);
3413 lpfc_mbx_issue_link_down(phba);
3415 lpfc_enable_la(phba);
3417 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3418 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3419 "Data: x%x x%x x%x\n",
3420 la->eventTag, phba->fc_eventTag,
3421 phba->pport->port_state, vport->fc_flag);
3423 * The cmnd that triggered this will be waiting for this
3426 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3427 if (phba->wait_4_mlo_maint_flg) {
3428 phba->wait_4_mlo_maint_flg = 0;
3429 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3433 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3434 bf_get(lpfc_mbx_read_top_fa, la)) {
3435 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3436 lpfc_issue_clear_la(phba, vport);
3437 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3439 bf_get(lpfc_mbx_read_top_fa, la));
3442 lpfc_mbx_cmpl_read_topology_free_mbuf:
3443 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3445 mempool_free(pmb, phba->mbox_mem_pool);
3450 * This routine handles processing a REG_LOGIN mailbox
3451 * command upon completion. It is setup in the LPFC_MBOXQ
3452 * as the completion routine when the command is
3453 * handed off to the SLI layer.
3456 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3458 struct lpfc_vport *vport = pmb->vport;
3459 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3460 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3461 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3463 pmb->context1 = NULL;
3464 pmb->context2 = NULL;
3466 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3467 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n",
3468 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3469 atomic_read(&ndlp->kref.refcount),
3470 ndlp->nlp_usg_map, ndlp);
3471 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3472 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3474 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3475 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3476 /* We rcvd a rscn after issuing this
3477 * mbox reg login, we may have cycled
3478 * back through the state and be
3479 * back at reg login state so this
3480 * mbox needs to be ignored becase
3481 * there is another reg login in
3484 spin_lock_irq(shost->host_lock);
3485 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3486 spin_unlock_irq(shost->host_lock);
3489 /* Call state machine */
3490 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3492 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3494 mempool_free(pmb, phba->mbox_mem_pool);
3495 /* decrement the node reference count held for this callback
3504 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3506 MAILBOX_t *mb = &pmb->u.mb;
3507 struct lpfc_vport *vport = pmb->vport;
3508 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3510 switch (mb->mbxStatus) {
3513 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3514 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3517 /* If VPI is busy, reset the HBA */
3519 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3520 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3521 vport->vpi, mb->mbxStatus);
3522 if (!(phba->pport->load_flag & FC_UNLOADING))
3523 lpfc_workq_post_event(phba, NULL, NULL,
3524 LPFC_EVT_RESET_HBA);
3526 spin_lock_irq(shost->host_lock);
3527 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3528 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3529 spin_unlock_irq(shost->host_lock);
3530 vport->unreg_vpi_cmpl = VPORT_OK;
3531 mempool_free(pmb, phba->mbox_mem_pool);
3532 lpfc_cleanup_vports_rrqs(vport, NULL);
3534 * This shost reference might have been taken at the beginning of
3535 * lpfc_vport_delete()
3537 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3538 scsi_host_put(shost);
3542 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3544 struct lpfc_hba *phba = vport->phba;
3548 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3552 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3553 mbox->vport = vport;
3554 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3555 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3556 if (rc == MBX_NOT_FINISHED) {
3557 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3558 "1800 Could not issue unreg_vpi\n");
3559 mempool_free(mbox, phba->mbox_mem_pool);
3560 vport->unreg_vpi_cmpl = VPORT_ERROR;
3567 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3569 struct lpfc_vport *vport = pmb->vport;
3570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3571 MAILBOX_t *mb = &pmb->u.mb;
3573 switch (mb->mbxStatus) {
3577 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3578 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3580 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3581 spin_lock_irq(shost->host_lock);
3582 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3583 spin_unlock_irq(shost->host_lock);
3584 vport->fc_myDID = 0;
3588 spin_lock_irq(shost->host_lock);
3589 vport->vpi_state |= LPFC_VPI_REGISTERED;
3590 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3591 spin_unlock_irq(shost->host_lock);
3592 vport->num_disc_nodes = 0;
3593 /* go thru NPR list and issue ELS PLOGIs */
3594 if (vport->fc_npr_cnt)
3595 lpfc_els_disc_plogi(vport);
3597 if (!vport->num_disc_nodes) {
3598 spin_lock_irq(shost->host_lock);
3599 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3600 spin_unlock_irq(shost->host_lock);
3601 lpfc_can_disctmo(vport);
3603 vport->port_state = LPFC_VPORT_READY;
3606 mempool_free(pmb, phba->mbox_mem_pool);
3611 * lpfc_create_static_vport - Read HBA config region to create static vports.
3612 * @phba: pointer to lpfc hba data structure.
3614 * This routine issue a DUMP mailbox command for config region 22 to get
3615 * the list of static vports to be created. The function create vports
3616 * based on the information returned from the HBA.
3619 lpfc_create_static_vport(struct lpfc_hba *phba)
3621 LPFC_MBOXQ_t *pmb = NULL;
3623 struct static_vport_info *vport_info;
3624 int mbx_wait_rc = 0, i;
3625 struct fc_vport_identifiers vport_id;
3626 struct fc_vport *new_fc_vport;
3627 struct Scsi_Host *shost;
3628 struct lpfc_vport *vport;
3629 uint16_t offset = 0;
3630 uint8_t *vport_buff;
3631 struct lpfc_dmabuf *mp;
3632 uint32_t byte_count = 0;
3634 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3636 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3637 "0542 lpfc_create_static_vport failed to"
3638 " allocate mailbox memory\n");
3641 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3644 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3646 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3647 "0543 lpfc_create_static_vport failed to"
3648 " allocate vport_info\n");
3649 mempool_free(pmb, phba->mbox_mem_pool);
3653 vport_buff = (uint8_t *) vport_info;
3655 /* free dma buffer from previous round */
3656 if (pmb->context1) {
3657 mp = (struct lpfc_dmabuf *)pmb->context1;
3658 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3661 if (lpfc_dump_static_vport(phba, pmb, offset))
3664 pmb->vport = phba->pport;
3665 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3668 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3669 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3670 "0544 lpfc_create_static_vport failed to"
3671 " issue dump mailbox command ret 0x%x "
3673 mbx_wait_rc, mb->mbxStatus);
3677 if (phba->sli_rev == LPFC_SLI_REV4) {
3678 byte_count = pmb->u.mqe.un.mb_words[5];
3679 mp = (struct lpfc_dmabuf *)pmb->context1;
3680 if (byte_count > sizeof(struct static_vport_info) -
3682 byte_count = sizeof(struct static_vport_info)
3684 memcpy(vport_buff + offset, mp->virt, byte_count);
3685 offset += byte_count;
3687 if (mb->un.varDmp.word_cnt >
3688 sizeof(struct static_vport_info) - offset)
3689 mb->un.varDmp.word_cnt =
3690 sizeof(struct static_vport_info)
3692 byte_count = mb->un.varDmp.word_cnt;
3693 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3694 vport_buff + offset,
3697 offset += byte_count;
3700 } while (byte_count &&
3701 offset < sizeof(struct static_vport_info));
3704 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3705 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3706 != VPORT_INFO_REV)) {
3707 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3708 "0545 lpfc_create_static_vport bad"
3709 " information header 0x%x 0x%x\n",
3710 le32_to_cpu(vport_info->signature),
3711 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3716 shost = lpfc_shost_from_vport(phba->pport);
3718 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3719 memset(&vport_id, 0, sizeof(vport_id));
3720 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3721 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3722 if (!vport_id.port_name || !vport_id.node_name)
3725 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3726 vport_id.vport_type = FC_PORTTYPE_NPIV;
3727 vport_id.disable = false;
3728 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3730 if (!new_fc_vport) {
3731 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3732 "0546 lpfc_create_static_vport failed to"
3737 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3738 vport->vport_flag |= STATIC_VPORT;
3743 if (mbx_wait_rc != MBX_TIMEOUT) {
3744 if (pmb->context1) {
3745 mp = (struct lpfc_dmabuf *)pmb->context1;
3746 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3749 mempool_free(pmb, phba->mbox_mem_pool);
3756 * This routine handles processing a Fabric REG_LOGIN mailbox
3757 * command upon completion. It is setup in the LPFC_MBOXQ
3758 * as the completion routine when the command is
3759 * handed off to the SLI layer.
3762 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3764 struct lpfc_vport *vport = pmb->vport;
3765 MAILBOX_t *mb = &pmb->u.mb;
3766 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3767 struct lpfc_nodelist *ndlp;
3768 struct Scsi_Host *shost;
3770 ndlp = (struct lpfc_nodelist *) pmb->context2;
3771 pmb->context1 = NULL;
3772 pmb->context2 = NULL;
3774 if (mb->mbxStatus) {
3775 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3776 "0258 Register Fabric login error: 0x%x\n",
3778 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3780 mempool_free(pmb, phba->mbox_mem_pool);
3782 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3783 /* FLOGI failed, use loop map to make discovery list */
3784 lpfc_disc_list_loopmap(vport);
3786 /* Start discovery */
3787 lpfc_disc_start(vport);
3788 /* Decrement the reference count to ndlp after the
3789 * reference to the ndlp are done.
3795 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3796 /* Decrement the reference count to ndlp after the reference
3797 * to the ndlp are done.
3803 if (phba->sli_rev < LPFC_SLI_REV4)
3804 ndlp->nlp_rpi = mb->un.varWords[0];
3805 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3806 ndlp->nlp_type |= NLP_FABRIC;
3807 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3809 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3810 /* when physical port receive logo donot start
3811 * vport discovery */
3812 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3813 lpfc_start_fdiscs(phba);
3815 shost = lpfc_shost_from_vport(vport);
3816 spin_lock_irq(shost->host_lock);
3817 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
3818 spin_unlock_irq(shost->host_lock);
3820 lpfc_do_scr_ns_plogi(phba, vport);
3823 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3825 mempool_free(pmb, phba->mbox_mem_pool);
3827 /* Drop the reference count from the mbox at the end after
3828 * all the current reference to the ndlp have been done.
3835 * This routine handles processing a NameServer REG_LOGIN mailbox
3836 * command upon completion. It is setup in the LPFC_MBOXQ
3837 * as the completion routine when the command is
3838 * handed off to the SLI layer.
3841 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3843 MAILBOX_t *mb = &pmb->u.mb;
3844 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3845 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3846 struct lpfc_vport *vport = pmb->vport;
3848 pmb->context1 = NULL;
3849 pmb->context2 = NULL;
3851 if (mb->mbxStatus) {
3853 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3854 "0260 Register NameServer error: 0x%x\n",
3856 /* decrement the node reference count held for this
3857 * callback function.
3860 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3862 mempool_free(pmb, phba->mbox_mem_pool);
3864 /* If no other thread is using the ndlp, free it */
3865 lpfc_nlp_not_used(ndlp);
3867 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3869 * RegLogin failed, use loop map to make discovery
3872 lpfc_disc_list_loopmap(vport);
3874 /* Start discovery */
3875 lpfc_disc_start(vport);
3878 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3882 if (phba->sli_rev < LPFC_SLI_REV4)
3883 ndlp->nlp_rpi = mb->un.varWords[0];
3884 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3885 ndlp->nlp_type |= NLP_FABRIC;
3886 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3887 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3888 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n",
3889 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3890 atomic_read(&ndlp->kref.refcount),
3891 ndlp->nlp_usg_map, ndlp);
3893 if (vport->port_state < LPFC_VPORT_READY) {
3894 /* Link up discovery requires Fabric registration. */
3895 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3896 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3897 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3898 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3899 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0);
3901 /* Issue SCR just before NameServer GID_FT Query */
3902 lpfc_issue_els_scr(vport, SCR_DID, 0);
3905 vport->fc_ns_retry = 0;
3906 /* Good status, issue CT Request to NameServer */
3907 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
3908 /* Cannot issue NameServer Query, so finish up discovery */
3912 /* decrement the node reference count held for this
3913 * callback function.
3916 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3918 mempool_free(pmb, phba->mbox_mem_pool);
3924 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3926 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3927 struct fc_rport *rport;
3928 struct lpfc_rport_data *rdata;
3929 struct fc_rport_identifiers rport_ids;
3930 struct lpfc_hba *phba = vport->phba;
3932 /* Remote port has reappeared. Re-register w/ FC transport */
3933 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3934 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
3935 rport_ids.port_id = ndlp->nlp_DID;
3936 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3939 * We leave our node pointer in rport->dd_data when we unregister a
3940 * FCP target port. But fc_remote_port_add zeros the space to which
3941 * rport->dd_data points. So, if we're reusing a previously
3942 * registered port, drop the reference that we took the last time we
3943 * registered the port.
3945 rport = ndlp->rport;
3947 rdata = rport->dd_data;
3948 /* break the link before dropping the ref */
3950 if (rdata && rdata->pnode == ndlp)
3952 rdata->pnode = NULL;
3953 /* drop reference for earlier registeration */
3954 put_device(&rport->dev);
3957 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3958 "rport add: did:x%x flg:x%x type x%x",
3959 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3961 /* Don't add the remote port if unloading. */
3962 if (vport->load_flag & FC_UNLOADING)
3965 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
3966 if (!rport || !get_device(&rport->dev)) {
3967 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3968 "Warning: fc_remote_port_add failed\n");
3972 /* initialize static port data */
3973 rport->maxframe_size = ndlp->nlp_maxframe;
3974 rport->supported_classes = ndlp->nlp_class_sup;
3975 rdata = rport->dd_data;
3976 rdata->pnode = lpfc_nlp_get(ndlp);
3978 if (ndlp->nlp_type & NLP_FCP_TARGET)
3979 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3980 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3981 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3983 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3984 fc_remote_port_rolechg(rport, rport_ids.roles);
3986 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3987 "3183 rport register x%06x, rport %p role x%x\n",
3988 ndlp->nlp_DID, rport, rport_ids.roles);
3990 if ((rport->scsi_target_id != -1) &&
3991 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
3992 ndlp->nlp_sid = rport->scsi_target_id;
3998 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4000 struct fc_rport *rport = ndlp->rport;
4002 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
4003 "rport delete: did:x%x flg:x%x type x%x",
4004 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4006 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4007 "3184 rport unregister x%06x, rport %p\n",
4008 ndlp->nlp_DID, rport);
4010 fc_remote_port_delete(rport);
4016 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4020 spin_lock_irq(shost->host_lock);
4022 case NLP_STE_UNUSED_NODE:
4023 vport->fc_unused_cnt += count;
4025 case NLP_STE_PLOGI_ISSUE:
4026 vport->fc_plogi_cnt += count;
4028 case NLP_STE_ADISC_ISSUE:
4029 vport->fc_adisc_cnt += count;
4031 case NLP_STE_REG_LOGIN_ISSUE:
4032 vport->fc_reglogin_cnt += count;
4034 case NLP_STE_PRLI_ISSUE:
4035 vport->fc_prli_cnt += count;
4037 case NLP_STE_UNMAPPED_NODE:
4038 vport->fc_unmap_cnt += count;
4040 case NLP_STE_MAPPED_NODE:
4041 vport->fc_map_cnt += count;
4043 case NLP_STE_NPR_NODE:
4044 if (vport->fc_npr_cnt == 0 && count == -1)
4045 vport->fc_npr_cnt = 0;
4047 vport->fc_npr_cnt += count;
4050 spin_unlock_irq(shost->host_lock);
4054 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4055 int old_state, int new_state)
4057 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4059 if (new_state == NLP_STE_UNMAPPED_NODE) {
4060 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4061 ndlp->nlp_type |= NLP_FC_NODE;
4063 if (new_state == NLP_STE_MAPPED_NODE)
4064 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4065 if (new_state == NLP_STE_NPR_NODE)
4066 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4068 /* Transport interface */
4069 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
4070 old_state == NLP_STE_UNMAPPED_NODE)) {
4071 vport->phba->nport_event_cnt++;
4072 lpfc_unregister_remote_port(ndlp);
4075 if (new_state == NLP_STE_MAPPED_NODE ||
4076 new_state == NLP_STE_UNMAPPED_NODE) {
4077 vport->phba->nport_event_cnt++;
4079 * Tell the fc transport about the port, if we haven't
4080 * already. If we have, and it's a scsi entity, be
4081 * sure to unblock any attached scsi devices
4083 lpfc_register_remote_port(vport, ndlp);
4085 if ((new_state == NLP_STE_MAPPED_NODE) &&
4086 (vport->stat_data_enabled)) {
4088 * A new target is discovered, if there is no buffer for
4089 * statistical data collection allocate buffer.
4091 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4092 sizeof(struct lpfc_scsicmd_bkt),
4095 if (!ndlp->lat_data)
4096 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4097 "0286 lpfc_nlp_state_cleanup failed to "
4098 "allocate statistical data buffer DID "
4099 "0x%x\n", ndlp->nlp_DID);
4102 * if we added to Mapped list, but the remote port
4103 * registration failed or assigned a target id outside
4104 * our presentable range - move the node to the
4107 if (new_state == NLP_STE_MAPPED_NODE &&
4109 ndlp->rport->scsi_target_id == -1 ||
4110 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4111 spin_lock_irq(shost->host_lock);
4112 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4113 spin_unlock_irq(shost->host_lock);
4114 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4119 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4121 static char *states[] = {
4122 [NLP_STE_UNUSED_NODE] = "UNUSED",
4123 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4124 [NLP_STE_ADISC_ISSUE] = "ADISC",
4125 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4126 [NLP_STE_PRLI_ISSUE] = "PRLI",
4127 [NLP_STE_LOGO_ISSUE] = "LOGO",
4128 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4129 [NLP_STE_MAPPED_NODE] = "MAPPED",
4130 [NLP_STE_NPR_NODE] = "NPR",
4133 if (state < NLP_STE_MAX_STATE && states[state])
4134 strlcpy(buffer, states[state], size);
4136 snprintf(buffer, size, "unknown (%d)", state);
4141 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4144 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4145 int old_state = ndlp->nlp_state;
4146 char name1[16], name2[16];
4148 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4149 "0904 NPort state transition x%06x, %s -> %s\n",
4151 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4152 lpfc_nlp_state_name(name2, sizeof(name2), state));
4154 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4155 "node statechg did:x%x old:%d ste:%d",
4156 ndlp->nlp_DID, old_state, state);
4158 if (old_state == NLP_STE_NPR_NODE &&
4159 state != NLP_STE_NPR_NODE)
4160 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4161 if (old_state == NLP_STE_UNMAPPED_NODE) {
4162 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4163 ndlp->nlp_type &= ~NLP_FC_NODE;
4166 if (list_empty(&ndlp->nlp_listp)) {
4167 spin_lock_irq(shost->host_lock);
4168 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4169 spin_unlock_irq(shost->host_lock);
4170 } else if (old_state)
4171 lpfc_nlp_counters(vport, old_state, -1);
4173 ndlp->nlp_state = state;
4174 lpfc_nlp_counters(vport, state, 1);
4175 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4179 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4183 if (list_empty(&ndlp->nlp_listp)) {
4184 spin_lock_irq(shost->host_lock);
4185 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4186 spin_unlock_irq(shost->host_lock);
4191 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4193 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4195 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4196 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4197 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4198 spin_lock_irq(shost->host_lock);
4199 list_del_init(&ndlp->nlp_listp);
4200 spin_unlock_irq(shost->host_lock);
4201 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4202 NLP_STE_UNUSED_NODE);
4206 lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4208 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4209 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4210 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4211 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4212 NLP_STE_UNUSED_NODE);
4215 * lpfc_initialize_node - Initialize all fields of node object
4216 * @vport: Pointer to Virtual Port object.
4217 * @ndlp: Pointer to FC node object.
4218 * @did: FC_ID of the node.
4220 * This function is always called when node object need to be initialized.
4221 * It initializes all the fields of the node object. Although the reference
4222 * to phba from @ndlp can be obtained indirectly through it's reference to
4223 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4224 * to the life-span of the @ndlp might go beyond the existence of @vport as
4225 * the final release of ndlp is determined by its reference count. And, the
4226 * operation on @ndlp needs the reference to phba.
4229 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4232 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4233 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4234 init_timer(&ndlp->nlp_delayfunc);
4235 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
4236 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
4237 ndlp->nlp_DID = did;
4238 ndlp->vport = vport;
4239 ndlp->phba = vport->phba;
4240 ndlp->nlp_sid = NLP_NO_SID;
4241 kref_init(&ndlp->kref);
4242 NLP_INT_NODE_ACT(ndlp);
4243 atomic_set(&ndlp->cmd_pending, 0);
4244 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4247 struct lpfc_nodelist *
4248 lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4251 struct lpfc_hba *phba = vport->phba;
4253 unsigned long flags;
4254 unsigned long *active_rrqs_xri_bitmap = NULL;
4259 spin_lock_irqsave(&phba->ndlp_lock, flags);
4260 /* The ndlp should not be in memory free mode */
4261 if (NLP_CHK_FREE_REQ(ndlp)) {
4262 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4263 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4264 "0277 lpfc_enable_node: ndlp:x%p "
4265 "usgmap:x%x refcnt:%d\n",
4266 (void *)ndlp, ndlp->nlp_usg_map,
4267 atomic_read(&ndlp->kref.refcount));
4270 /* The ndlp should not already be in active mode */
4271 if (NLP_CHK_NODE_ACT(ndlp)) {
4272 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4273 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4274 "0278 lpfc_enable_node: ndlp:x%p "
4275 "usgmap:x%x refcnt:%d\n",
4276 (void *)ndlp, ndlp->nlp_usg_map,
4277 atomic_read(&ndlp->kref.refcount));
4281 /* Keep the original DID */
4282 did = ndlp->nlp_DID;
4283 if (phba->sli_rev == LPFC_SLI_REV4)
4284 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
4286 /* re-initialize ndlp except of ndlp linked list pointer */
4287 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4288 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
4289 lpfc_initialize_node(vport, ndlp, did);
4291 if (phba->sli_rev == LPFC_SLI_REV4)
4292 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4294 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4295 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4296 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
4297 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4298 "0008 rpi:%x DID:%x flg:%x refcnt:%d "
4299 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
4301 atomic_read(&ndlp->kref.refcount),
4302 ndlp->nlp_usg_map, ndlp);
4306 if (state != NLP_STE_UNUSED_NODE)
4307 lpfc_nlp_set_state(vport, ndlp, state);
4309 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4310 "node enable: did:x%x",
4311 ndlp->nlp_DID, 0, 0);
4316 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4319 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4320 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4321 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4322 * until ALL other outstanding threads have completed. We check
4323 * that the ndlp not already in the UNUSED state before we proceed.
4325 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4327 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4328 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4329 lpfc_cleanup_vports_rrqs(vport, ndlp);
4330 lpfc_unreg_rpi(vport, ndlp);
4338 * Start / ReStart rescue timer for Discovery / RSCN handling
4341 lpfc_set_disctmo(struct lpfc_vport *vport)
4343 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4344 struct lpfc_hba *phba = vport->phba;
4347 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4348 /* For FAN, timeout should be greater than edtov */
4349 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4351 /* Normal discovery timeout should be > than ELS/CT timeout
4352 * FC spec states we need 3 * ratov for CT requests
4354 tmo = ((phba->fc_ratov * 3) + 3);
4358 if (!timer_pending(&vport->fc_disctmo)) {
4359 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4360 "set disc timer: tmo:x%x state:x%x flg:x%x",
4361 tmo, vport->port_state, vport->fc_flag);
4364 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
4365 spin_lock_irq(shost->host_lock);
4366 vport->fc_flag |= FC_DISC_TMO;
4367 spin_unlock_irq(shost->host_lock);
4369 /* Start Discovery Timer state <hba_state> */
4370 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4371 "0247 Start Discovery Timer state x%x "
4372 "Data: x%x x%lx x%x x%x\n",
4373 vport->port_state, tmo,
4374 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4375 vport->fc_adisc_cnt);
4381 * Cancel rescue timer for Discovery / RSCN handling
4384 lpfc_can_disctmo(struct lpfc_vport *vport)
4386 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4387 unsigned long iflags;
4389 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4390 "can disc timer: state:x%x rtry:x%x flg:x%x",
4391 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4393 /* Turn off discovery timer if its running */
4394 if (vport->fc_flag & FC_DISC_TMO) {
4395 spin_lock_irqsave(shost->host_lock, iflags);
4396 vport->fc_flag &= ~FC_DISC_TMO;
4397 spin_unlock_irqrestore(shost->host_lock, iflags);
4398 del_timer_sync(&vport->fc_disctmo);
4399 spin_lock_irqsave(&vport->work_port_lock, iflags);
4400 vport->work_port_events &= ~WORKER_DISC_TMO;
4401 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4404 /* Cancel Discovery Timer state <hba_state> */
4405 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4406 "0248 Cancel Discovery Timer state x%x "
4407 "Data: x%x x%x x%x\n",
4408 vport->port_state, vport->fc_flag,
4409 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4414 * Check specified ring for outstanding IOCB on the SLI queue
4415 * Return true if iocb matches the specified nport
4418 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4419 struct lpfc_sli_ring *pring,
4420 struct lpfc_iocbq *iocb,
4421 struct lpfc_nodelist *ndlp)
4423 struct lpfc_sli *psli = &phba->sli;
4424 IOCB_t *icmd = &iocb->iocb;
4425 struct lpfc_vport *vport = ndlp->vport;
4427 if (iocb->vport != vport)
4430 if (pring->ringno == LPFC_ELS_RING) {
4431 switch (icmd->ulpCommand) {
4432 case CMD_GEN_REQUEST64_CR:
4433 if (iocb->context_un.ndlp == ndlp)
4435 case CMD_ELS_REQUEST64_CR:
4436 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4438 case CMD_XMIT_ELS_RSP64_CX:
4439 if (iocb->context1 == (uint8_t *) ndlp)
4442 } else if (pring->ringno == psli->extra_ring) {
4444 } else if (pring->ringno == psli->fcp_ring) {
4445 /* Skip match check if waiting to relogin to FCP target */
4446 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4447 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4450 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4453 } else if (pring->ringno == psli->next_ring) {
4460 * Free resources / clean up outstanding I/Os
4461 * associated with nlp_rpi in the LPFC_NODELIST entry.
4464 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
4466 LIST_HEAD(completions);
4467 struct lpfc_sli *psli;
4468 struct lpfc_sli_ring *pring;
4469 struct lpfc_iocbq *iocb, *next_iocb;
4472 lpfc_fabric_abort_nport(ndlp);
4475 * Everything that matches on txcmplq will be returned
4476 * by firmware with a no rpi error.
4479 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4480 /* Now process each ring */
4481 for (i = 0; i < psli->num_rings; i++) {
4482 pring = &psli->ring[i];
4484 spin_lock_irq(&phba->hbalock);
4485 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
4488 * Check to see if iocb matches the nport we are
4491 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
4493 /* It matches, so deque and call compl
4495 list_move_tail(&iocb->list,
4499 spin_unlock_irq(&phba->hbalock);
4503 /* Cancel all the IOCBs from the completions list */
4504 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4511 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4512 * @phba: Pointer to HBA context object.
4513 * @pmb: Pointer to mailbox object.
4515 * This function will issue an ELS LOGO command after completing
4519 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4521 struct lpfc_vport *vport = pmb->vport;
4522 struct lpfc_nodelist *ndlp;
4524 ndlp = (struct lpfc_nodelist *)(pmb->context1);
4527 lpfc_issue_els_logo(vport, ndlp, 0);
4528 mempool_free(pmb, phba->mbox_mem_pool);
4532 * Free rpi associated with LPFC_NODELIST entry.
4533 * This routine is called from lpfc_freenode(), when we are removing
4534 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4535 * LOGO that completes successfully, and we are waiting to PLOGI back
4536 * to the remote NPort. In addition, it is called after we receive
4537 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4538 * we are waiting to PLOGI back to the remote NPort.
4541 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4543 struct lpfc_hba *phba = vport->phba;
4545 int rc, acc_plogi = 1;
4548 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4549 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4550 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4551 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4552 "3366 RPI x%x needs to be "
4553 "unregistered nlp_flag x%x "
4555 ndlp->nlp_rpi, ndlp->nlp_flag,
4557 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4559 /* SLI4 ports require the physical rpi value. */
4560 rpi = ndlp->nlp_rpi;
4561 if (phba->sli_rev == LPFC_SLI_REV4)
4562 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4564 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
4565 mbox->vport = vport;
4566 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4567 mbox->context1 = ndlp;
4568 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4570 if (phba->sli_rev == LPFC_SLI_REV4 &&
4571 (!(vport->load_flag & FC_UNLOADING)) &&
4572 (bf_get(lpfc_sli_intf_if_type,
4573 &phba->sli4_hba.sli_intf) ==
4574 LPFC_SLI_INTF_IF_TYPE_2) &&
4575 (atomic_read(&ndlp->kref.refcount) > 0)) {
4576 mbox->context1 = lpfc_nlp_get(ndlp);
4578 lpfc_sli4_unreg_rpi_cmpl_clr;
4580 * accept PLOGIs after unreg_rpi_cmpl
4585 lpfc_sli_def_mbox_cmpl;
4588 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4589 if (rc == MBX_NOT_FINISHED) {
4590 mempool_free(mbox, phba->mbox_mem_pool);
4594 lpfc_no_rpi(phba, ndlp);
4596 if (phba->sli_rev != LPFC_SLI_REV4)
4598 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
4599 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4601 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4604 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4609 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4610 * @phba: pointer to lpfc hba data structure.
4612 * This routine is invoked to unregister all the currently registered RPIs
4616 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4618 struct lpfc_vport **vports;
4619 struct lpfc_nodelist *ndlp;
4620 struct Scsi_Host *shost;
4623 vports = lpfc_create_vport_work_array(phba);
4625 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4626 "2884 Vport array allocation failed \n");
4629 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4630 shost = lpfc_shost_from_vport(vports[i]);
4631 spin_lock_irq(shost->host_lock);
4632 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
4633 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4634 /* The mempool_alloc might sleep */
4635 spin_unlock_irq(shost->host_lock);
4636 lpfc_unreg_rpi(vports[i], ndlp);
4637 spin_lock_irq(shost->host_lock);
4640 spin_unlock_irq(shost->host_lock);
4642 lpfc_destroy_vport_work_array(phba, vports);
4646 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4648 struct lpfc_hba *phba = vport->phba;
4652 if (phba->sli_rev == LPFC_SLI_REV4) {
4653 lpfc_sli4_unreg_all_rpis(vport);
4657 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4659 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
4661 mbox->vport = vport;
4662 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4663 mbox->context1 = NULL;
4664 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4665 if (rc != MBX_TIMEOUT)
4666 mempool_free(mbox, phba->mbox_mem_pool);
4668 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4669 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4670 "1836 Could not issue "
4671 "unreg_login(all_rpis) status %d\n", rc);
4676 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4678 struct lpfc_hba *phba = vport->phba;
4682 /* Unreg DID is an SLI3 operation. */
4683 if (phba->sli_rev > LPFC_SLI_REV3)
4686 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4688 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
4690 mbox->vport = vport;
4691 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4692 mbox->context1 = NULL;
4693 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4694 if (rc != MBX_TIMEOUT)
4695 mempool_free(mbox, phba->mbox_mem_pool);
4697 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4698 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4699 "1815 Could not issue "
4700 "unreg_did (default rpis) status %d\n",
4706 * Free resources associated with LPFC_NODELIST entry
4707 * so it can be freed.
4710 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4712 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4713 struct lpfc_hba *phba = vport->phba;
4714 LPFC_MBOXQ_t *mb, *nextmb;
4715 struct lpfc_dmabuf *mp;
4717 /* Cleanup node for NPort <nlp_DID> */
4718 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4719 "0900 Cleanup node for NPort x%x "
4720 "Data: x%x x%x x%x\n",
4721 ndlp->nlp_DID, ndlp->nlp_flag,
4722 ndlp->nlp_state, ndlp->nlp_rpi);
4723 if (NLP_CHK_FREE_REQ(ndlp)) {
4724 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4725 "0280 lpfc_cleanup_node: ndlp:x%p "
4726 "usgmap:x%x refcnt:%d\n",
4727 (void *)ndlp, ndlp->nlp_usg_map,
4728 atomic_read(&ndlp->kref.refcount));
4729 lpfc_dequeue_node(vport, ndlp);
4731 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4732 "0281 lpfc_cleanup_node: ndlp:x%p "
4733 "usgmap:x%x refcnt:%d\n",
4734 (void *)ndlp, ndlp->nlp_usg_map,
4735 atomic_read(&ndlp->kref.refcount));
4736 lpfc_disable_node(vport, ndlp);
4740 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
4742 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4743 if ((mb = phba->sli.mbox_active)) {
4744 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4745 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
4746 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4747 mb->context2 = NULL;
4748 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4752 spin_lock_irq(&phba->hbalock);
4753 /* Cleanup REG_LOGIN completions which are not yet processed */
4754 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4755 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
4756 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
4757 (ndlp != (struct lpfc_nodelist *) mb->context2))
4760 mb->context2 = NULL;
4761 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4764 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
4765 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4766 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
4767 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4768 mp = (struct lpfc_dmabuf *) (mb->context1);
4770 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
4773 list_del(&mb->list);
4774 mempool_free(mb, phba->mbox_mem_pool);
4775 /* We shall not invoke the lpfc_nlp_put to decrement
4776 * the ndlp reference count as we are in the process
4777 * of lpfc_nlp_release.
4781 spin_unlock_irq(&phba->hbalock);
4783 lpfc_els_abort(phba, ndlp);
4785 spin_lock_irq(shost->host_lock);
4786 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
4787 spin_unlock_irq(shost->host_lock);
4789 ndlp->nlp_last_elscmd = 0;
4790 del_timer_sync(&ndlp->nlp_delayfunc);
4792 list_del_init(&ndlp->els_retry_evt.evt_listp);
4793 list_del_init(&ndlp->dev_loss_evt.evt_listp);
4794 lpfc_cleanup_vports_rrqs(vport, ndlp);
4795 lpfc_unreg_rpi(vport, ndlp);
4801 * Check to see if we can free the nlp back to the freelist.
4802 * If we are in the middle of using the nlp in the discovery state
4803 * machine, defer the free till we reach the end of the state machine.
4806 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4808 struct lpfc_hba *phba = vport->phba;
4809 struct lpfc_rport_data *rdata;
4810 struct fc_rport *rport;
4814 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4815 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
4816 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
4817 !(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
4818 phba->sli_rev != LPFC_SLI_REV4) {
4819 /* For this case we need to cleanup the default rpi
4820 * allocated by the firmware.
4822 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4823 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n",
4824 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4825 atomic_read(&ndlp->kref.refcount),
4826 ndlp->nlp_usg_map, ndlp);
4827 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4829 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
4830 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
4832 mempool_free(mbox, phba->mbox_mem_pool);
4835 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4836 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4837 mbox->vport = vport;
4838 mbox->context2 = ndlp;
4839 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4840 if (rc == MBX_NOT_FINISHED) {
4841 mempool_free(mbox, phba->mbox_mem_pool);
4846 lpfc_cleanup_node(vport, ndlp);
4849 * ndlp->rport must be set to NULL before it reaches here
4850 * i.e. break rport/node link before doing lpfc_nlp_put for
4851 * registered rport and then drop the reference of rport.
4855 * extra lpfc_nlp_put dropped the reference of ndlp
4856 * for registered rport so need to cleanup rport
4858 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4859 "0940 removed node x%p DID x%x "
4860 " rport not null %p\n",
4861 ndlp, ndlp->nlp_DID, ndlp->rport);
4862 rport = ndlp->rport;
4863 rdata = rport->dd_data;
4864 rdata->pnode = NULL;
4866 put_device(&rport->dev);
4871 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4874 D_ID mydid, ndlpdid, matchdid;
4876 if (did == Bcast_DID)
4879 /* First check for Direct match */
4880 if (ndlp->nlp_DID == did)
4883 /* Next check for area/domain identically equals 0 match */
4884 mydid.un.word = vport->fc_myDID;
4885 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
4889 matchdid.un.word = did;
4890 ndlpdid.un.word = ndlp->nlp_DID;
4891 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4892 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4893 (mydid.un.b.area == matchdid.un.b.area)) {
4894 /* This code is supposed to match the ID
4895 * for a private loop device that is
4896 * connect to fl_port. But we need to
4897 * check that the port did not just go
4898 * from pt2pt to fabric or we could end
4899 * up matching ndlp->nlp_DID 000001 to
4900 * fabric DID 0x20101
4902 if ((ndlpdid.un.b.domain == 0) &&
4903 (ndlpdid.un.b.area == 0)) {
4904 if (ndlpdid.un.b.id &&
4905 vport->phba->fc_topology ==
4912 matchdid.un.word = ndlp->nlp_DID;
4913 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4914 (mydid.un.b.area == ndlpdid.un.b.area)) {
4915 if ((matchdid.un.b.domain == 0) &&
4916 (matchdid.un.b.area == 0)) {
4917 if (matchdid.un.b.id)
4925 /* Search for a nodelist entry */
4926 static struct lpfc_nodelist *
4927 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4929 struct lpfc_nodelist *ndlp;
4932 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4933 if (lpfc_matchdid(vport, ndlp, did)) {
4934 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4935 ((uint32_t) ndlp->nlp_xri << 16) |
4936 ((uint32_t) ndlp->nlp_type << 8) |
4937 ((uint32_t) ndlp->nlp_rpi & 0xff));
4938 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4939 "0929 FIND node DID "
4940 "Data: x%p x%x x%x x%x %p\n",
4941 ndlp, ndlp->nlp_DID,
4942 ndlp->nlp_flag, data1,
4943 ndlp->active_rrqs_xri_bitmap);
4948 /* FIND node did <did> NOT FOUND */
4949 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4950 "0932 FIND node did x%x NOT FOUND.\n", did);
4954 struct lpfc_nodelist *
4955 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4958 struct lpfc_nodelist *ndlp;
4959 unsigned long iflags;
4961 spin_lock_irqsave(shost->host_lock, iflags);
4962 ndlp = __lpfc_findnode_did(vport, did);
4963 spin_unlock_irqrestore(shost->host_lock, iflags);
4967 struct lpfc_nodelist *
4968 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
4970 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4971 struct lpfc_nodelist *ndlp;
4973 ndlp = lpfc_findnode_did(vport, did);
4975 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4976 lpfc_rscn_payload_check(vport, did) == 0)
4978 ndlp = (struct lpfc_nodelist *)
4979 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
4982 lpfc_nlp_init(vport, ndlp, did);
4983 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4984 spin_lock_irq(shost->host_lock);
4985 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4986 spin_unlock_irq(shost->host_lock);
4988 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4989 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4992 spin_lock_irq(shost->host_lock);
4993 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4994 spin_unlock_irq(shost->host_lock);
4998 if ((vport->fc_flag & FC_RSCN_MODE) &&
4999 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5000 if (lpfc_rscn_payload_check(vport, did)) {
5001 /* If we've already received a PLOGI from this NPort
5002 * we don't need to try to discover it again.
5004 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
5007 /* Since this node is marked for discovery,
5008 * delay timeout is not needed.
5010 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5011 spin_lock_irq(shost->host_lock);
5012 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5013 spin_unlock_irq(shost->host_lock);
5017 /* If we've already received a PLOGI from this NPort,
5018 * or we are already in the process of discovery on it,
5019 * we don't need to try to discover it again.
5021 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5022 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5023 ndlp->nlp_flag & NLP_RCV_PLOGI)
5025 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5026 spin_lock_irq(shost->host_lock);
5027 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5028 spin_unlock_irq(shost->host_lock);
5033 /* Build a list of nodes to discover based on the loopmap */
5035 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5037 struct lpfc_hba *phba = vport->phba;
5039 uint32_t alpa, index;
5041 if (!lpfc_is_link_up(phba))
5044 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5047 /* Check for loop map present or not */
5048 if (phba->alpa_map[0]) {
5049 for (j = 1; j <= phba->alpa_map[0]; j++) {
5050 alpa = phba->alpa_map[j];
5051 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5053 lpfc_setup_disc_node(vport, alpa);
5056 /* No alpamap, so try all alpa's */
5057 for (j = 0; j < FC_MAXLOOP; j++) {
5058 /* If cfg_scan_down is set, start from highest
5059 * ALPA (0xef) to lowest (0x1).
5061 if (vport->cfg_scan_down)
5064 index = FC_MAXLOOP - j - 1;
5065 alpa = lpfcAlpaArray[index];
5066 if ((vport->fc_myDID & 0xff) == alpa)
5068 lpfc_setup_disc_node(vport, alpa);
5075 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5078 struct lpfc_sli *psli = &phba->sli;
5079 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
5080 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
5081 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
5085 * if it's not a physical port or if we already send
5086 * clear_la then don't send it.
5088 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5089 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5090 (phba->sli_rev == LPFC_SLI_REV4))
5093 /* Link up discovery */
5094 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5095 phba->link_state = LPFC_CLEAR_LA;
5096 lpfc_clear_la(phba, mbox);
5097 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5098 mbox->vport = vport;
5099 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5100 if (rc == MBX_NOT_FINISHED) {
5101 mempool_free(mbox, phba->mbox_mem_pool);
5102 lpfc_disc_flush_list(vport);
5103 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5104 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5105 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5106 phba->link_state = LPFC_HBA_ERROR;
5111 /* Reg_vpi to tell firmware to resume normal operations */
5113 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5115 LPFC_MBOXQ_t *regvpimbox;
5117 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5119 lpfc_reg_vpi(vport, regvpimbox);
5120 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5121 regvpimbox->vport = vport;
5122 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5123 == MBX_NOT_FINISHED) {
5124 mempool_free(regvpimbox, phba->mbox_mem_pool);
5129 /* Start Link up / RSCN discovery on NPR nodes */
5131 lpfc_disc_start(struct lpfc_vport *vport)
5133 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5134 struct lpfc_hba *phba = vport->phba;
5136 uint32_t clear_la_pending;
5138 if (!lpfc_is_link_up(phba)) {
5139 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5140 "3315 Link is not up %x\n",
5145 if (phba->link_state == LPFC_CLEAR_LA)
5146 clear_la_pending = 1;
5148 clear_la_pending = 0;
5150 if (vport->port_state < LPFC_VPORT_READY)
5151 vport->port_state = LPFC_DISC_AUTH;
5153 lpfc_set_disctmo(vport);
5155 vport->fc_prevDID = vport->fc_myDID;
5156 vport->num_disc_nodes = 0;
5158 /* Start Discovery state <hba_state> */
5159 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5160 "0202 Start Discovery hba state x%x "
5161 "Data: x%x x%x x%x\n",
5162 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5163 vport->fc_adisc_cnt);
5165 /* First do ADISCs - if any */
5166 num_sent = lpfc_els_disc_adisc(vport);
5171 /* Register the VPI for SLI3, NPIV only. */
5172 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5173 !(vport->fc_flag & FC_PT2PT) &&
5174 !(vport->fc_flag & FC_RSCN_MODE) &&
5175 (phba->sli_rev < LPFC_SLI_REV4)) {
5176 lpfc_issue_clear_la(phba, vport);
5177 lpfc_issue_reg_vpi(phba, vport);
5182 * For SLI2, we need to set port_state to READY and continue
5185 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5186 /* If we get here, there is nothing to ADISC */
5187 lpfc_issue_clear_la(phba, vport);
5189 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5190 vport->num_disc_nodes = 0;
5191 /* go thru NPR nodes and issue ELS PLOGIs */
5192 if (vport->fc_npr_cnt)
5193 lpfc_els_disc_plogi(vport);
5195 if (!vport->num_disc_nodes) {
5196 spin_lock_irq(shost->host_lock);
5197 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5198 spin_unlock_irq(shost->host_lock);
5199 lpfc_can_disctmo(vport);
5202 vport->port_state = LPFC_VPORT_READY;
5204 /* Next do PLOGIs - if any */
5205 num_sent = lpfc_els_disc_plogi(vport);
5210 if (vport->fc_flag & FC_RSCN_MODE) {
5211 /* Check to see if more RSCNs came in while we
5212 * were processing this one.
5214 if ((vport->fc_rscn_id_cnt == 0) &&
5215 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5216 spin_lock_irq(shost->host_lock);
5217 vport->fc_flag &= ~FC_RSCN_MODE;
5218 spin_unlock_irq(shost->host_lock);
5219 lpfc_can_disctmo(vport);
5221 lpfc_els_handle_rscn(vport);
5228 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5229 * ring the match the sppecified nodelist.
5232 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5234 LIST_HEAD(completions);
5235 struct lpfc_sli *psli;
5237 struct lpfc_iocbq *iocb, *next_iocb;
5238 struct lpfc_sli_ring *pring;
5241 pring = &psli->ring[LPFC_ELS_RING];
5243 /* Error matching iocb on txq or txcmplq
5244 * First check the txq.
5246 spin_lock_irq(&phba->hbalock);
5247 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5248 if (iocb->context1 != ndlp) {
5252 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5253 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5255 list_move_tail(&iocb->list, &completions);
5259 /* Next check the txcmplq */
5260 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5261 if (iocb->context1 != ndlp) {
5265 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5266 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5267 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
5270 spin_unlock_irq(&phba->hbalock);
5272 /* Cancel all the IOCBs from the completions list */
5273 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5278 lpfc_disc_flush_list(struct lpfc_vport *vport)
5280 struct lpfc_nodelist *ndlp, *next_ndlp;
5281 struct lpfc_hba *phba = vport->phba;
5283 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5284 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5286 if (!NLP_CHK_NODE_ACT(ndlp))
5288 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5289 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5290 lpfc_free_tx(phba, ndlp);
5297 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5299 lpfc_els_flush_rscn(vport);
5300 lpfc_els_flush_cmd(vport);
5301 lpfc_disc_flush_list(vport);
5304 /*****************************************************************************/
5306 * NAME: lpfc_disc_timeout
5308 * FUNCTION: Fibre Channel driver discovery timeout routine.
5310 * EXECUTION ENVIRONMENT: interrupt only
5318 /*****************************************************************************/
5320 lpfc_disc_timeout(unsigned long ptr)
5322 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5323 struct lpfc_hba *phba = vport->phba;
5324 uint32_t tmo_posted;
5325 unsigned long flags = 0;
5327 if (unlikely(!phba))
5330 spin_lock_irqsave(&vport->work_port_lock, flags);
5331 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5333 vport->work_port_events |= WORKER_DISC_TMO;
5334 spin_unlock_irqrestore(&vport->work_port_lock, flags);
5337 lpfc_worker_wake_up(phba);
5342 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
5344 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5345 struct lpfc_hba *phba = vport->phba;
5346 struct lpfc_sli *psli = &phba->sli;
5347 struct lpfc_nodelist *ndlp, *next_ndlp;
5348 LPFC_MBOXQ_t *initlinkmbox;
5349 int rc, clrlaerr = 0;
5351 if (!(vport->fc_flag & FC_DISC_TMO))
5354 spin_lock_irq(shost->host_lock);
5355 vport->fc_flag &= ~FC_DISC_TMO;
5356 spin_unlock_irq(shost->host_lock);
5358 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5359 "disc timeout: state:x%x rtry:x%x flg:x%x",
5360 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5362 switch (vport->port_state) {
5364 case LPFC_LOCAL_CFG_LINK:
5365 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
5369 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5370 "0221 FAN timeout\n");
5371 /* Start discovery by sending FLOGI, clean up old rpis */
5372 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5374 if (!NLP_CHK_NODE_ACT(ndlp))
5376 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5378 if (ndlp->nlp_type & NLP_FABRIC) {
5379 /* Clean up the ndlp on Fabric connections */
5380 lpfc_drop_node(vport, ndlp);
5382 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
5383 /* Fail outstanding IO now since device
5384 * is marked for PLOGI.
5386 lpfc_unreg_rpi(vport, ndlp);
5389 if (vport->port_state != LPFC_FLOGI) {
5390 if (phba->sli_rev <= LPFC_SLI_REV3)
5391 lpfc_initial_flogi(vport);
5393 lpfc_issue_init_vfi(vport);
5400 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5401 /* Initial FLOGI timeout */
5402 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5403 "0222 Initial %s timeout\n",
5404 vport->vpi ? "FDISC" : "FLOGI");
5406 /* Assume no Fabric and go on with discovery.
5407 * Check for outstanding ELS FLOGI to abort.
5410 /* FLOGI failed, so just use loop map to make discovery list */
5411 lpfc_disc_list_loopmap(vport);
5413 /* Start discovery */
5414 lpfc_disc_start(vport);
5417 case LPFC_FABRIC_CFG_LINK:
5418 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5420 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5421 "0223 Timeout while waiting for "
5422 "NameServer login\n");
5423 /* Next look for NameServer ndlp */
5424 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5425 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5426 lpfc_els_abort(phba, ndlp);
5428 /* ReStart discovery */
5432 /* Check for wait for NameServer Rsp timeout */
5433 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5434 "0224 NameServer Query timeout "
5436 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5438 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5439 /* Try it one more time */
5440 vport->fc_ns_retry++;
5441 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
5442 vport->fc_ns_retry, 0);
5446 vport->fc_ns_retry = 0;
5450 * Discovery is over.
5451 * set port_state to PORT_READY if SLI2.
5452 * cmpl_reg_vpi will set port_state to READY for SLI3.
5454 if (phba->sli_rev < LPFC_SLI_REV4) {
5455 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5456 lpfc_issue_reg_vpi(phba, vport);
5458 lpfc_issue_clear_la(phba, vport);
5459 vport->port_state = LPFC_VPORT_READY;
5463 /* Setup and issue mailbox INITIALIZE LINK command */
5464 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5465 if (!initlinkmbox) {
5466 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5467 "0206 Device Discovery "
5468 "completion error\n");
5469 phba->link_state = LPFC_HBA_ERROR;
5473 lpfc_linkdown(phba);
5474 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5475 phba->cfg_link_speed);
5476 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5477 initlinkmbox->vport = vport;
5478 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5479 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
5480 lpfc_set_loopback_flag(phba);
5481 if (rc == MBX_NOT_FINISHED)
5482 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5486 case LPFC_DISC_AUTH:
5487 /* Node Authentication timeout */
5488 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5489 "0227 Node Authentication timeout\n");
5490 lpfc_disc_flush_list(vport);
5493 * set port_state to PORT_READY if SLI2.
5494 * cmpl_reg_vpi will set port_state to READY for SLI3.
5496 if (phba->sli_rev < LPFC_SLI_REV4) {
5497 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5498 lpfc_issue_reg_vpi(phba, vport);
5499 else { /* NPIV Not enabled */
5500 lpfc_issue_clear_la(phba, vport);
5501 vport->port_state = LPFC_VPORT_READY;
5506 case LPFC_VPORT_READY:
5507 if (vport->fc_flag & FC_RSCN_MODE) {
5508 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5509 "0231 RSCN timeout Data: x%x "
5511 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5513 /* Cleanup any outstanding ELS commands */
5514 lpfc_els_flush_cmd(vport);
5516 lpfc_els_flush_rscn(vport);
5517 lpfc_disc_flush_list(vport);
5522 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5523 "0273 Unexpected discovery timeout, "
5524 "vport State x%x\n", vport->port_state);
5528 switch (phba->link_state) {
5530 /* CLEAR LA timeout */
5531 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5532 "0228 CLEAR LA timeout\n");
5537 lpfc_issue_clear_la(phba, vport);
5539 case LPFC_LINK_UNKNOWN:
5540 case LPFC_WARM_START:
5541 case LPFC_INIT_START:
5542 case LPFC_INIT_MBX_CMDS:
5543 case LPFC_LINK_DOWN:
5544 case LPFC_HBA_ERROR:
5545 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5546 "0230 Unexpected timeout, hba link "
5547 "state x%x\n", phba->link_state);
5551 case LPFC_HBA_READY:
5556 lpfc_disc_flush_list(vport);
5557 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5558 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5559 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5560 vport->port_state = LPFC_VPORT_READY;
5567 * This routine handles processing a NameServer REG_LOGIN mailbox
5568 * command upon completion. It is setup in the LPFC_MBOXQ
5569 * as the completion routine when the command is
5570 * handed off to the SLI layer.
5573 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5575 MAILBOX_t *mb = &pmb->u.mb;
5576 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
5577 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5578 struct lpfc_vport *vport = pmb->vport;
5580 pmb->context1 = NULL;
5581 pmb->context2 = NULL;
5583 if (phba->sli_rev < LPFC_SLI_REV4)
5584 ndlp->nlp_rpi = mb->un.varWords[0];
5585 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
5586 ndlp->nlp_type |= NLP_FABRIC;
5587 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
5588 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5589 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n",
5590 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
5591 atomic_read(&ndlp->kref.refcount),
5592 ndlp->nlp_usg_map, ndlp);
5594 * Start issuing Fabric-Device Management Interface (FDMI) command to
5595 * 0xfffffa (FDMI well known port).
5596 * DHBA -> DPRT -> RHBA -> RPA (physical port)
5597 * DPRT -> RPRT (vports)
5599 if (vport->port_type == LPFC_PHYSICAL_PORT)
5600 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
5602 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
5605 /* decrement the node reference count held for this callback
5609 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5611 mempool_free(pmb, phba->mbox_mem_pool);
5617 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5619 uint16_t *rpi = param;
5621 /* check for active node */
5622 if (!NLP_CHK_NODE_ACT(ndlp))
5625 return ndlp->nlp_rpi == *rpi;
5629 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5631 return memcmp(&ndlp->nlp_portname, param,
5632 sizeof(ndlp->nlp_portname)) == 0;
5635 static struct lpfc_nodelist *
5636 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
5638 struct lpfc_nodelist *ndlp;
5640 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5641 if (filter(ndlp, param)) {
5642 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5643 "3185 FIND node filter %p DID "
5644 "Data: x%p x%x x%x\n",
5645 filter, ndlp, ndlp->nlp_DID,
5650 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5651 "3186 FIND node filter %p NOT FOUND.\n", filter);
5656 * This routine looks up the ndlp lists for the given RPI. If rpi found it
5657 * returns the node list element pointer else return NULL.
5659 struct lpfc_nodelist *
5660 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5662 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
5666 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
5667 * returns the node element list pointer else return NULL.
5669 struct lpfc_nodelist *
5670 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
5672 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5673 struct lpfc_nodelist *ndlp;
5675 spin_lock_irq(shost->host_lock);
5676 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5677 spin_unlock_irq(shost->host_lock);
5682 * This routine looks up the ndlp lists for the given RPI. If the rpi
5683 * is found, the routine returns the node element list pointer else
5686 struct lpfc_nodelist *
5687 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5689 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5690 struct lpfc_nodelist *ndlp;
5692 spin_lock_irq(shost->host_lock);
5693 ndlp = __lpfc_findnode_rpi(vport, rpi);
5694 spin_unlock_irq(shost->host_lock);
5699 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5700 * @phba: pointer to lpfc hba data structure.
5701 * @vpi: the physical host virtual N_Port identifier.
5703 * This routine finds a vport on a HBA (referred by @phba) through a
5704 * @vpi. The function walks the HBA's vport list and returns the address
5705 * of the vport with the matching @vpi.
5708 * NULL - No vport with the matching @vpi found
5709 * Otherwise - Address to the vport with the matching @vpi.
5712 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5714 struct lpfc_vport *vport;
5715 unsigned long flags;
5718 /* The physical ports are always vpi 0 - translate is unnecessary. */
5721 * Translate the physical vpi to the logical vpi. The
5722 * vport stores the logical vpi.
5724 for (i = 0; i < phba->max_vpi; i++) {
5725 if (vpi == phba->vpi_ids[i])
5729 if (i >= phba->max_vpi) {
5730 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5731 "2936 Could not find Vport mapped "
5732 "to vpi %d\n", vpi);
5737 spin_lock_irqsave(&phba->hbalock, flags);
5738 list_for_each_entry(vport, &phba->port_list, listentry) {
5739 if (vport->vpi == i) {
5740 spin_unlock_irqrestore(&phba->hbalock, flags);
5744 spin_unlock_irqrestore(&phba->hbalock, flags);
5749 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5752 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
5754 lpfc_initialize_node(vport, ndlp, did);
5755 INIT_LIST_HEAD(&ndlp->nlp_listp);
5756 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
5757 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
5758 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5759 "0007 rpi:%x DID:%x flg:%x refcnt:%d "
5760 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID,
5762 atomic_read(&ndlp->kref.refcount),
5763 ndlp->nlp_usg_map, ndlp);
5765 ndlp->active_rrqs_xri_bitmap =
5766 mempool_alloc(vport->phba->active_rrq_pool,
5768 if (ndlp->active_rrqs_xri_bitmap)
5769 memset(ndlp->active_rrqs_xri_bitmap, 0,
5770 ndlp->phba->cfg_rrq_xri_bitmap_sz);
5775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5776 "node init: did:x%x",
5777 ndlp->nlp_DID, 0, 0);
5782 /* This routine releases all resources associated with a specifc NPort's ndlp
5783 * and mempool_free's the nodelist.
5786 lpfc_nlp_release(struct kref *kref)
5788 struct lpfc_hba *phba;
5789 unsigned long flags;
5790 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5793 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5794 "node release: did:x%x flg:x%x type:x%x",
5795 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5797 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5798 "0279 lpfc_nlp_release: ndlp:x%p did %x "
5799 "usgmap:x%x refcnt:%d rpi:%x\n",
5800 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
5801 atomic_read(&ndlp->kref.refcount), ndlp->nlp_rpi);
5803 /* remove ndlp from action. */
5804 lpfc_nlp_remove(ndlp->vport, ndlp);
5806 /* clear the ndlp active flag for all release cases */
5808 spin_lock_irqsave(&phba->ndlp_lock, flags);
5809 NLP_CLR_NODE_ACT(ndlp);
5810 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5811 if (phba->sli_rev == LPFC_SLI_REV4)
5812 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
5814 /* free ndlp memory for final ndlp release */
5815 if (NLP_CHK_FREE_REQ(ndlp)) {
5816 kfree(ndlp->lat_data);
5817 if (phba->sli_rev == LPFC_SLI_REV4)
5818 mempool_free(ndlp->active_rrqs_xri_bitmap,
5819 ndlp->phba->active_rrq_pool);
5820 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
5824 /* This routine bumps the reference count for a ndlp structure to ensure
5825 * that one discovery thread won't free a ndlp while another discovery thread
5828 struct lpfc_nodelist *
5829 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5831 struct lpfc_hba *phba;
5832 unsigned long flags;
5835 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5836 "node get: did:x%x flg:x%x refcnt:x%x",
5837 ndlp->nlp_DID, ndlp->nlp_flag,
5838 atomic_read(&ndlp->kref.refcount));
5839 /* The check of ndlp usage to prevent incrementing the
5840 * ndlp reference count that is in the process of being
5844 spin_lock_irqsave(&phba->ndlp_lock, flags);
5845 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5846 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5847 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5848 "0276 lpfc_nlp_get: ndlp:x%p "
5849 "usgmap:x%x refcnt:%d\n",
5850 (void *)ndlp, ndlp->nlp_usg_map,
5851 atomic_read(&ndlp->kref.refcount));
5854 kref_get(&ndlp->kref);
5855 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5860 /* This routine decrements the reference count for a ndlp structure. If the
5861 * count goes to 0, this indicates the the associated nodelist should be
5862 * freed. Returning 1 indicates the ndlp resource has been released; on the
5863 * other hand, returning 0 indicates the ndlp resource has not been released
5867 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
5869 struct lpfc_hba *phba;
5870 unsigned long flags;
5875 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5876 "node put: did:x%x flg:x%x refcnt:x%x",
5877 ndlp->nlp_DID, ndlp->nlp_flag,
5878 atomic_read(&ndlp->kref.refcount));
5880 spin_lock_irqsave(&phba->ndlp_lock, flags);
5881 /* Check the ndlp memory free acknowledge flag to avoid the
5882 * possible race condition that kref_put got invoked again
5883 * after previous one has done ndlp memory free.
5885 if (NLP_CHK_FREE_ACK(ndlp)) {
5886 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5887 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5888 "0274 lpfc_nlp_put: ndlp:x%p "
5889 "usgmap:x%x refcnt:%d\n",
5890 (void *)ndlp, ndlp->nlp_usg_map,
5891 atomic_read(&ndlp->kref.refcount));
5894 /* Check the ndlp inactivate log flag to avoid the possible
5895 * race condition that kref_put got invoked again after ndlp
5896 * is already in inactivating state.
5898 if (NLP_CHK_IACT_REQ(ndlp)) {
5899 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5900 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5901 "0275 lpfc_nlp_put: ndlp:x%p "
5902 "usgmap:x%x refcnt:%d\n",
5903 (void *)ndlp, ndlp->nlp_usg_map,
5904 atomic_read(&ndlp->kref.refcount));
5907 /* For last put, mark the ndlp usage flags to make sure no
5908 * other kref_get and kref_put on the same ndlp shall get
5909 * in between the process when the final kref_put has been
5910 * invoked on this ndlp.
5912 if (atomic_read(&ndlp->kref.refcount) == 1) {
5913 /* Indicate ndlp is put to inactive state. */
5914 NLP_SET_IACT_REQ(ndlp);
5915 /* Acknowledge ndlp memory free has been seen. */
5916 if (NLP_CHK_FREE_REQ(ndlp))
5917 NLP_SET_FREE_ACK(ndlp);
5919 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5920 /* Note, the kref_put returns 1 when decrementing a reference
5921 * count that was 1, it invokes the release callback function,
5922 * but it still left the reference count as 1 (not actually
5923 * performs the last decrementation). Otherwise, it actually
5924 * decrements the reference count and returns 0.
5926 return kref_put(&ndlp->kref, lpfc_nlp_release);
5929 /* This routine free's the specified nodelist if it is not in use
5930 * by any other discovery thread. This routine returns 1 if the
5931 * ndlp has been freed. A return value of 0 indicates the ndlp is
5932 * not yet been released.
5935 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5937 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5938 "node not used: did:x%x flg:x%x refcnt:x%x",
5939 ndlp->nlp_DID, ndlp->nlp_flag,
5940 atomic_read(&ndlp->kref.refcount));
5941 if (atomic_read(&ndlp->kref.refcount) == 1)
5942 if (lpfc_nlp_put(ndlp))
5948 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5949 * @phba: Pointer to hba context object.
5951 * This function iterate through all FC nodes associated
5952 * will all vports to check if there is any node with
5953 * fc_rports associated with it. If there is an fc_rport
5954 * associated with the node, then the node is either in
5955 * discovered state or its devloss_timer is pending.
5958 lpfc_fcf_inuse(struct lpfc_hba *phba)
5960 struct lpfc_vport **vports;
5962 struct lpfc_nodelist *ndlp;
5963 struct Scsi_Host *shost;
5965 vports = lpfc_create_vport_work_array(phba);
5967 /* If driver cannot allocate memory, indicate fcf is in use */
5971 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5972 shost = lpfc_shost_from_vport(vports[i]);
5973 spin_lock_irq(shost->host_lock);
5975 * IF the CVL_RCVD bit is not set then we have sent the
5977 * If dev_loss fires while we are waiting we do not want to
5980 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
5981 spin_unlock_irq(shost->host_lock);
5985 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5986 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5987 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5989 spin_unlock_irq(shost->host_lock);
5991 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5993 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5994 "2624 RPI %x DID %x flag %x "
5995 "still logged in\n",
5996 ndlp->nlp_rpi, ndlp->nlp_DID,
6000 spin_unlock_irq(shost->host_lock);
6003 lpfc_destroy_vport_work_array(phba, vports);
6008 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6009 * @phba: Pointer to hba context object.
6010 * @mboxq: Pointer to mailbox object.
6012 * This function frees memory associated with the mailbox command.
6015 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6017 struct lpfc_vport *vport = mboxq->vport;
6018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6020 if (mboxq->u.mb.mbxStatus) {
6021 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6022 "2555 UNREG_VFI mbxStatus error x%x "
6024 mboxq->u.mb.mbxStatus, vport->port_state);
6026 spin_lock_irq(shost->host_lock);
6027 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6028 spin_unlock_irq(shost->host_lock);
6029 mempool_free(mboxq, phba->mbox_mem_pool);
6034 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6035 * @phba: Pointer to hba context object.
6036 * @mboxq: Pointer to mailbox object.
6038 * This function frees memory associated with the mailbox command.
6041 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6043 struct lpfc_vport *vport = mboxq->vport;
6045 if (mboxq->u.mb.mbxStatus) {
6046 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6047 "2550 UNREG_FCFI mbxStatus error x%x "
6049 mboxq->u.mb.mbxStatus, vport->port_state);
6051 mempool_free(mboxq, phba->mbox_mem_pool);
6056 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6057 * @phba: Pointer to hba context object.
6059 * This function prepare the HBA for unregistering the currently registered
6060 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6064 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6066 struct lpfc_vport **vports;
6067 struct lpfc_nodelist *ndlp;
6068 struct Scsi_Host *shost;
6071 /* Unregister RPIs */
6072 if (lpfc_fcf_inuse(phba))
6073 lpfc_unreg_hba_rpis(phba);
6075 /* At this point, all discovery is aborted */
6076 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6078 /* Unregister VPIs */
6079 vports = lpfc_create_vport_work_array(phba);
6080 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6081 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6082 /* Stop FLOGI/FDISC retries */
6083 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6085 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6086 lpfc_cleanup_pending_mbox(vports[i]);
6087 if (phba->sli_rev == LPFC_SLI_REV4)
6088 lpfc_sli4_unreg_all_rpis(vports[i]);
6089 lpfc_mbx_unreg_vpi(vports[i]);
6090 shost = lpfc_shost_from_vport(vports[i]);
6091 spin_lock_irq(shost->host_lock);
6092 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6093 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6094 spin_unlock_irq(shost->host_lock);
6096 lpfc_destroy_vport_work_array(phba, vports);
6097 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6098 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6100 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6101 lpfc_cleanup_pending_mbox(phba->pport);
6102 if (phba->sli_rev == LPFC_SLI_REV4)
6103 lpfc_sli4_unreg_all_rpis(phba->pport);
6104 lpfc_mbx_unreg_vpi(phba->pport);
6105 shost = lpfc_shost_from_vport(phba->pport);
6106 spin_lock_irq(shost->host_lock);
6107 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6108 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6109 spin_unlock_irq(shost->host_lock);
6112 /* Cleanup any outstanding ELS commands */
6113 lpfc_els_flush_all_cmd(phba);
6115 /* Unregister the physical port VFI */
6116 rc = lpfc_issue_unreg_vfi(phba->pport);
6121 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6122 * @phba: Pointer to hba context object.
6124 * This function issues synchronous unregister FCF mailbox command to HBA to
6125 * unregister the currently registered FCF record. The driver does not reset
6126 * the driver FCF usage state flags.
6128 * Return 0 if successfully issued, none-zero otherwise.
6131 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6136 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6138 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6139 "2551 UNREG_FCFI mbox allocation failed"
6140 "HBA state x%x\n", phba->pport->port_state);
6143 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6144 mbox->vport = phba->pport;
6145 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6146 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6148 if (rc == MBX_NOT_FINISHED) {
6149 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6150 "2552 Unregister FCFI command failed rc x%x "
6152 rc, phba->pport->port_state);
6159 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6160 * @phba: Pointer to hba context object.
6162 * This function unregisters the currently reigstered FCF. This function
6163 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6166 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6170 /* Preparation for unregistering fcf */
6171 rc = lpfc_unregister_fcf_prep(phba);
6173 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6174 "2748 Failed to prepare for unregistering "
6175 "HBA's FCF record: rc=%d\n", rc);
6179 /* Now, unregister FCF record and reset HBA FCF state */
6180 rc = lpfc_sli4_unregister_fcf(phba);
6183 /* Reset HBA FCF states after successful unregister FCF */
6184 phba->fcf.fcf_flag = 0;
6185 phba->fcf.current_rec.flag = 0;
6188 * If driver is not unloading, check if there is any other
6189 * FCF record that can be used for discovery.
6191 if ((phba->pport->load_flag & FC_UNLOADING) ||
6192 (phba->link_state < LPFC_LINK_UP))
6195 /* This is considered as the initial FCF discovery scan */
6196 spin_lock_irq(&phba->hbalock);
6197 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6198 spin_unlock_irq(&phba->hbalock);
6200 /* Reset FCF roundrobin bmask for new discovery */
6201 lpfc_sli4_clear_fcf_rr_bmask(phba);
6203 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6206 spin_lock_irq(&phba->hbalock);
6207 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6208 spin_unlock_irq(&phba->hbalock);
6209 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6210 "2553 lpfc_unregister_unused_fcf failed "
6211 "to read FCF record HBA state x%x\n",
6212 phba->pport->port_state);
6217 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6218 * @phba: Pointer to hba context object.
6220 * This function just unregisters the currently reigstered FCF. It does not
6221 * try to find another FCF for discovery.
6224 lpfc_unregister_fcf(struct lpfc_hba *phba)
6228 /* Preparation for unregistering fcf */
6229 rc = lpfc_unregister_fcf_prep(phba);
6231 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6232 "2749 Failed to prepare for unregistering "
6233 "HBA's FCF record: rc=%d\n", rc);
6237 /* Now, unregister FCF record and reset HBA FCF state */
6238 rc = lpfc_sli4_unregister_fcf(phba);
6241 /* Set proper HBA FCF states after successful unregister FCF */
6242 spin_lock_irq(&phba->hbalock);
6243 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6244 spin_unlock_irq(&phba->hbalock);
6248 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6249 * @phba: Pointer to hba context object.
6251 * This function check if there are any connected remote port for the FCF and
6252 * if all the devices are disconnected, this function unregister FCFI.
6253 * This function also tries to use another FCF for discovery.
6256 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6259 * If HBA is not running in FIP mode, if HBA does not support
6260 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6261 * registered, do nothing.
6263 spin_lock_irq(&phba->hbalock);
6264 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6265 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6266 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6267 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6268 (phba->pport->port_state == LPFC_FLOGI)) {
6269 spin_unlock_irq(&phba->hbalock);
6272 spin_unlock_irq(&phba->hbalock);
6274 if (lpfc_fcf_inuse(phba))
6277 lpfc_unregister_fcf_rescan(phba);
6281 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6282 * @phba: Pointer to hba context object.
6283 * @buff: Buffer containing the FCF connection table as in the config
6285 * This function create driver data structure for the FCF connection
6286 * record table read from config region 23.
6289 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6292 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6293 struct lpfc_fcf_conn_hdr *conn_hdr;
6294 struct lpfc_fcf_conn_rec *conn_rec;
6295 uint32_t record_count;
6298 /* Free the current connect table */
6299 list_for_each_entry_safe(conn_entry, next_conn_entry,
6300 &phba->fcf_conn_rec_list, list) {
6301 list_del_init(&conn_entry->list);
6305 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6306 record_count = conn_hdr->length * sizeof(uint32_t)/
6307 sizeof(struct lpfc_fcf_conn_rec);
6309 conn_rec = (struct lpfc_fcf_conn_rec *)
6310 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6312 for (i = 0; i < record_count; i++) {
6313 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6315 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6318 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6319 "2566 Failed to allocate connection"
6324 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6325 sizeof(struct lpfc_fcf_conn_rec));
6326 list_add_tail(&conn_entry->list,
6327 &phba->fcf_conn_rec_list);
6330 if (!list_empty(&phba->fcf_conn_rec_list)) {
6332 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6334 conn_rec = &conn_entry->conn_rec;
6335 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6336 "3345 FCF connection list rec[%02d]: "
6337 "flags:x%04x, vtag:x%04x, "
6338 "fabric_name:x%02x:%02x:%02x:%02x:"
6339 "%02x:%02x:%02x:%02x, "
6340 "switch_name:x%02x:%02x:%02x:%02x:"
6341 "%02x:%02x:%02x:%02x\n", i++,
6342 conn_rec->flags, conn_rec->vlan_tag,
6343 conn_rec->fabric_name[0],
6344 conn_rec->fabric_name[1],
6345 conn_rec->fabric_name[2],
6346 conn_rec->fabric_name[3],
6347 conn_rec->fabric_name[4],
6348 conn_rec->fabric_name[5],
6349 conn_rec->fabric_name[6],
6350 conn_rec->fabric_name[7],
6351 conn_rec->switch_name[0],
6352 conn_rec->switch_name[1],
6353 conn_rec->switch_name[2],
6354 conn_rec->switch_name[3],
6355 conn_rec->switch_name[4],
6356 conn_rec->switch_name[5],
6357 conn_rec->switch_name[6],
6358 conn_rec->switch_name[7]);
6364 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6365 * @phba: Pointer to hba context object.
6366 * @buff: Buffer containing the FCoE parameter data structure.
6368 * This function update driver data structure with config
6369 * parameters read from config region 23.
6372 lpfc_read_fcoe_param(struct lpfc_hba *phba,
6375 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6376 struct lpfc_fcoe_params *fcoe_param;
6378 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6380 fcoe_param = (struct lpfc_fcoe_params *)
6381 (buff + sizeof(struct lpfc_fip_param_hdr));
6383 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6384 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6387 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6388 phba->valid_vlan = 1;
6389 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6393 phba->fc_map[0] = fcoe_param->fc_map[0];
6394 phba->fc_map[1] = fcoe_param->fc_map[1];
6395 phba->fc_map[2] = fcoe_param->fc_map[2];
6400 * lpfc_get_rec_conf23 - Get a record type in config region data.
6401 * @buff: Buffer containing config region 23 data.
6402 * @size: Size of the data buffer.
6403 * @rec_type: Record type to be searched.
6405 * This function searches config region data to find the beginning
6406 * of the record specified by record_type. If record found, this
6407 * function return pointer to the record else return NULL.
6410 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6412 uint32_t offset = 0, rec_length;
6414 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6415 (size < sizeof(uint32_t)))
6418 rec_length = buff[offset + 1];
6421 * One TLV record has one word header and number of data words
6422 * specified in the rec_length field of the record header.
6424 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6426 if (buff[offset] == rec_type)
6427 return &buff[offset];
6429 if (buff[offset] == LPFC_REGION23_LAST_REC)
6432 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6433 rec_length = buff[offset + 1];
6439 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6440 * @phba: Pointer to lpfc_hba data structure.
6441 * @buff: Buffer containing config region 23 data.
6442 * @size: Size of the data buffer.
6444 * This function parses the FCoE config parameters in config region 23 and
6445 * populate driver data structure with the parameters.
6448 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6452 uint32_t offset = 0;
6456 * If data size is less than 2 words signature and version cannot be
6459 if (size < 2*sizeof(uint32_t))
6462 /* Check the region signature first */
6463 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6464 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6465 "2567 Config region 23 has bad signature\n");
6471 /* Check the data structure version */
6472 if (buff[offset] != LPFC_REGION23_VERSION) {
6473 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6474 "2568 Config region 23 has bad version\n");
6479 /* Read FCoE param record */
6480 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6481 size - offset, FCOE_PARAM_TYPE);
6483 lpfc_read_fcoe_param(phba, rec_ptr);
6485 /* Read FCF connection table */
6486 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6487 size - offset, FCOE_CONN_TBL_TYPE);
6489 lpfc_read_fcf_conn_tbl(phba, rec_ptr);