1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/slab.h>
25 #include <linux/pci.h>
26 #include <linux/kthread.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_disc.h"
39 #include "lpfc_sli4.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 /* AlpaArray for assignment of scsid for scan-down and bind_method */
48 static uint8_t lpfcAlpaArray[] = {
49 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
50 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
51 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
52 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
53 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
54 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
55 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
56 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
57 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
58 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
59 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
60 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
61 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
64 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
65 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
66 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
67 static int lpfc_fcf_inuse(struct lpfc_hba *);
70 lpfc_terminate_rport_io(struct fc_rport *rport)
72 struct lpfc_rport_data *rdata;
73 struct lpfc_nodelist * ndlp;
74 struct lpfc_hba *phba;
76 rdata = rport->dd_data;
79 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
80 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
81 printk(KERN_ERR "Cannot find remote node"
82 " to terminate I/O Data x%x\n",
89 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
90 "rport terminate: sid:x%x did:x%x flg:x%x",
91 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
93 if (ndlp->nlp_sid != NLP_NO_SID) {
94 lpfc_sli_abort_iocb(ndlp->vport,
95 &phba->sli.ring[phba->sli.fcp_ring],
96 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
101 * This function will be called when dev_loss_tmo fire.
104 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
106 struct lpfc_rport_data *rdata;
107 struct lpfc_nodelist * ndlp;
108 struct lpfc_vport *vport;
109 struct lpfc_hba *phba;
110 struct lpfc_work_evt *evtp;
114 rdata = rport->dd_data;
116 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
122 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
123 "rport devlosscb: sid:x%x did:x%x flg:x%x",
124 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
126 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
127 "3181 dev_loss_callbk x%06x, rport %p flg x%x\n",
128 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
130 /* Don't defer this if we are in the process of deleting the vport
131 * or unloading the driver. The unload will cleanup the node
132 * appropriately we just need to cleanup the ndlp rport info here.
134 if (vport->load_flag & FC_UNLOADING) {
135 put_node = rdata->pnode != NULL;
136 put_rport = ndlp->rport != NULL;
142 put_device(&rport->dev);
146 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
149 if (ndlp->nlp_type & NLP_FABRIC) {
151 /* If the WWPN of the rport and ndlp don't match, ignore it */
152 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn)) {
153 put_device(&rport->dev);
158 evtp = &ndlp->dev_loss_evt;
160 if (!list_empty(&evtp->evt_listp))
163 spin_lock_irq(&phba->hbalock);
164 /* We need to hold the node by incrementing the reference
165 * count until this queued work is done
167 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
168 if (evtp->evt_arg1) {
169 evtp->evt = LPFC_EVT_DEV_LOSS;
170 list_add_tail(&evtp->evt_listp, &phba->work_list);
171 lpfc_worker_wake_up(phba);
173 spin_unlock_irq(&phba->hbalock);
179 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
180 * @ndlp: Pointer to remote node object.
182 * This function is called from the worker thread when devloss timeout timer
183 * expires. For SLI4 host, this routine shall return 1 when at lease one
184 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
185 * routine shall return 0 when there is no remote node is still in use of FCF
186 * when devloss timeout happened to this @ndlp.
189 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
191 struct lpfc_rport_data *rdata;
192 struct fc_rport *rport;
193 struct lpfc_vport *vport;
194 struct lpfc_hba *phba;
206 rdata = rport->dd_data;
207 name = (uint8_t *) &ndlp->nlp_portname;
211 if (phba->sli_rev == LPFC_SLI_REV4)
212 fcf_inuse = lpfc_fcf_inuse(phba);
214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
215 "rport devlosstmo:did:x%x type:x%x id:x%x",
216 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
218 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
219 "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n",
220 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
222 /* Don't defer this if we are in the process of deleting the vport
223 * or unloading the driver. The unload will cleanup the node
224 * appropriately we just need to cleanup the ndlp rport info here.
226 if (vport->load_flag & FC_UNLOADING) {
227 if (ndlp->nlp_sid != NLP_NO_SID) {
228 /* flush the target */
229 lpfc_sli_abort_iocb(vport,
230 &phba->sli.ring[phba->sli.fcp_ring],
231 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
233 put_node = rdata->pnode != NULL;
234 put_rport = ndlp->rport != NULL;
240 put_device(&rport->dev);
244 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
245 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
246 "0284 Devloss timeout Ignored on "
247 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
249 *name, *(name+1), *(name+2), *(name+3),
250 *(name+4), *(name+5), *(name+6), *(name+7),
255 if (ndlp->nlp_type & NLP_FABRIC) {
256 /* We will clean up these Nodes in linkup */
257 put_node = rdata->pnode != NULL;
258 put_rport = ndlp->rport != NULL;
264 put_device(&rport->dev);
268 if (ndlp->nlp_sid != NLP_NO_SID) {
270 /* flush the target */
271 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
272 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
276 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
277 "0203 Devloss timeout on "
278 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
279 "NPort x%06x Data: x%x x%x x%x\n",
280 *name, *(name+1), *(name+2), *(name+3),
281 *(name+4), *(name+5), *(name+6), *(name+7),
282 ndlp->nlp_DID, ndlp->nlp_flag,
283 ndlp->nlp_state, ndlp->nlp_rpi);
285 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
286 "0204 Devloss timeout on "
287 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
288 "NPort x%06x Data: x%x x%x x%x\n",
289 *name, *(name+1), *(name+2), *(name+3),
290 *(name+4), *(name+5), *(name+6), *(name+7),
291 ndlp->nlp_DID, ndlp->nlp_flag,
292 ndlp->nlp_state, ndlp->nlp_rpi);
295 put_node = rdata->pnode != NULL;
296 put_rport = ndlp->rport != NULL;
302 put_device(&rport->dev);
304 if (!(vport->load_flag & FC_UNLOADING) &&
305 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
306 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
307 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
308 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
309 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
310 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
316 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
317 * @phba: Pointer to hba context object.
318 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
319 * @nlp_did: remote node identifer with devloss timeout.
321 * This function is called from the worker thread after invoking devloss
322 * timeout handler and releasing the reference count for the ndlp with
323 * which the devloss timeout was handled for SLI4 host. For the devloss
324 * timeout of the last remote node which had been in use of FCF, when this
325 * routine is invoked, it shall be guaranteed that none of the remote are
326 * in-use of FCF. When devloss timeout to the last remote using the FCF,
327 * if the FIP engine is neither in FCF table scan process nor roundrobin
328 * failover process, the in-use FCF shall be unregistered. If the FIP
329 * engine is in FCF discovery process, the devloss timeout state shall
330 * be set for either the FCF table scan process or roundrobin failover
331 * process to unregister the in-use FCF.
334 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
337 /* If devloss timeout happened to a remote node when FCF had no
338 * longer been in-use, do nothing.
343 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
344 spin_lock_irq(&phba->hbalock);
345 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
346 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
347 spin_unlock_irq(&phba->hbalock);
350 phba->hba_flag |= HBA_DEVLOSS_TMO;
351 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
352 "2847 Last remote node (x%x) using "
353 "FCF devloss tmo\n", nlp_did);
355 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
356 spin_unlock_irq(&phba->hbalock);
357 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
358 "2868 Devloss tmo to FCF rediscovery "
362 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
363 spin_unlock_irq(&phba->hbalock);
364 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
365 "2869 Devloss tmo to idle FIP engine, "
366 "unreg in-use FCF and rescan.\n");
367 /* Unregister in-use FCF and rescan */
368 lpfc_unregister_fcf_rescan(phba);
371 spin_unlock_irq(&phba->hbalock);
372 if (phba->hba_flag & FCF_TS_INPROG)
373 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
374 "2870 FCF table scan in progress\n");
375 if (phba->hba_flag & FCF_RR_INPROG)
376 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
377 "2871 FLOGI roundrobin FCF failover "
380 lpfc_unregister_unused_fcf(phba);
384 * lpfc_alloc_fast_evt - Allocates data structure for posting event
385 * @phba: Pointer to hba context object.
387 * This function is called from the functions which need to post
388 * events from interrupt context. This function allocates data
389 * structure required for posting event. It also keeps track of
390 * number of events pending and prevent event storm when there are
393 struct lpfc_fast_path_event *
394 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
395 struct lpfc_fast_path_event *ret;
397 /* If there are lot of fast event do not exhaust memory due to this */
398 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
401 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
404 atomic_inc(&phba->fast_event_count);
405 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
406 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
412 * lpfc_free_fast_evt - Frees event data structure
413 * @phba: Pointer to hba context object.
414 * @evt: Event object which need to be freed.
416 * This function frees the data structure required for posting
420 lpfc_free_fast_evt(struct lpfc_hba *phba,
421 struct lpfc_fast_path_event *evt) {
423 atomic_dec(&phba->fast_event_count);
428 * lpfc_send_fastpath_evt - Posts events generated from fast path
429 * @phba: Pointer to hba context object.
430 * @evtp: Event data structure.
432 * This function is called from worker thread, when the interrupt
433 * context need to post an event. This function posts the event
434 * to fc transport netlink interface.
437 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
438 struct lpfc_work_evt *evtp)
440 unsigned long evt_category, evt_sub_category;
441 struct lpfc_fast_path_event *fast_evt_data;
443 uint32_t evt_data_size;
444 struct Scsi_Host *shost;
446 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
449 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
450 evt_sub_category = (unsigned long) fast_evt_data->un.
451 fabric_evt.subcategory;
452 shost = lpfc_shost_from_vport(fast_evt_data->vport);
453 if (evt_category == FC_REG_FABRIC_EVENT) {
454 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
455 evt_data = (char *) &fast_evt_data->un.read_check_error;
456 evt_data_size = sizeof(fast_evt_data->un.
458 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
459 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
460 evt_data = (char *) &fast_evt_data->un.fabric_evt;
461 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
463 lpfc_free_fast_evt(phba, fast_evt_data);
466 } else if (evt_category == FC_REG_SCSI_EVENT) {
467 switch (evt_sub_category) {
468 case LPFC_EVENT_QFULL:
469 case LPFC_EVENT_DEVBSY:
470 evt_data = (char *) &fast_evt_data->un.scsi_evt;
471 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
473 case LPFC_EVENT_CHECK_COND:
474 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
475 evt_data_size = sizeof(fast_evt_data->un.
478 case LPFC_EVENT_VARQUEDEPTH:
479 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
480 evt_data_size = sizeof(fast_evt_data->un.
484 lpfc_free_fast_evt(phba, fast_evt_data);
488 lpfc_free_fast_evt(phba, fast_evt_data);
492 fc_host_post_vendor_event(shost,
493 fc_get_event_number(),
498 lpfc_free_fast_evt(phba, fast_evt_data);
503 lpfc_work_list_done(struct lpfc_hba *phba)
505 struct lpfc_work_evt *evtp = NULL;
506 struct lpfc_nodelist *ndlp;
511 spin_lock_irq(&phba->hbalock);
512 while (!list_empty(&phba->work_list)) {
513 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
515 spin_unlock_irq(&phba->hbalock);
518 case LPFC_EVT_ELS_RETRY:
519 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
520 lpfc_els_retry_delay_handler(ndlp);
521 free_evt = 0; /* evt is part of ndlp */
522 /* decrement the node reference count held
523 * for this queued work
527 case LPFC_EVT_DEV_LOSS:
528 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
529 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
531 /* decrement the node reference count held for
534 nlp_did = ndlp->nlp_DID;
536 if (phba->sli_rev == LPFC_SLI_REV4)
537 lpfc_sli4_post_dev_loss_tmo_handler(phba,
541 case LPFC_EVT_ONLINE:
542 if (phba->link_state < LPFC_LINK_DOWN)
543 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
545 *(int *) (evtp->evt_arg1) = 0;
546 complete((struct completion *)(evtp->evt_arg2));
548 case LPFC_EVT_OFFLINE_PREP:
549 if (phba->link_state >= LPFC_LINK_DOWN)
550 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
551 *(int *)(evtp->evt_arg1) = 0;
552 complete((struct completion *)(evtp->evt_arg2));
554 case LPFC_EVT_OFFLINE:
556 lpfc_sli_brdrestart(phba);
557 *(int *)(evtp->evt_arg1) =
558 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
559 lpfc_unblock_mgmt_io(phba);
560 complete((struct completion *)(evtp->evt_arg2));
562 case LPFC_EVT_WARM_START:
564 lpfc_reset_barrier(phba);
565 lpfc_sli_brdreset(phba);
566 lpfc_hba_down_post(phba);
567 *(int *)(evtp->evt_arg1) =
568 lpfc_sli_brdready(phba, HS_MBRDY);
569 lpfc_unblock_mgmt_io(phba);
570 complete((struct completion *)(evtp->evt_arg2));
574 *(int *)(evtp->evt_arg1)
575 = (phba->pport->stopped)
576 ? 0 : lpfc_sli_brdkill(phba);
577 lpfc_unblock_mgmt_io(phba);
578 complete((struct completion *)(evtp->evt_arg2));
580 case LPFC_EVT_FASTPATH_MGMT_EVT:
581 lpfc_send_fastpath_evt(phba, evtp);
584 case LPFC_EVT_RESET_HBA:
585 if (!(phba->pport->load_flag & FC_UNLOADING))
586 lpfc_reset_hba(phba);
591 spin_lock_irq(&phba->hbalock);
593 spin_unlock_irq(&phba->hbalock);
598 lpfc_work_done(struct lpfc_hba *phba)
600 struct lpfc_sli_ring *pring;
601 uint32_t ha_copy, status, control, work_port_events;
602 struct lpfc_vport **vports;
603 struct lpfc_vport *vport;
606 spin_lock_irq(&phba->hbalock);
607 ha_copy = phba->work_ha;
609 spin_unlock_irq(&phba->hbalock);
611 /* First, try to post the next mailbox command to SLI4 device */
612 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
613 lpfc_sli4_post_async_mbox(phba);
615 if (ha_copy & HA_ERATT)
616 /* Handle the error attention event */
617 lpfc_handle_eratt(phba);
619 if (ha_copy & HA_MBATT)
620 lpfc_sli_handle_mb_event(phba);
622 if (ha_copy & HA_LATT)
623 lpfc_handle_latt(phba);
625 /* Process SLI4 events */
626 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
627 if (phba->hba_flag & HBA_RRQ_ACTIVE)
628 lpfc_handle_rrq_active(phba);
629 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
630 lpfc_sli4_fcp_xri_abort_event_proc(phba);
631 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
632 lpfc_sli4_els_xri_abort_event_proc(phba);
633 if (phba->hba_flag & ASYNC_EVENT)
634 lpfc_sli4_async_event_proc(phba);
635 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
636 spin_lock_irq(&phba->hbalock);
637 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
638 spin_unlock_irq(&phba->hbalock);
639 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
641 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
642 lpfc_sli4_fcf_redisc_event_proc(phba);
645 vports = lpfc_create_vport_work_array(phba);
647 for (i = 0; i <= phba->max_vports; i++) {
649 * We could have no vports in array if unloading, so if
650 * this happens then just use the pport
652 if (vports[i] == NULL && i == 0)
658 spin_lock_irq(&vport->work_port_lock);
659 work_port_events = vport->work_port_events;
660 vport->work_port_events &= ~work_port_events;
661 spin_unlock_irq(&vport->work_port_lock);
662 if (work_port_events & WORKER_DISC_TMO)
663 lpfc_disc_timeout_handler(vport);
664 if (work_port_events & WORKER_ELS_TMO)
665 lpfc_els_timeout_handler(vport);
666 if (work_port_events & WORKER_HB_TMO)
667 lpfc_hb_timeout_handler(phba);
668 if (work_port_events & WORKER_MBOX_TMO)
669 lpfc_mbox_timeout_handler(phba);
670 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
671 lpfc_unblock_fabric_iocbs(phba);
672 if (work_port_events & WORKER_FDMI_TMO)
673 lpfc_fdmi_timeout_handler(vport);
674 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
675 lpfc_ramp_down_queue_handler(phba);
676 if (work_port_events & WORKER_RAMP_UP_QUEUE)
677 lpfc_ramp_up_queue_handler(phba);
678 if (work_port_events & WORKER_DELAYED_DISC_TMO)
679 lpfc_delayed_disc_timeout_handler(vport);
681 lpfc_destroy_vport_work_array(phba, vports);
683 pring = &phba->sli.ring[LPFC_ELS_RING];
684 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
685 status >>= (4*LPFC_ELS_RING);
686 if ((status & HA_RXMASK) ||
687 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
688 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
689 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
690 pring->flag |= LPFC_DEFERRED_RING_EVENT;
691 /* Set the lpfc data pending flag */
692 set_bit(LPFC_DATA_READY, &phba->data_flags);
694 if (phba->link_state >= LPFC_LINK_UP) {
695 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
696 lpfc_sli_handle_slow_ring_event(phba, pring,
701 if ((phba->sli_rev == LPFC_SLI_REV4) &
702 (!list_empty(&pring->txq)))
703 lpfc_drain_txq(phba);
705 * Turn on Ring interrupts
707 if (phba->sli_rev <= LPFC_SLI_REV3) {
708 spin_lock_irq(&phba->hbalock);
709 control = readl(phba->HCregaddr);
710 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
711 lpfc_debugfs_slow_ring_trc(phba,
712 "WRK Enable ring: cntl:x%x hacopy:x%x",
713 control, ha_copy, 0);
715 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
716 writel(control, phba->HCregaddr);
717 readl(phba->HCregaddr); /* flush */
719 lpfc_debugfs_slow_ring_trc(phba,
720 "WRK Ring ok: cntl:x%x hacopy:x%x",
721 control, ha_copy, 0);
723 spin_unlock_irq(&phba->hbalock);
726 lpfc_work_list_done(phba);
730 lpfc_do_work(void *p)
732 struct lpfc_hba *phba = p;
735 set_user_nice(current, -20);
736 current->flags |= PF_NOFREEZE;
737 phba->data_flags = 0;
739 while (!kthread_should_stop()) {
740 /* wait and check worker queue activities */
741 rc = wait_event_interruptible(phba->work_waitq,
742 (test_and_clear_bit(LPFC_DATA_READY,
744 || kthread_should_stop()));
745 /* Signal wakeup shall terminate the worker thread */
747 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
748 "0433 Wakeup on signal: rc=x%x\n", rc);
752 /* Attend pending lpfc data processing */
753 lpfc_work_done(phba);
755 phba->worker_thread = NULL;
756 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
757 "0432 Worker thread stopped.\n");
762 * This is only called to handle FC worker events. Since this a rare
763 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
764 * embedding it in the IOCB.
767 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
770 struct lpfc_work_evt *evtp;
774 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
775 * be queued to worker thread for processing
777 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
781 evtp->evt_arg1 = arg1;
782 evtp->evt_arg2 = arg2;
785 spin_lock_irqsave(&phba->hbalock, flags);
786 list_add_tail(&evtp->evt_listp, &phba->work_list);
787 spin_unlock_irqrestore(&phba->hbalock, flags);
789 lpfc_worker_wake_up(phba);
795 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
797 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
798 struct lpfc_hba *phba = vport->phba;
799 struct lpfc_nodelist *ndlp, *next_ndlp;
802 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
803 if (!NLP_CHK_NODE_ACT(ndlp))
805 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
807 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
808 ((vport->port_type == LPFC_NPIV_PORT) &&
809 (ndlp->nlp_DID == NameServer_DID)))
810 lpfc_unreg_rpi(vport, ndlp);
812 /* Leave Fabric nodes alone on link down */
813 if ((phba->sli_rev < LPFC_SLI_REV4) &&
814 (!remove && ndlp->nlp_type & NLP_FABRIC))
816 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
819 : NLP_EVT_DEVICE_RECOVERY);
821 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
822 if (phba->sli_rev == LPFC_SLI_REV4)
823 lpfc_sli4_unreg_all_rpis(vport);
824 lpfc_mbx_unreg_vpi(vport);
825 spin_lock_irq(shost->host_lock);
826 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
827 spin_unlock_irq(shost->host_lock);
832 lpfc_port_link_failure(struct lpfc_vport *vport)
834 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
836 /* Cleanup any outstanding received buffers */
837 lpfc_cleanup_rcv_buffers(vport);
839 /* Cleanup any outstanding RSCN activity */
840 lpfc_els_flush_rscn(vport);
842 /* Cleanup any outstanding ELS commands */
843 lpfc_els_flush_cmd(vport);
845 lpfc_cleanup_rpis(vport, 0);
847 /* Turn off discovery timer if its running */
848 lpfc_can_disctmo(vport);
852 lpfc_linkdown_port(struct lpfc_vport *vport)
854 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
856 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
858 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
859 "Link Down: state:x%x rtry:x%x flg:x%x",
860 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
862 lpfc_port_link_failure(vport);
864 /* Stop delayed Nport discovery */
865 spin_lock_irq(shost->host_lock);
866 vport->fc_flag &= ~FC_DISC_DELAYED;
867 spin_unlock_irq(shost->host_lock);
868 del_timer_sync(&vport->delayed_disc_tmo);
872 lpfc_linkdown(struct lpfc_hba *phba)
874 struct lpfc_vport *vport = phba->pport;
875 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
876 struct lpfc_vport **vports;
880 if (phba->link_state == LPFC_LINK_DOWN)
883 /* Block all SCSI stack I/Os */
884 lpfc_scsi_dev_block(phba);
886 spin_lock_irq(&phba->hbalock);
887 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
888 spin_unlock_irq(&phba->hbalock);
889 if (phba->link_state > LPFC_LINK_DOWN) {
890 phba->link_state = LPFC_LINK_DOWN;
891 spin_lock_irq(shost->host_lock);
892 phba->pport->fc_flag &= ~FC_LBIT;
893 spin_unlock_irq(shost->host_lock);
895 vports = lpfc_create_vport_work_array(phba);
897 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
898 /* Issue a LINK DOWN event to all nodes */
899 lpfc_linkdown_port(vports[i]);
901 lpfc_destroy_vport_work_array(phba, vports);
902 /* Clean up any firmware default rpi's */
903 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
905 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
907 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
908 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
909 == MBX_NOT_FINISHED) {
910 mempool_free(mb, phba->mbox_mem_pool);
914 /* Setup myDID for link up if we are in pt2pt mode */
915 if (phba->pport->fc_flag & FC_PT2PT) {
916 phba->pport->fc_myDID = 0;
917 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
919 lpfc_config_link(phba, mb);
920 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
922 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
923 == MBX_NOT_FINISHED) {
924 mempool_free(mb, phba->mbox_mem_pool);
927 spin_lock_irq(shost->host_lock);
928 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
929 spin_unlock_irq(shost->host_lock);
936 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
938 struct lpfc_nodelist *ndlp;
940 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
941 if (!NLP_CHK_NODE_ACT(ndlp))
943 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
945 if (ndlp->nlp_type & NLP_FABRIC) {
946 /* On Linkup its safe to clean up the ndlp
947 * from Fabric connections.
949 if (ndlp->nlp_DID != Fabric_DID)
950 lpfc_unreg_rpi(vport, ndlp);
951 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
952 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
953 /* Fail outstanding IO now since device is
956 lpfc_unreg_rpi(vport, ndlp);
962 lpfc_linkup_port(struct lpfc_vport *vport)
964 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
965 struct lpfc_hba *phba = vport->phba;
967 if ((vport->load_flag & FC_UNLOADING) != 0)
970 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
971 "Link Up: top:x%x speed:x%x flg:x%x",
972 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
974 /* If NPIV is not enabled, only bring the physical port up */
975 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
976 (vport != phba->pport))
979 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
981 spin_lock_irq(shost->host_lock);
982 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
983 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
984 vport->fc_flag |= FC_NDISC_ACTIVE;
985 vport->fc_ns_retry = 0;
986 spin_unlock_irq(shost->host_lock);
988 if (vport->fc_flag & FC_LBIT)
989 lpfc_linkup_cleanup_nodes(vport);
994 lpfc_linkup(struct lpfc_hba *phba)
996 struct lpfc_vport **vports;
999 lpfc_cleanup_wt_rrqs(phba);
1000 phba->link_state = LPFC_LINK_UP;
1002 /* Unblock fabric iocbs if they are blocked */
1003 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1004 del_timer_sync(&phba->fabric_block_timer);
1006 vports = lpfc_create_vport_work_array(phba);
1008 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1009 lpfc_linkup_port(vports[i]);
1010 lpfc_destroy_vport_work_array(phba, vports);
1011 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1012 (phba->sli_rev < LPFC_SLI_REV4))
1013 lpfc_issue_clear_la(phba, phba->pport);
1019 * This routine handles processing a CLEAR_LA mailbox
1020 * command upon completion. It is setup in the LPFC_MBOXQ
1021 * as the completion routine when the command is
1022 * handed off to the SLI layer.
1025 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1027 struct lpfc_vport *vport = pmb->vport;
1028 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1029 struct lpfc_sli *psli = &phba->sli;
1030 MAILBOX_t *mb = &pmb->u.mb;
1033 /* Since we don't do discovery right now, turn these off here */
1034 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1035 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1036 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1038 /* Check for error */
1039 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1040 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1041 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1042 "0320 CLEAR_LA mbxStatus error x%x hba "
1044 mb->mbxStatus, vport->port_state);
1045 phba->link_state = LPFC_HBA_ERROR;
1049 if (vport->port_type == LPFC_PHYSICAL_PORT)
1050 phba->link_state = LPFC_HBA_READY;
1052 spin_lock_irq(&phba->hbalock);
1053 psli->sli_flag |= LPFC_PROCESS_LA;
1054 control = readl(phba->HCregaddr);
1055 control |= HC_LAINT_ENA;
1056 writel(control, phba->HCregaddr);
1057 readl(phba->HCregaddr); /* flush */
1058 spin_unlock_irq(&phba->hbalock);
1059 mempool_free(pmb, phba->mbox_mem_pool);
1063 /* Device Discovery completes */
1064 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1065 "0225 Device Discovery completes\n");
1066 mempool_free(pmb, phba->mbox_mem_pool);
1068 spin_lock_irq(shost->host_lock);
1069 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1070 spin_unlock_irq(shost->host_lock);
1072 lpfc_can_disctmo(vport);
1074 /* turn on Link Attention interrupts */
1076 spin_lock_irq(&phba->hbalock);
1077 psli->sli_flag |= LPFC_PROCESS_LA;
1078 control = readl(phba->HCregaddr);
1079 control |= HC_LAINT_ENA;
1080 writel(control, phba->HCregaddr);
1081 readl(phba->HCregaddr); /* flush */
1082 spin_unlock_irq(&phba->hbalock);
1089 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1091 struct lpfc_vport *vport = pmb->vport;
1093 if (pmb->u.mb.mbxStatus)
1096 mempool_free(pmb, phba->mbox_mem_pool);
1098 /* don't perform discovery for SLI4 loopback diagnostic test */
1099 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1100 !(phba->hba_flag & HBA_FCOE_MODE) &&
1101 (phba->link_flag & LS_LOOPBACK_MODE))
1104 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1105 vport->fc_flag & FC_PUBLIC_LOOP &&
1106 !(vport->fc_flag & FC_LBIT)) {
1107 /* Need to wait for FAN - use discovery timer
1108 * for timeout. port_state is identically
1109 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1111 lpfc_set_disctmo(vport);
1115 /* Start discovery by sending a FLOGI. port_state is identically
1116 * LPFC_FLOGI while waiting for FLOGI cmpl
1118 if (vport->port_state != LPFC_FLOGI || vport->fc_flag & FC_PT2PT_PLOGI)
1119 lpfc_initial_flogi(vport);
1123 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1124 "0306 CONFIG_LINK mbxStatus error x%x "
1126 pmb->u.mb.mbxStatus, vport->port_state);
1127 mempool_free(pmb, phba->mbox_mem_pool);
1129 lpfc_linkdown(phba);
1131 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1132 "0200 CONFIG_LINK bad hba state x%x\n",
1135 lpfc_issue_clear_la(phba, vport);
1140 * lpfc_sli4_clear_fcf_rr_bmask
1141 * @phba pointer to the struct lpfc_hba for this port.
1142 * This fucnction resets the round robin bit mask and clears the
1143 * fcf priority list. The list deletions are done while holding the
1144 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1145 * from the lpfc_fcf_pri record.
1148 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1150 struct lpfc_fcf_pri *fcf_pri;
1151 struct lpfc_fcf_pri *next_fcf_pri;
1152 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1153 spin_lock_irq(&phba->hbalock);
1154 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1155 &phba->fcf.fcf_pri_list, list) {
1156 list_del_init(&fcf_pri->list);
1157 fcf_pri->fcf_rec.flag = 0;
1159 spin_unlock_irq(&phba->hbalock);
1162 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1164 struct lpfc_vport *vport = mboxq->vport;
1166 if (mboxq->u.mb.mbxStatus) {
1167 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1168 "2017 REG_FCFI mbxStatus error x%x "
1170 mboxq->u.mb.mbxStatus, vport->port_state);
1174 /* Start FCoE discovery by sending a FLOGI. */
1175 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1176 /* Set the FCFI registered flag */
1177 spin_lock_irq(&phba->hbalock);
1178 phba->fcf.fcf_flag |= FCF_REGISTERED;
1179 spin_unlock_irq(&phba->hbalock);
1181 /* If there is a pending FCoE event, restart FCF table scan. */
1182 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1183 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1186 /* Mark successful completion of FCF table scan */
1187 spin_lock_irq(&phba->hbalock);
1188 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1189 phba->hba_flag &= ~FCF_TS_INPROG;
1190 if (vport->port_state != LPFC_FLOGI) {
1191 phba->hba_flag |= FCF_RR_INPROG;
1192 spin_unlock_irq(&phba->hbalock);
1193 lpfc_issue_init_vfi(vport);
1196 spin_unlock_irq(&phba->hbalock);
1200 spin_lock_irq(&phba->hbalock);
1201 phba->hba_flag &= ~FCF_RR_INPROG;
1202 spin_unlock_irq(&phba->hbalock);
1204 mempool_free(mboxq, phba->mbox_mem_pool);
1208 * lpfc_fab_name_match - Check if the fcf fabric name match.
1209 * @fab_name: pointer to fabric name.
1210 * @new_fcf_record: pointer to fcf record.
1212 * This routine compare the fcf record's fabric name with provided
1213 * fabric name. If the fabric name are identical this function
1214 * returns 1 else return 0.
1217 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1219 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1221 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1223 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1225 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1227 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1229 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1231 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1233 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1239 * lpfc_sw_name_match - Check if the fcf switch name match.
1240 * @fab_name: pointer to fabric name.
1241 * @new_fcf_record: pointer to fcf record.
1243 * This routine compare the fcf record's switch name with provided
1244 * switch name. If the switch name are identical this function
1245 * returns 1 else return 0.
1248 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1250 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1252 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1254 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1256 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1258 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1260 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1262 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1264 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1270 * lpfc_mac_addr_match - Check if the fcf mac address match.
1271 * @mac_addr: pointer to mac address.
1272 * @new_fcf_record: pointer to fcf record.
1274 * This routine compare the fcf record's mac address with HBA's
1275 * FCF mac address. If the mac addresses are identical this function
1276 * returns 1 else return 0.
1279 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1281 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1283 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1285 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1287 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1289 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1291 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1297 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1299 return (curr_vlan_id == new_vlan_id);
1303 * lpfc_update_fcf_record - Update driver fcf record
1304 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1305 * @phba: pointer to lpfc hba data structure.
1306 * @fcf_index: Index for the lpfc_fcf_record.
1307 * @new_fcf_record: pointer to hba fcf record.
1309 * This routine updates the driver FCF priority record from the new HBA FCF
1310 * record. This routine is called with the host lock held.
1313 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1314 struct fcf_record *new_fcf_record
1317 struct lpfc_fcf_pri *fcf_pri;
1319 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1320 fcf_pri->fcf_rec.fcf_index = fcf_index;
1321 /* FCF record priority */
1322 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1327 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1328 * @fcf: pointer to driver fcf record.
1329 * @new_fcf_record: pointer to fcf record.
1331 * This routine copies the FCF information from the FCF
1332 * record to lpfc_hba data structure.
1335 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1336 struct fcf_record *new_fcf_record)
1339 fcf_rec->fabric_name[0] =
1340 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1341 fcf_rec->fabric_name[1] =
1342 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1343 fcf_rec->fabric_name[2] =
1344 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1345 fcf_rec->fabric_name[3] =
1346 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1347 fcf_rec->fabric_name[4] =
1348 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1349 fcf_rec->fabric_name[5] =
1350 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1351 fcf_rec->fabric_name[6] =
1352 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1353 fcf_rec->fabric_name[7] =
1354 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1356 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1357 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1358 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1359 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1360 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1361 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1362 /* FCF record index */
1363 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1364 /* FCF record priority */
1365 fcf_rec->priority = new_fcf_record->fip_priority;
1367 fcf_rec->switch_name[0] =
1368 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1369 fcf_rec->switch_name[1] =
1370 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1371 fcf_rec->switch_name[2] =
1372 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1373 fcf_rec->switch_name[3] =
1374 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1375 fcf_rec->switch_name[4] =
1376 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1377 fcf_rec->switch_name[5] =
1378 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1379 fcf_rec->switch_name[6] =
1380 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1381 fcf_rec->switch_name[7] =
1382 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1386 * lpfc_update_fcf_record - Update driver fcf record
1387 * @phba: pointer to lpfc hba data structure.
1388 * @fcf_rec: pointer to driver fcf record.
1389 * @new_fcf_record: pointer to hba fcf record.
1390 * @addr_mode: address mode to be set to the driver fcf record.
1391 * @vlan_id: vlan tag to be set to the driver fcf record.
1392 * @flag: flag bits to be set to the driver fcf record.
1394 * This routine updates the driver FCF record from the new HBA FCF record
1395 * together with the address mode, vlan_id, and other informations. This
1396 * routine is called with the host lock held.
1399 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1400 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1401 uint16_t vlan_id, uint32_t flag)
1403 /* Copy the fields from the HBA's FCF record */
1404 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1405 /* Update other fields of driver FCF record */
1406 fcf_rec->addr_mode = addr_mode;
1407 fcf_rec->vlan_id = vlan_id;
1408 fcf_rec->flag |= (flag | RECORD_VALID);
1409 __lpfc_update_fcf_record_pri(phba,
1410 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1415 * lpfc_register_fcf - Register the FCF with hba.
1416 * @phba: pointer to lpfc hba data structure.
1418 * This routine issues a register fcfi mailbox command to register
1422 lpfc_register_fcf(struct lpfc_hba *phba)
1424 LPFC_MBOXQ_t *fcf_mbxq;
1427 spin_lock_irq(&phba->hbalock);
1428 /* If the FCF is not available do nothing. */
1429 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1430 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1431 spin_unlock_irq(&phba->hbalock);
1435 /* The FCF is already registered, start discovery */
1436 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1437 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1438 phba->hba_flag &= ~FCF_TS_INPROG;
1439 if (phba->pport->port_state != LPFC_FLOGI) {
1440 phba->hba_flag |= FCF_RR_INPROG;
1441 spin_unlock_irq(&phba->hbalock);
1442 lpfc_initial_flogi(phba->pport);
1445 spin_unlock_irq(&phba->hbalock);
1448 spin_unlock_irq(&phba->hbalock);
1450 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1452 spin_lock_irq(&phba->hbalock);
1453 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1454 spin_unlock_irq(&phba->hbalock);
1458 lpfc_reg_fcfi(phba, fcf_mbxq);
1459 fcf_mbxq->vport = phba->pport;
1460 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1461 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1462 if (rc == MBX_NOT_FINISHED) {
1463 spin_lock_irq(&phba->hbalock);
1464 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1465 spin_unlock_irq(&phba->hbalock);
1466 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1473 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1474 * @phba: pointer to lpfc hba data structure.
1475 * @new_fcf_record: pointer to fcf record.
1476 * @boot_flag: Indicates if this record used by boot bios.
1477 * @addr_mode: The address mode to be used by this FCF
1478 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1480 * This routine compare the fcf record with connect list obtained from the
1481 * config region to decide if this FCF can be used for SAN discovery. It returns
1482 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1483 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1484 * is used by boot bios and addr_mode will indicate the addressing mode to be
1485 * used for this FCF when the function returns.
1486 * If the FCF record need to be used with a particular vlan id, the vlan is
1487 * set in the vlan_id on return of the function. If not VLAN tagging need to
1488 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1491 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1492 struct fcf_record *new_fcf_record,
1493 uint32_t *boot_flag, uint32_t *addr_mode,
1496 struct lpfc_fcf_conn_entry *conn_entry;
1497 int i, j, fcf_vlan_id = 0;
1499 /* Find the lowest VLAN id in the FCF record */
1500 for (i = 0; i < 512; i++) {
1501 if (new_fcf_record->vlan_bitmap[i]) {
1502 fcf_vlan_id = i * 8;
1504 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1512 /* FCF not valid/available or solicitation in progress */
1513 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1514 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1515 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1518 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1520 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1522 if (phba->valid_vlan)
1523 *vlan_id = phba->vlan_id;
1525 *vlan_id = LPFC_FCOE_NULL_VID;
1530 * If there are no FCF connection table entry, driver connect to all
1533 if (list_empty(&phba->fcf_conn_rec_list)) {
1535 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1539 * When there are no FCF connect entries, use driver's default
1540 * addressing mode - FPMA.
1542 if (*addr_mode & LPFC_FCF_FPMA)
1543 *addr_mode = LPFC_FCF_FPMA;
1545 /* If FCF record report a vlan id use that vlan id */
1547 *vlan_id = fcf_vlan_id;
1549 *vlan_id = LPFC_FCOE_NULL_VID;
1553 list_for_each_entry(conn_entry,
1554 &phba->fcf_conn_rec_list, list) {
1555 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1558 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1559 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1562 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1563 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1566 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1568 * If the vlan bit map does not have the bit set for the
1569 * vlan id to be used, then it is not a match.
1571 if (!(new_fcf_record->vlan_bitmap
1572 [conn_entry->conn_rec.vlan_tag / 8] &
1573 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1578 * If connection record does not support any addressing mode,
1579 * skip the FCF record.
1581 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1582 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1586 * Check if the connection record specifies a required
1589 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1590 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1593 * If SPMA required but FCF not support this continue.
1595 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1596 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1597 new_fcf_record) & LPFC_FCF_SPMA))
1601 * If FPMA required but FCF not support this continue.
1603 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1604 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1605 new_fcf_record) & LPFC_FCF_FPMA))
1610 * This fcf record matches filtering criteria.
1612 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1618 * If user did not specify any addressing mode, or if the
1619 * preferred addressing mode specified by user is not supported
1620 * by FCF, allow fabric to pick the addressing mode.
1622 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1625 * If the user specified a required address mode, assign that
1628 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1629 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1630 *addr_mode = (conn_entry->conn_rec.flags &
1632 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1634 * If the user specified a preferred address mode, use the
1635 * addr mode only if FCF support the addr_mode.
1637 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1638 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1639 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1640 (*addr_mode & LPFC_FCF_SPMA))
1641 *addr_mode = LPFC_FCF_SPMA;
1642 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1643 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1644 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1645 (*addr_mode & LPFC_FCF_FPMA))
1646 *addr_mode = LPFC_FCF_FPMA;
1648 /* If matching connect list has a vlan id, use it */
1649 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1650 *vlan_id = conn_entry->conn_rec.vlan_tag;
1652 * If no vlan id is specified in connect list, use the vlan id
1655 else if (fcf_vlan_id)
1656 *vlan_id = fcf_vlan_id;
1658 *vlan_id = LPFC_FCOE_NULL_VID;
1667 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1668 * @phba: pointer to lpfc hba data structure.
1669 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1671 * This function check if there is any fcoe event pending while driver
1672 * scan FCF entries. If there is any pending event, it will restart the
1673 * FCF saning and return 1 else return 0.
1676 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1679 * If the Link is up and no FCoE events while in the
1680 * FCF discovery, no need to restart FCF discovery.
1682 if ((phba->link_state >= LPFC_LINK_UP) &&
1683 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1686 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1687 "2768 Pending link or FCF event during current "
1688 "handling of the previous event: link_state:x%x, "
1689 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1690 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1691 phba->fcoe_eventtag);
1693 spin_lock_irq(&phba->hbalock);
1694 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1695 spin_unlock_irq(&phba->hbalock);
1697 if (phba->link_state >= LPFC_LINK_UP) {
1698 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1699 "2780 Restart FCF table scan due to "
1700 "pending FCF event:evt_tag_at_scan:x%x, "
1701 "evt_tag_current:x%x\n",
1702 phba->fcoe_eventtag_at_fcf_scan,
1703 phba->fcoe_eventtag);
1704 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1707 * Do not continue FCF discovery and clear FCF_TS_INPROG
1710 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1711 "2833 Stop FCF discovery process due to link "
1712 "state change (x%x)\n", phba->link_state);
1713 spin_lock_irq(&phba->hbalock);
1714 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1715 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1716 spin_unlock_irq(&phba->hbalock);
1719 /* Unregister the currently registered FCF if required */
1721 spin_lock_irq(&phba->hbalock);
1722 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1723 spin_unlock_irq(&phba->hbalock);
1724 lpfc_sli4_unregister_fcf(phba);
1730 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1731 * @phba: pointer to lpfc hba data structure.
1732 * @fcf_cnt: number of eligible fcf record seen so far.
1734 * This function makes an running random selection decision on FCF record to
1735 * use through a sequence of @fcf_cnt eligible FCF records with equal
1736 * probability. To perform integer manunipulation of random numbers with
1737 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1738 * from random32() are taken as the random random number generated.
1740 * Returns true when outcome is for the newly read FCF record should be
1741 * chosen; otherwise, return false when outcome is for keeping the previously
1742 * chosen FCF record.
1745 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1749 /* Get 16-bit uniform random number */
1750 rand_num = (0xFFFF & random32());
1752 /* Decision with probability 1/fcf_cnt */
1753 if ((fcf_cnt * rand_num) < 0xFFFF)
1760 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1761 * @phba: pointer to lpfc hba data structure.
1762 * @mboxq: pointer to mailbox object.
1763 * @next_fcf_index: pointer to holder of next fcf index.
1765 * This routine parses the non-embedded fcf mailbox command by performing the
1766 * necessarily error checking, non-embedded read FCF record mailbox command
1767 * SGE parsing, and endianness swapping.
1769 * Returns the pointer to the new FCF record in the non-embedded mailbox
1770 * command DMA memory if successfully, other NULL.
1772 static struct fcf_record *
1773 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1774 uint16_t *next_fcf_index)
1777 dma_addr_t phys_addr;
1778 struct lpfc_mbx_sge sge;
1779 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1780 uint32_t shdr_status, shdr_add_status;
1781 union lpfc_sli4_cfg_shdr *shdr;
1782 struct fcf_record *new_fcf_record;
1784 /* Get the first SGE entry from the non-embedded DMA memory. This
1785 * routine only uses a single SGE.
1787 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1788 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1789 if (unlikely(!mboxq->sge_array)) {
1790 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1791 "2524 Failed to get the non-embedded SGE "
1792 "virtual address\n");
1795 virt_addr = mboxq->sge_array->addr[0];
1797 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1798 lpfc_sli_pcimem_bcopy(shdr, shdr,
1799 sizeof(union lpfc_sli4_cfg_shdr));
1800 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1801 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1802 if (shdr_status || shdr_add_status) {
1803 if (shdr_status == STATUS_FCF_TABLE_EMPTY)
1804 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1805 "2726 READ_FCF_RECORD Indicates empty "
1808 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1809 "2521 READ_FCF_RECORD mailbox failed "
1810 "with status x%x add_status x%x, "
1811 "mbx\n", shdr_status, shdr_add_status);
1815 /* Interpreting the returned information of the FCF record */
1816 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1817 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1818 sizeof(struct lpfc_mbx_read_fcf_tbl));
1819 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1820 new_fcf_record = (struct fcf_record *)(virt_addr +
1821 sizeof(struct lpfc_mbx_read_fcf_tbl));
1822 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1823 offsetof(struct fcf_record, vlan_bitmap));
1824 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1825 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
1827 return new_fcf_record;
1831 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1832 * @phba: pointer to lpfc hba data structure.
1833 * @fcf_record: pointer to the fcf record.
1834 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1835 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1837 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1841 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1842 struct fcf_record *fcf_record,
1844 uint16_t next_fcf_index)
1846 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1847 "2764 READ_FCF_RECORD:\n"
1848 "\tFCF_Index : x%x\n"
1849 "\tFCF_Avail : x%x\n"
1850 "\tFCF_Valid : x%x\n"
1852 "\tFIP_Priority : x%x\n"
1853 "\tMAC_Provider : x%x\n"
1854 "\tLowest VLANID : x%x\n"
1855 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1856 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1857 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1858 "\tNext_FCF_Index: x%x\n",
1859 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1860 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1861 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1862 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
1863 fcf_record->fip_priority,
1864 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1866 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1867 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1868 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1869 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1870 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1871 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1872 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1873 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1874 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1875 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1876 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1877 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1878 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1879 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1880 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1881 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1882 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1883 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1884 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1885 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1886 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1887 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1892 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1893 * @phba: pointer to lpfc hba data structure.
1894 * @fcf_rec: pointer to an existing FCF record.
1895 * @new_fcf_record: pointer to a new FCF record.
1896 * @new_vlan_id: vlan id from the new FCF record.
1898 * This function performs matching test of a new FCF record against an existing
1899 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1900 * will not be used as part of the FCF record matching criteria.
1902 * Returns true if all the fields matching, otherwise returns false.
1905 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1906 struct lpfc_fcf_rec *fcf_rec,
1907 struct fcf_record *new_fcf_record,
1908 uint16_t new_vlan_id)
1910 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1911 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1913 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1915 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1917 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1919 if (fcf_rec->priority != new_fcf_record->fip_priority)
1925 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1926 * @vport: Pointer to vport object.
1927 * @fcf_index: index to next fcf.
1929 * This function processing the roundrobin fcf failover to next fcf index.
1930 * When this function is invoked, there will be a current fcf registered
1932 * Return: 0 for continue retrying flogi on currently registered fcf;
1933 * 1 for stop flogi on currently registered fcf;
1935 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1937 struct lpfc_hba *phba = vport->phba;
1940 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1941 spin_lock_irq(&phba->hbalock);
1942 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1943 spin_unlock_irq(&phba->hbalock);
1944 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1945 "2872 Devloss tmo with no eligible "
1946 "FCF, unregister in-use FCF (x%x) "
1947 "and rescan FCF table\n",
1948 phba->fcf.current_rec.fcf_indx);
1949 lpfc_unregister_fcf_rescan(phba);
1950 goto stop_flogi_current_fcf;
1952 /* Mark the end to FLOGI roundrobin failover */
1953 phba->hba_flag &= ~FCF_RR_INPROG;
1954 /* Allow action to new fcf asynchronous event */
1955 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1956 spin_unlock_irq(&phba->hbalock);
1957 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1958 "2865 No FCF available, stop roundrobin FCF "
1959 "failover and change port state:x%x/x%x\n",
1960 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1961 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1962 goto stop_flogi_current_fcf;
1964 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1965 "2794 Try FLOGI roundrobin FCF failover to "
1966 "(x%x)\n", fcf_index);
1967 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1969 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1970 "2761 FLOGI roundrobin FCF failover "
1971 "failed (rc:x%x) to read FCF (x%x)\n",
1972 rc, phba->fcf.current_rec.fcf_indx);
1974 goto stop_flogi_current_fcf;
1978 stop_flogi_current_fcf:
1979 lpfc_can_disctmo(vport);
1984 * lpfc_sli4_fcf_pri_list_del
1985 * @phba: pointer to lpfc hba data structure.
1986 * @fcf_index the index of the fcf record to delete
1987 * This routine checks the on list flag of the fcf_index to be deleted.
1988 * If it is one the list then it is removed from the list, and the flag
1989 * is cleared. This routine grab the hbalock before removing the fcf
1990 * record from the list.
1992 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
1995 struct lpfc_fcf_pri *new_fcf_pri;
1997 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1998 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1999 "3058 deleting idx x%x pri x%x flg x%x\n",
2000 fcf_index, new_fcf_pri->fcf_rec.priority,
2001 new_fcf_pri->fcf_rec.flag);
2002 spin_lock_irq(&phba->hbalock);
2003 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2004 if (phba->fcf.current_rec.priority ==
2005 new_fcf_pri->fcf_rec.priority)
2006 phba->fcf.eligible_fcf_cnt--;
2007 list_del_init(&new_fcf_pri->list);
2008 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2010 spin_unlock_irq(&phba->hbalock);
2014 * lpfc_sli4_set_fcf_flogi_fail
2015 * @phba: pointer to lpfc hba data structure.
2016 * @fcf_index the index of the fcf record to update
2017 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2018 * flag so the the round robin slection for the particular priority level
2019 * will try a different fcf record that does not have this bit set.
2020 * If the fcf record is re-read for any reason this flag is cleared brfore
2021 * adding it to the priority list.
2024 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2026 struct lpfc_fcf_pri *new_fcf_pri;
2027 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2028 spin_lock_irq(&phba->hbalock);
2029 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2030 spin_unlock_irq(&phba->hbalock);
2034 * lpfc_sli4_fcf_pri_list_add
2035 * @phba: pointer to lpfc hba data structure.
2036 * @fcf_index the index of the fcf record to add
2037 * This routine checks the priority of the fcf_index to be added.
2038 * If it is a lower priority than the current head of the fcf_pri list
2039 * then it is added to the list in the right order.
2040 * If it is the same priority as the current head of the list then it
2041 * is added to the head of the list and its bit in the rr_bmask is set.
2042 * If the fcf_index to be added is of a higher priority than the current
2043 * head of the list then the rr_bmask is cleared, its bit is set in the
2044 * rr_bmask and it is added to the head of the list.
2046 * 0=success 1=failure
2048 int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba, uint16_t fcf_index,
2049 struct fcf_record *new_fcf_record)
2051 uint16_t current_fcf_pri;
2052 uint16_t last_index;
2053 struct lpfc_fcf_pri *fcf_pri;
2054 struct lpfc_fcf_pri *next_fcf_pri;
2055 struct lpfc_fcf_pri *new_fcf_pri;
2058 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2059 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2060 "3059 adding idx x%x pri x%x flg x%x\n",
2061 fcf_index, new_fcf_record->fip_priority,
2062 new_fcf_pri->fcf_rec.flag);
2063 spin_lock_irq(&phba->hbalock);
2064 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2065 list_del_init(&new_fcf_pri->list);
2066 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2067 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2068 if (list_empty(&phba->fcf.fcf_pri_list)) {
2069 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2070 ret = lpfc_sli4_fcf_rr_index_set(phba,
2071 new_fcf_pri->fcf_rec.fcf_index);
2075 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2076 LPFC_SLI4_FCF_TBL_INDX_MAX);
2077 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2078 ret = 0; /* Empty rr list */
2081 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2082 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2083 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2084 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2085 memset(phba->fcf.fcf_rr_bmask, 0,
2086 sizeof(*phba->fcf.fcf_rr_bmask));
2087 /* fcfs_at_this_priority_level = 1; */
2088 phba->fcf.eligible_fcf_cnt = 1;
2090 /* fcfs_at_this_priority_level++; */
2091 phba->fcf.eligible_fcf_cnt++;
2092 ret = lpfc_sli4_fcf_rr_index_set(phba,
2093 new_fcf_pri->fcf_rec.fcf_index);
2097 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2098 &phba->fcf.fcf_pri_list, list) {
2099 if (new_fcf_pri->fcf_rec.priority <=
2100 fcf_pri->fcf_rec.priority) {
2101 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2102 list_add(&new_fcf_pri->list,
2103 &phba->fcf.fcf_pri_list);
2105 list_add(&new_fcf_pri->list,
2106 &((struct lpfc_fcf_pri *)
2107 fcf_pri->list.prev)->list);
2110 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2111 || new_fcf_pri->fcf_rec.priority <
2112 next_fcf_pri->fcf_rec.priority) {
2113 list_add(&new_fcf_pri->list, &fcf_pri->list);
2117 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2123 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2124 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2125 spin_unlock_irq(&phba->hbalock);
2130 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2131 * @phba: pointer to lpfc hba data structure.
2132 * @mboxq: pointer to mailbox object.
2134 * This function iterates through all the fcf records available in
2135 * HBA and chooses the optimal FCF record for discovery. After finding
2136 * the FCF for discovery it registers the FCF record and kicks start
2138 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2139 * use an FCF record which matches fabric name and mac address of the
2140 * currently used FCF record.
2141 * If the driver supports only one FCF, it will try to use the FCF record
2142 * used by BOOT_BIOS.
2145 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2147 struct fcf_record *new_fcf_record;
2148 uint32_t boot_flag, addr_mode;
2149 uint16_t fcf_index, next_fcf_index;
2150 struct lpfc_fcf_rec *fcf_rec = NULL;
2153 bool select_new_fcf;
2156 /* If there is pending FCoE event restart FCF table scan */
2157 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2158 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2162 /* Parse the FCF record from the non-embedded mailbox command */
2163 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2165 if (!new_fcf_record) {
2166 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2167 "2765 Mailbox command READ_FCF_RECORD "
2168 "failed to retrieve a FCF record.\n");
2169 /* Let next new FCF event trigger fast failover */
2170 spin_lock_irq(&phba->hbalock);
2171 phba->hba_flag &= ~FCF_TS_INPROG;
2172 spin_unlock_irq(&phba->hbalock);
2173 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2177 /* Check the FCF record against the connection list */
2178 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2179 &addr_mode, &vlan_id);
2181 /* Log the FCF record information if turned on */
2182 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2186 * If the fcf record does not match with connect list entries
2187 * read the next entry; otherwise, this is an eligible FCF
2188 * record for roundrobin FCF failover.
2191 lpfc_sli4_fcf_pri_list_del(phba,
2192 bf_get(lpfc_fcf_record_fcf_index,
2194 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2195 "2781 FCF (x%x) failed connection "
2196 "list check: (x%x/x%x/%x)\n",
2197 bf_get(lpfc_fcf_record_fcf_index,
2199 bf_get(lpfc_fcf_record_fcf_avail,
2201 bf_get(lpfc_fcf_record_fcf_valid,
2203 bf_get(lpfc_fcf_record_fcf_sol,
2205 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2206 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2207 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2208 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2209 phba->fcf.current_rec.fcf_indx) {
2210 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2211 "2862 FCF (x%x) matches property "
2212 "of in-use FCF (x%x)\n",
2213 bf_get(lpfc_fcf_record_fcf_index,
2215 phba->fcf.current_rec.fcf_indx);
2219 * In case the current in-use FCF record becomes
2220 * invalid/unavailable during FCF discovery that
2221 * was not triggered by fast FCF failover process,
2222 * treat it as fast FCF failover.
2224 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2225 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2226 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2227 "2835 Invalid in-use FCF "
2228 "(x%x), enter FCF failover "
2230 phba->fcf.current_rec.fcf_indx);
2231 spin_lock_irq(&phba->hbalock);
2232 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2233 spin_unlock_irq(&phba->hbalock);
2234 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2235 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2236 LPFC_FCOE_FCF_GET_FIRST);
2242 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2243 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2250 * If this is not the first FCF discovery of the HBA, use last
2251 * FCF record for the discovery. The condition that a rescan
2252 * matches the in-use FCF record: fabric name, switch name, mac
2253 * address, and vlan_id.
2255 spin_lock_irq(&phba->hbalock);
2256 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2257 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2258 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2259 new_fcf_record, vlan_id)) {
2260 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2261 phba->fcf.current_rec.fcf_indx) {
2262 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2263 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2264 /* Stop FCF redisc wait timer */
2265 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2267 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2268 /* Fast failover, mark completed */
2269 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2270 spin_unlock_irq(&phba->hbalock);
2271 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2272 "2836 New FCF matches in-use "
2274 phba->fcf.current_rec.fcf_indx);
2277 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2278 "2863 New FCF (x%x) matches "
2279 "property of in-use FCF (x%x)\n",
2280 bf_get(lpfc_fcf_record_fcf_index,
2282 phba->fcf.current_rec.fcf_indx);
2285 * Read next FCF record from HBA searching for the matching
2286 * with in-use record only if not during the fast failover
2287 * period. In case of fast failover period, it shall try to
2288 * determine whether the FCF record just read should be the
2291 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2292 spin_unlock_irq(&phba->hbalock);
2297 * Update on failover FCF record only if it's in FCF fast-failover
2298 * period; otherwise, update on current FCF record.
2300 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2301 fcf_rec = &phba->fcf.failover_rec;
2303 fcf_rec = &phba->fcf.current_rec;
2305 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2307 * If the driver FCF record does not have boot flag
2308 * set and new hba fcf record has boot flag set, use
2309 * the new hba fcf record.
2311 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2312 /* Choose this FCF record */
2313 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2314 "2837 Update current FCF record "
2315 "(x%x) with new FCF record (x%x)\n",
2317 bf_get(lpfc_fcf_record_fcf_index,
2319 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2320 addr_mode, vlan_id, BOOT_ENABLE);
2321 spin_unlock_irq(&phba->hbalock);
2325 * If the driver FCF record has boot flag set and the
2326 * new hba FCF record does not have boot flag, read
2327 * the next FCF record.
2329 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2330 spin_unlock_irq(&phba->hbalock);
2334 * If the new hba FCF record has lower priority value
2335 * than the driver FCF record, use the new record.
2337 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2338 /* Choose the new FCF record with lower priority */
2339 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2340 "2838 Update current FCF record "
2341 "(x%x) with new FCF record (x%x)\n",
2343 bf_get(lpfc_fcf_record_fcf_index,
2345 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2346 addr_mode, vlan_id, 0);
2347 /* Reset running random FCF selection count */
2348 phba->fcf.eligible_fcf_cnt = 1;
2349 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2350 /* Update running random FCF selection count */
2351 phba->fcf.eligible_fcf_cnt++;
2352 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2353 phba->fcf.eligible_fcf_cnt);
2354 if (select_new_fcf) {
2355 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2356 "2839 Update current FCF record "
2357 "(x%x) with new FCF record (x%x)\n",
2359 bf_get(lpfc_fcf_record_fcf_index,
2361 /* Choose the new FCF by random selection */
2362 __lpfc_update_fcf_record(phba, fcf_rec,
2364 addr_mode, vlan_id, 0);
2367 spin_unlock_irq(&phba->hbalock);
2371 * This is the first suitable FCF record, choose this record for
2372 * initial best-fit FCF.
2375 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2376 "2840 Update initial FCF candidate "
2378 bf_get(lpfc_fcf_record_fcf_index,
2380 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2381 addr_mode, vlan_id, (boot_flag ?
2383 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2384 /* Setup initial running random FCF selection count */
2385 phba->fcf.eligible_fcf_cnt = 1;
2386 /* Seeding the random number generator for random selection */
2387 seed = (uint32_t)(0xFFFFFFFF & jiffies);
2390 spin_unlock_irq(&phba->hbalock);
2394 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2395 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2396 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2398 * Case of FCF fast failover scan
2402 * It has not found any suitable FCF record, cancel
2403 * FCF scan inprogress, and do nothing
2405 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2406 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2407 "2782 No suitable FCF found: "
2409 phba->fcoe_eventtag_at_fcf_scan,
2410 bf_get(lpfc_fcf_record_fcf_index,
2412 spin_lock_irq(&phba->hbalock);
2413 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2414 phba->hba_flag &= ~FCF_TS_INPROG;
2415 spin_unlock_irq(&phba->hbalock);
2416 /* Unregister in-use FCF and rescan */
2417 lpfc_printf_log(phba, KERN_INFO,
2419 "2864 On devloss tmo "
2420 "unreg in-use FCF and "
2421 "rescan FCF table\n");
2422 lpfc_unregister_fcf_rescan(phba);
2426 * Let next new FCF event trigger fast failover
2428 phba->hba_flag &= ~FCF_TS_INPROG;
2429 spin_unlock_irq(&phba->hbalock);
2433 * It has found a suitable FCF record that is not
2434 * the same as in-use FCF record, unregister the
2435 * in-use FCF record, replace the in-use FCF record
2436 * with the new FCF record, mark FCF fast failover
2437 * completed, and then start register the new FCF
2441 /* Unregister the current in-use FCF record */
2442 lpfc_unregister_fcf(phba);
2444 /* Replace in-use record with the new record */
2445 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2446 "2842 Replace in-use FCF (x%x) "
2447 "with failover FCF (x%x)\n",
2448 phba->fcf.current_rec.fcf_indx,
2449 phba->fcf.failover_rec.fcf_indx);
2450 memcpy(&phba->fcf.current_rec,
2451 &phba->fcf.failover_rec,
2452 sizeof(struct lpfc_fcf_rec));
2454 * Mark the fast FCF failover rediscovery completed
2455 * and the start of the first round of the roundrobin
2458 spin_lock_irq(&phba->hbalock);
2459 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2460 spin_unlock_irq(&phba->hbalock);
2461 /* Register to the new FCF record */
2462 lpfc_register_fcf(phba);
2465 * In case of transaction period to fast FCF failover,
2466 * do nothing when search to the end of the FCF table.
2468 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2469 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2472 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2473 phba->fcf.fcf_flag & FCF_IN_USE) {
2475 * In case the current in-use FCF record no
2476 * longer existed during FCF discovery that
2477 * was not triggered by fast FCF failover
2478 * process, treat it as fast FCF failover.
2480 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2481 "2841 In-use FCF record (x%x) "
2482 "not reported, entering fast "
2483 "FCF failover mode scanning.\n",
2484 phba->fcf.current_rec.fcf_indx);
2485 spin_lock_irq(&phba->hbalock);
2486 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2487 spin_unlock_irq(&phba->hbalock);
2488 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2489 LPFC_FCOE_FCF_GET_FIRST);
2492 /* Register to the new FCF record */
2493 lpfc_register_fcf(phba);
2496 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2500 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2501 lpfc_register_fcf(phba);
2507 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2508 * @phba: pointer to lpfc hba data structure.
2509 * @mboxq: pointer to mailbox object.
2511 * This is the callback function for FLOGI failure roundrobin FCF failover
2512 * read FCF record mailbox command from the eligible FCF record bmask for
2513 * performing the failover. If the FCF read back is not valid/available, it
2514 * fails through to retrying FLOGI to the currently registered FCF again.
2515 * Otherwise, if the FCF read back is valid and available, it will set the
2516 * newly read FCF record to the failover FCF record, unregister currently
2517 * registered FCF record, copy the failover FCF record to the current
2518 * FCF record, and then register the current FCF record before proceeding
2519 * to trying FLOGI on the new failover FCF.
2522 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2524 struct fcf_record *new_fcf_record;
2525 uint32_t boot_flag, addr_mode;
2526 uint16_t next_fcf_index, fcf_index;
2527 uint16_t current_fcf_index;
2531 /* If link state is not up, stop the roundrobin failover process */
2532 if (phba->link_state < LPFC_LINK_UP) {
2533 spin_lock_irq(&phba->hbalock);
2534 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2535 phba->hba_flag &= ~FCF_RR_INPROG;
2536 spin_unlock_irq(&phba->hbalock);
2540 /* Parse the FCF record from the non-embedded mailbox command */
2541 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2543 if (!new_fcf_record) {
2544 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2545 "2766 Mailbox command READ_FCF_RECORD "
2546 "failed to retrieve a FCF record.\n");
2550 /* Get the needed parameters from FCF record */
2551 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2552 &addr_mode, &vlan_id);
2554 /* Log the FCF record information if turned on */
2555 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2558 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2560 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2561 "2848 Remove ineligible FCF (x%x) from "
2562 "from roundrobin bmask\n", fcf_index);
2563 /* Clear roundrobin bmask bit for ineligible FCF */
2564 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2565 /* Perform next round of roundrobin FCF failover */
2566 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2567 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2573 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2574 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2575 "2760 Perform FLOGI roundrobin FCF failover: "
2576 "FCF (x%x) back to FCF (x%x)\n",
2577 phba->fcf.current_rec.fcf_indx, fcf_index);
2578 /* Wait 500 ms before retrying FLOGI to current FCF */
2580 lpfc_issue_init_vfi(phba->pport);
2584 /* Upload new FCF record to the failover FCF record */
2585 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2586 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2587 phba->fcf.failover_rec.fcf_indx, fcf_index);
2588 spin_lock_irq(&phba->hbalock);
2589 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2590 new_fcf_record, addr_mode, vlan_id,
2591 (boot_flag ? BOOT_ENABLE : 0));
2592 spin_unlock_irq(&phba->hbalock);
2594 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2596 /* Unregister the current in-use FCF record */
2597 lpfc_unregister_fcf(phba);
2599 /* Replace in-use record with the new record */
2600 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2601 sizeof(struct lpfc_fcf_rec));
2603 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2604 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2605 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2608 lpfc_register_fcf(phba);
2610 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2614 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2615 * @phba: pointer to lpfc hba data structure.
2616 * @mboxq: pointer to mailbox object.
2618 * This is the callback function of read FCF record mailbox command for
2619 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2620 * failover when a new FCF event happened. If the FCF read back is
2621 * valid/available and it passes the connection list check, it updates
2622 * the bmask for the eligible FCF record for roundrobin failover.
2625 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2627 struct fcf_record *new_fcf_record;
2628 uint32_t boot_flag, addr_mode;
2629 uint16_t fcf_index, next_fcf_index;
2633 /* If link state is not up, no need to proceed */
2634 if (phba->link_state < LPFC_LINK_UP)
2637 /* If FCF discovery period is over, no need to proceed */
2638 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2641 /* Parse the FCF record from the non-embedded mailbox command */
2642 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2644 if (!new_fcf_record) {
2645 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2646 "2767 Mailbox command READ_FCF_RECORD "
2647 "failed to retrieve a FCF record.\n");
2651 /* Check the connection list for eligibility */
2652 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2653 &addr_mode, &vlan_id);
2655 /* Log the FCF record information if turned on */
2656 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2662 /* Update the eligible FCF record index bmask */
2663 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2665 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2668 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2672 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2673 * @phba: pointer to lpfc hba data structure.
2674 * @mboxq: pointer to mailbox data structure.
2676 * This function handles completion of init vfi mailbox command.
2679 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2681 struct lpfc_vport *vport = mboxq->vport;
2684 * VFI not supported on interface type 0, just do the flogi
2685 * Also continue if the VFI is in use - just use the same one.
2687 if (mboxq->u.mb.mbxStatus &&
2688 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2689 LPFC_SLI_INTF_IF_TYPE_0) &&
2690 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2691 lpfc_printf_vlog(vport, KERN_ERR,
2693 "2891 Init VFI mailbox failed 0x%x\n",
2694 mboxq->u.mb.mbxStatus);
2695 mempool_free(mboxq, phba->mbox_mem_pool);
2696 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2700 lpfc_initial_flogi(vport);
2701 mempool_free(mboxq, phba->mbox_mem_pool);
2706 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2707 * @vport: pointer to lpfc_vport data structure.
2709 * This function issue a init_vfi mailbox command to initialize the VFI and
2710 * VPI for the physical port.
2713 lpfc_issue_init_vfi(struct lpfc_vport *vport)
2715 LPFC_MBOXQ_t *mboxq;
2717 struct lpfc_hba *phba = vport->phba;
2719 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2721 lpfc_printf_vlog(vport, KERN_ERR,
2722 LOG_MBOX, "2892 Failed to allocate "
2723 "init_vfi mailbox\n");
2726 lpfc_init_vfi(mboxq, vport);
2727 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2728 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2729 if (rc == MBX_NOT_FINISHED) {
2730 lpfc_printf_vlog(vport, KERN_ERR,
2731 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2732 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2737 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2738 * @phba: pointer to lpfc hba data structure.
2739 * @mboxq: pointer to mailbox data structure.
2741 * This function handles completion of init vpi mailbox command.
2744 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2746 struct lpfc_vport *vport = mboxq->vport;
2747 struct lpfc_nodelist *ndlp;
2748 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2750 if (mboxq->u.mb.mbxStatus) {
2751 lpfc_printf_vlog(vport, KERN_ERR,
2753 "2609 Init VPI mailbox failed 0x%x\n",
2754 mboxq->u.mb.mbxStatus);
2755 mempool_free(mboxq, phba->mbox_mem_pool);
2756 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2759 spin_lock_irq(shost->host_lock);
2760 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2761 spin_unlock_irq(shost->host_lock);
2763 /* If this port is physical port or FDISC is done, do reg_vpi */
2764 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2765 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2767 lpfc_printf_vlog(vport, KERN_ERR,
2769 "2731 Cannot find fabric "
2770 "controller node\n");
2772 lpfc_register_new_vport(phba, vport, ndlp);
2773 mempool_free(mboxq, phba->mbox_mem_pool);
2777 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2778 lpfc_initial_fdisc(vport);
2780 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
2781 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2782 "2606 No NPIV Fabric support\n");
2784 mempool_free(mboxq, phba->mbox_mem_pool);
2789 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2790 * @vport: pointer to lpfc_vport data structure.
2792 * This function issue a init_vpi mailbox command to initialize
2793 * VPI for the vport.
2796 lpfc_issue_init_vpi(struct lpfc_vport *vport)
2798 LPFC_MBOXQ_t *mboxq;
2801 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2803 lpfc_printf_vlog(vport, KERN_ERR,
2804 LOG_MBOX, "2607 Failed to allocate "
2805 "init_vpi mailbox\n");
2808 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2809 mboxq->vport = vport;
2810 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2811 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2812 if (rc == MBX_NOT_FINISHED) {
2813 lpfc_printf_vlog(vport, KERN_ERR,
2814 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2815 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2820 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2821 * @phba: pointer to lpfc hba data structure.
2823 * This function loops through the list of vports on the @phba and issues an
2824 * FDISC if possible.
2827 lpfc_start_fdiscs(struct lpfc_hba *phba)
2829 struct lpfc_vport **vports;
2832 vports = lpfc_create_vport_work_array(phba);
2833 if (vports != NULL) {
2834 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2835 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2837 /* There are no vpi for this vport */
2838 if (vports[i]->vpi > phba->max_vpi) {
2839 lpfc_vport_set_state(vports[i],
2843 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2844 lpfc_vport_set_state(vports[i],
2848 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
2849 lpfc_issue_init_vpi(vports[i]);
2852 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2853 lpfc_initial_fdisc(vports[i]);
2855 lpfc_vport_set_state(vports[i],
2856 FC_VPORT_NO_FABRIC_SUPP);
2857 lpfc_printf_vlog(vports[i], KERN_ERR,
2860 "Fabric support\n");
2864 lpfc_destroy_vport_work_array(phba, vports);
2868 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2870 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2871 struct lpfc_vport *vport = mboxq->vport;
2872 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2875 * VFI not supported for interface type 0, so ignore any mailbox
2876 * error (except VFI in use) and continue with the discovery.
2878 if (mboxq->u.mb.mbxStatus &&
2879 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2880 LPFC_SLI_INTF_IF_TYPE_0) &&
2881 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2882 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2883 "2018 REG_VFI mbxStatus error x%x "
2885 mboxq->u.mb.mbxStatus, vport->port_state);
2886 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2887 /* FLOGI failed, use loop map to make discovery list */
2888 lpfc_disc_list_loopmap(vport);
2889 /* Start discovery */
2890 lpfc_disc_start(vport);
2893 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2897 /* If the VFI is already registered, there is nothing else to do */
2898 if (vport->fc_flag & FC_VFI_REGISTERED)
2901 /* The VPI is implicitly registered when the VFI is registered */
2902 spin_lock_irq(shost->host_lock);
2903 vport->vpi_state |= LPFC_VPI_REGISTERED;
2904 vport->fc_flag |= FC_VFI_REGISTERED;
2905 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2906 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2907 spin_unlock_irq(shost->host_lock);
2909 /* In case SLI4 FC loopback test, we are ready */
2910 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2911 (phba->link_flag & LS_LOOPBACK_MODE)) {
2912 phba->link_state = LPFC_HBA_READY;
2916 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
2918 * For private loop or for NPort pt2pt,
2919 * just start discovery and we are done.
2921 if ((vport->fc_flag & FC_PT2PT) ||
2922 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2923 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
2925 /* Use loop map to make discovery list */
2926 lpfc_disc_list_loopmap(vport);
2927 /* Start discovery */
2928 lpfc_disc_start(vport);
2930 lpfc_start_fdiscs(phba);
2931 lpfc_do_scr_ns_plogi(phba, vport);
2936 mempool_free(mboxq, phba->mbox_mem_pool);
2937 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2943 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2945 MAILBOX_t *mb = &pmb->u.mb;
2946 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
2947 struct lpfc_vport *vport = pmb->vport;
2950 /* Check for error */
2951 if (mb->mbxStatus) {
2952 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
2953 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2954 "0319 READ_SPARAM mbxStatus error x%x "
2956 mb->mbxStatus, vport->port_state);
2957 lpfc_linkdown(phba);
2961 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
2962 sizeof (struct serv_parm));
2963 lpfc_update_vport_wwn(vport);
2964 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2965 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
2966 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
2969 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2971 mempool_free(pmb, phba->mbox_mem_pool);
2975 pmb->context1 = NULL;
2976 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2978 lpfc_issue_clear_la(phba, vport);
2979 mempool_free(pmb, phba->mbox_mem_pool);
2984 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
2986 struct lpfc_vport *vport = phba->pport;
2987 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
2988 struct Scsi_Host *shost;
2990 struct lpfc_dmabuf *mp;
2992 struct fcf_record *fcf_record;
2993 uint32_t fc_flags = 0;
2995 spin_lock_irq(&phba->hbalock);
2996 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
2997 case LPFC_LINK_SPEED_1GHZ:
2998 case LPFC_LINK_SPEED_2GHZ:
2999 case LPFC_LINK_SPEED_4GHZ:
3000 case LPFC_LINK_SPEED_8GHZ:
3001 case LPFC_LINK_SPEED_10GHZ:
3002 case LPFC_LINK_SPEED_16GHZ:
3003 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3006 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3010 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3011 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
3013 shost = lpfc_shost_from_vport(vport);
3014 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3015 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3017 /* if npiv is enabled and this adapter supports npiv log
3018 * a message that npiv is not supported in this topology
3020 if (phba->cfg_enable_npiv && phba->max_vpi)
3021 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3022 "1309 Link Up Event npiv not supported in loop "
3024 /* Get Loop Map information */
3025 if (bf_get(lpfc_mbx_read_top_il, la))
3026 fc_flags |= FC_LBIT;
3028 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3029 i = la->lilpBde64.tus.f.bdeSize;
3032 phba->alpa_map[0] = 0;
3034 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3045 numalpa = phba->alpa_map[0];
3047 while (j < numalpa) {
3048 memset(un.pamap, 0, 16);
3049 for (k = 1; j < numalpa; k++) {
3051 phba->alpa_map[j + 1];
3056 /* Link Up Event ALPA map */
3057 lpfc_printf_log(phba,
3060 "1304 Link Up Event "
3061 "ALPA map Data: x%x "
3063 un.pa.wd1, un.pa.wd2,
3064 un.pa.wd3, un.pa.wd4);
3069 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3070 if (phba->max_vpi && phba->cfg_enable_npiv &&
3071 (phba->sli_rev >= LPFC_SLI_REV3))
3072 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3074 vport->fc_myDID = phba->fc_pref_DID;
3075 fc_flags |= FC_LBIT;
3077 spin_unlock_irq(&phba->hbalock);
3080 spin_lock_irq(shost->host_lock);
3081 vport->fc_flag |= fc_flags;
3082 spin_unlock_irq(shost->host_lock);
3086 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3090 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3092 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3095 sparam_mbox->vport = vport;
3096 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3097 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3098 if (rc == MBX_NOT_FINISHED) {
3099 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
3100 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3102 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3106 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3107 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3110 vport->port_state = LPFC_LOCAL_CFG_LINK;
3111 lpfc_config_link(phba, cfglink_mbox);
3112 cfglink_mbox->vport = vport;
3113 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3114 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3115 if (rc == MBX_NOT_FINISHED) {
3116 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3120 vport->port_state = LPFC_VPORT_UNKNOWN;
3122 * Add the driver's default FCF record at FCF index 0 now. This
3123 * is phase 1 implementation that support FCF index 0 and driver
3126 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3127 fcf_record = kzalloc(sizeof(struct fcf_record),
3129 if (unlikely(!fcf_record)) {
3130 lpfc_printf_log(phba, KERN_ERR,
3132 "2554 Could not allocate memory for "
3138 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3139 LPFC_FCOE_FCF_DEF_INDEX);
3140 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3142 lpfc_printf_log(phba, KERN_ERR,
3144 "2013 Could not manually add FCF "
3145 "record 0, status %d\n", rc);
3153 * The driver is expected to do FIP/FCF. Call the port
3154 * and get the FCF Table.
3156 spin_lock_irq(&phba->hbalock);
3157 if (phba->hba_flag & FCF_TS_INPROG) {
3158 spin_unlock_irq(&phba->hbalock);
3161 /* This is the initial FCF discovery scan */
3162 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3163 spin_unlock_irq(&phba->hbalock);
3164 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3165 "2778 Start FCF table scan at linkup\n");
3166 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3167 LPFC_FCOE_FCF_GET_FIRST);
3169 spin_lock_irq(&phba->hbalock);
3170 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3171 spin_unlock_irq(&phba->hbalock);
3174 /* Reset FCF roundrobin bmask for new discovery */
3175 lpfc_sli4_clear_fcf_rr_bmask(phba);
3180 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3181 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3182 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3183 vport->port_state, sparam_mbox, cfglink_mbox);
3184 lpfc_issue_clear_la(phba, vport);
3189 lpfc_enable_la(struct lpfc_hba *phba)
3192 struct lpfc_sli *psli = &phba->sli;
3193 spin_lock_irq(&phba->hbalock);
3194 psli->sli_flag |= LPFC_PROCESS_LA;
3195 if (phba->sli_rev <= LPFC_SLI_REV3) {
3196 control = readl(phba->HCregaddr);
3197 control |= HC_LAINT_ENA;
3198 writel(control, phba->HCregaddr);
3199 readl(phba->HCregaddr); /* flush */
3201 spin_unlock_irq(&phba->hbalock);
3205 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3207 lpfc_linkdown(phba);
3208 lpfc_enable_la(phba);
3209 lpfc_unregister_unused_fcf(phba);
3210 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3215 * This routine handles processing a READ_TOPOLOGY mailbox
3216 * command upon completion. It is setup in the LPFC_MBOXQ
3217 * as the completion routine when the command is
3218 * handed off to the SLI layer.
3221 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3223 struct lpfc_vport *vport = pmb->vport;
3224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3225 struct lpfc_mbx_read_top *la;
3226 MAILBOX_t *mb = &pmb->u.mb;
3227 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3229 /* Unblock ELS traffic */
3230 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
3231 /* Check for error */
3232 if (mb->mbxStatus) {
3233 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3234 "1307 READ_LA mbox error x%x state x%x\n",
3235 mb->mbxStatus, vport->port_state);
3236 lpfc_mbx_issue_link_down(phba);
3237 phba->link_state = LPFC_HBA_ERROR;
3238 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3241 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3243 memcpy(&phba->alpa_map[0], mp->virt, 128);
3245 spin_lock_irq(shost->host_lock);
3246 if (bf_get(lpfc_mbx_read_top_pb, la))
3247 vport->fc_flag |= FC_BYPASSED_MODE;
3249 vport->fc_flag &= ~FC_BYPASSED_MODE;
3250 spin_unlock_irq(shost->host_lock);
3252 if ((phba->fc_eventTag < la->eventTag) ||
3253 (phba->fc_eventTag == la->eventTag)) {
3254 phba->fc_stat.LinkMultiEvent++;
3255 if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
3256 if (phba->fc_eventTag != 0)
3257 lpfc_linkdown(phba);
3260 phba->fc_eventTag = la->eventTag;
3261 spin_lock_irq(&phba->hbalock);
3262 if (bf_get(lpfc_mbx_read_top_mm, la))
3263 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3265 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3266 spin_unlock_irq(&phba->hbalock);
3268 phba->link_events++;
3269 if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
3270 (!bf_get(lpfc_mbx_read_top_mm, la))) {
3271 phba->fc_stat.LinkUp++;
3272 if (phba->link_flag & LS_LOOPBACK_MODE) {
3273 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3274 "1306 Link Up Event in loop back mode "
3275 "x%x received Data: x%x x%x x%x x%x\n",
3276 la->eventTag, phba->fc_eventTag,
3277 bf_get(lpfc_mbx_read_top_alpa_granted,
3279 bf_get(lpfc_mbx_read_top_link_spd, la),
3282 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3283 "1303 Link Up Event x%x received "
3284 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3285 la->eventTag, phba->fc_eventTag,
3286 bf_get(lpfc_mbx_read_top_alpa_granted,
3288 bf_get(lpfc_mbx_read_top_link_spd, la),
3290 bf_get(lpfc_mbx_read_top_mm, la),
3291 bf_get(lpfc_mbx_read_top_fa, la),
3292 phba->wait_4_mlo_maint_flg);
3294 lpfc_mbx_process_link_up(phba, la);
3295 } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
3296 LPFC_ATT_LINK_DOWN) {
3297 phba->fc_stat.LinkDown++;
3298 if (phba->link_flag & LS_LOOPBACK_MODE)
3299 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3300 "1308 Link Down Event in loop back mode "
3302 "Data: x%x x%x x%x\n",
3303 la->eventTag, phba->fc_eventTag,
3304 phba->pport->port_state, vport->fc_flag);
3306 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3307 "1305 Link Down Event x%x received "
3308 "Data: x%x x%x x%x x%x x%x\n",
3309 la->eventTag, phba->fc_eventTag,
3310 phba->pport->port_state, vport->fc_flag,
3311 bf_get(lpfc_mbx_read_top_mm, la),
3312 bf_get(lpfc_mbx_read_top_fa, la));
3313 lpfc_mbx_issue_link_down(phba);
3315 if ((bf_get(lpfc_mbx_read_top_mm, la)) &&
3316 (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)) {
3317 if (phba->link_state != LPFC_LINK_DOWN) {
3318 phba->fc_stat.LinkDown++;
3319 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3320 "1312 Link Down Event x%x received "
3321 "Data: x%x x%x x%x\n",
3322 la->eventTag, phba->fc_eventTag,
3323 phba->pport->port_state, vport->fc_flag);
3324 lpfc_mbx_issue_link_down(phba);
3326 lpfc_enable_la(phba);
3328 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3329 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3330 "Data: x%x x%x x%x\n",
3331 la->eventTag, phba->fc_eventTag,
3332 phba->pport->port_state, vport->fc_flag);
3334 * The cmnd that triggered this will be waiting for this
3337 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3338 if (phba->wait_4_mlo_maint_flg) {
3339 phba->wait_4_mlo_maint_flg = 0;
3340 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3344 if (bf_get(lpfc_mbx_read_top_fa, la)) {
3345 if (bf_get(lpfc_mbx_read_top_mm, la))
3346 lpfc_issue_clear_la(phba, vport);
3347 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3349 bf_get(lpfc_mbx_read_top_fa, la));
3352 lpfc_mbx_cmpl_read_topology_free_mbuf:
3353 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3355 mempool_free(pmb, phba->mbox_mem_pool);
3360 * This routine handles processing a REG_LOGIN mailbox
3361 * command upon completion. It is setup in the LPFC_MBOXQ
3362 * as the completion routine when the command is
3363 * handed off to the SLI layer.
3366 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3368 struct lpfc_vport *vport = pmb->vport;
3369 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3370 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3371 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3373 pmb->context1 = NULL;
3374 pmb->context2 = NULL;
3376 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3377 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3379 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3380 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3381 /* We rcvd a rscn after issuing this
3382 * mbox reg login, we may have cycled
3383 * back through the state and be
3384 * back at reg login state so this
3385 * mbox needs to be ignored becase
3386 * there is another reg login in
3389 spin_lock_irq(shost->host_lock);
3390 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3391 spin_unlock_irq(shost->host_lock);
3393 /* Good status, call state machine */
3394 lpfc_disc_state_machine(vport, ndlp, pmb,
3395 NLP_EVT_CMPL_REG_LOGIN);
3397 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3399 mempool_free(pmb, phba->mbox_mem_pool);
3400 /* decrement the node reference count held for this callback
3409 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3411 MAILBOX_t *mb = &pmb->u.mb;
3412 struct lpfc_vport *vport = pmb->vport;
3413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3415 switch (mb->mbxStatus) {
3418 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3419 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3422 /* If VPI is busy, reset the HBA */
3424 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3425 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3426 vport->vpi, mb->mbxStatus);
3427 if (!(phba->pport->load_flag & FC_UNLOADING))
3428 lpfc_workq_post_event(phba, NULL, NULL,
3429 LPFC_EVT_RESET_HBA);
3431 spin_lock_irq(shost->host_lock);
3432 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3433 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3434 spin_unlock_irq(shost->host_lock);
3435 vport->unreg_vpi_cmpl = VPORT_OK;
3436 mempool_free(pmb, phba->mbox_mem_pool);
3437 lpfc_cleanup_vports_rrqs(vport, NULL);
3439 * This shost reference might have been taken at the beginning of
3440 * lpfc_vport_delete()
3442 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3443 scsi_host_put(shost);
3447 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3449 struct lpfc_hba *phba = vport->phba;
3453 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3457 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3458 mbox->vport = vport;
3459 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3460 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3461 if (rc == MBX_NOT_FINISHED) {
3462 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3463 "1800 Could not issue unreg_vpi\n");
3464 mempool_free(mbox, phba->mbox_mem_pool);
3465 vport->unreg_vpi_cmpl = VPORT_ERROR;
3472 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3474 struct lpfc_vport *vport = pmb->vport;
3475 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3476 MAILBOX_t *mb = &pmb->u.mb;
3478 switch (mb->mbxStatus) {
3482 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3483 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3485 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3486 spin_lock_irq(shost->host_lock);
3487 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3488 spin_unlock_irq(shost->host_lock);
3489 vport->fc_myDID = 0;
3493 spin_lock_irq(shost->host_lock);
3494 vport->vpi_state |= LPFC_VPI_REGISTERED;
3495 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3496 spin_unlock_irq(shost->host_lock);
3497 vport->num_disc_nodes = 0;
3498 /* go thru NPR list and issue ELS PLOGIs */
3499 if (vport->fc_npr_cnt)
3500 lpfc_els_disc_plogi(vport);
3502 if (!vport->num_disc_nodes) {
3503 spin_lock_irq(shost->host_lock);
3504 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3505 spin_unlock_irq(shost->host_lock);
3506 lpfc_can_disctmo(vport);
3508 vport->port_state = LPFC_VPORT_READY;
3511 mempool_free(pmb, phba->mbox_mem_pool);
3516 * lpfc_create_static_vport - Read HBA config region to create static vports.
3517 * @phba: pointer to lpfc hba data structure.
3519 * This routine issue a DUMP mailbox command for config region 22 to get
3520 * the list of static vports to be created. The function create vports
3521 * based on the information returned from the HBA.
3524 lpfc_create_static_vport(struct lpfc_hba *phba)
3526 LPFC_MBOXQ_t *pmb = NULL;
3528 struct static_vport_info *vport_info;
3529 int mbx_wait_rc = 0, i;
3530 struct fc_vport_identifiers vport_id;
3531 struct fc_vport *new_fc_vport;
3532 struct Scsi_Host *shost;
3533 struct lpfc_vport *vport;
3534 uint16_t offset = 0;
3535 uint8_t *vport_buff;
3536 struct lpfc_dmabuf *mp;
3537 uint32_t byte_count = 0;
3539 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3541 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3542 "0542 lpfc_create_static_vport failed to"
3543 " allocate mailbox memory\n");
3546 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3549 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3551 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3552 "0543 lpfc_create_static_vport failed to"
3553 " allocate vport_info\n");
3554 mempool_free(pmb, phba->mbox_mem_pool);
3558 vport_buff = (uint8_t *) vport_info;
3560 /* free dma buffer from previous round */
3561 if (pmb->context1) {
3562 mp = (struct lpfc_dmabuf *)pmb->context1;
3563 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3566 if (lpfc_dump_static_vport(phba, pmb, offset))
3569 pmb->vport = phba->pport;
3570 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3573 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3574 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3575 "0544 lpfc_create_static_vport failed to"
3576 " issue dump mailbox command ret 0x%x "
3578 mbx_wait_rc, mb->mbxStatus);
3582 if (phba->sli_rev == LPFC_SLI_REV4) {
3583 byte_count = pmb->u.mqe.un.mb_words[5];
3584 mp = (struct lpfc_dmabuf *)pmb->context1;
3585 if (byte_count > sizeof(struct static_vport_info) -
3587 byte_count = sizeof(struct static_vport_info)
3589 memcpy(vport_buff + offset, mp->virt, byte_count);
3590 offset += byte_count;
3592 if (mb->un.varDmp.word_cnt >
3593 sizeof(struct static_vport_info) - offset)
3594 mb->un.varDmp.word_cnt =
3595 sizeof(struct static_vport_info)
3597 byte_count = mb->un.varDmp.word_cnt;
3598 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3599 vport_buff + offset,
3602 offset += byte_count;
3605 } while (byte_count &&
3606 offset < sizeof(struct static_vport_info));
3609 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3610 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3611 != VPORT_INFO_REV)) {
3612 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3613 "0545 lpfc_create_static_vport bad"
3614 " information header 0x%x 0x%x\n",
3615 le32_to_cpu(vport_info->signature),
3616 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3621 shost = lpfc_shost_from_vport(phba->pport);
3623 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3624 memset(&vport_id, 0, sizeof(vport_id));
3625 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3626 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3627 if (!vport_id.port_name || !vport_id.node_name)
3630 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3631 vport_id.vport_type = FC_PORTTYPE_NPIV;
3632 vport_id.disable = false;
3633 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3635 if (!new_fc_vport) {
3636 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3637 "0546 lpfc_create_static_vport failed to"
3642 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3643 vport->vport_flag |= STATIC_VPORT;
3648 if (mbx_wait_rc != MBX_TIMEOUT) {
3649 if (pmb->context1) {
3650 mp = (struct lpfc_dmabuf *)pmb->context1;
3651 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3654 mempool_free(pmb, phba->mbox_mem_pool);
3661 * This routine handles processing a Fabric REG_LOGIN mailbox
3662 * command upon completion. It is setup in the LPFC_MBOXQ
3663 * as the completion routine when the command is
3664 * handed off to the SLI layer.
3667 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3669 struct lpfc_vport *vport = pmb->vport;
3670 MAILBOX_t *mb = &pmb->u.mb;
3671 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3672 struct lpfc_nodelist *ndlp;
3673 struct Scsi_Host *shost;
3675 ndlp = (struct lpfc_nodelist *) pmb->context2;
3676 pmb->context1 = NULL;
3677 pmb->context2 = NULL;
3679 if (mb->mbxStatus) {
3680 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3681 "0258 Register Fabric login error: 0x%x\n",
3683 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3685 mempool_free(pmb, phba->mbox_mem_pool);
3687 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3688 /* FLOGI failed, use loop map to make discovery list */
3689 lpfc_disc_list_loopmap(vport);
3691 /* Start discovery */
3692 lpfc_disc_start(vport);
3693 /* Decrement the reference count to ndlp after the
3694 * reference to the ndlp are done.
3700 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3701 /* Decrement the reference count to ndlp after the reference
3702 * to the ndlp are done.
3708 if (phba->sli_rev < LPFC_SLI_REV4)
3709 ndlp->nlp_rpi = mb->un.varWords[0];
3710 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3711 ndlp->nlp_type |= NLP_FABRIC;
3712 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3714 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3715 /* when physical port receive logo donot start
3716 * vport discovery */
3717 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3718 lpfc_start_fdiscs(phba);
3720 shost = lpfc_shost_from_vport(vport);
3721 spin_lock_irq(shost->host_lock);
3722 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
3723 spin_unlock_irq(shost->host_lock);
3725 lpfc_do_scr_ns_plogi(phba, vport);
3728 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3730 mempool_free(pmb, phba->mbox_mem_pool);
3732 /* Drop the reference count from the mbox at the end after
3733 * all the current reference to the ndlp have been done.
3740 * This routine handles processing a NameServer REG_LOGIN mailbox
3741 * command upon completion. It is setup in the LPFC_MBOXQ
3742 * as the completion routine when the command is
3743 * handed off to the SLI layer.
3746 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3748 MAILBOX_t *mb = &pmb->u.mb;
3749 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3750 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3751 struct lpfc_vport *vport = pmb->vport;
3753 pmb->context1 = NULL;
3754 pmb->context2 = NULL;
3756 if (mb->mbxStatus) {
3758 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3759 "0260 Register NameServer error: 0x%x\n",
3761 /* decrement the node reference count held for this
3762 * callback function.
3765 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3767 mempool_free(pmb, phba->mbox_mem_pool);
3769 /* If no other thread is using the ndlp, free it */
3770 lpfc_nlp_not_used(ndlp);
3772 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3774 * RegLogin failed, use loop map to make discovery
3777 lpfc_disc_list_loopmap(vport);
3779 /* Start discovery */
3780 lpfc_disc_start(vport);
3783 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3787 if (phba->sli_rev < LPFC_SLI_REV4)
3788 ndlp->nlp_rpi = mb->un.varWords[0];
3789 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3790 ndlp->nlp_type |= NLP_FABRIC;
3791 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3793 if (vport->port_state < LPFC_VPORT_READY) {
3794 /* Link up discovery requires Fabric registration. */
3795 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
3796 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3797 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3798 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3799 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3801 /* Issue SCR just before NameServer GID_FT Query */
3802 lpfc_issue_els_scr(vport, SCR_DID, 0);
3805 vport->fc_ns_retry = 0;
3806 /* Good status, issue CT Request to NameServer */
3807 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
3808 /* Cannot issue NameServer Query, so finish up discovery */
3812 /* decrement the node reference count held for this
3813 * callback function.
3816 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3818 mempool_free(pmb, phba->mbox_mem_pool);
3824 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3826 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3827 struct fc_rport *rport;
3828 struct lpfc_rport_data *rdata;
3829 struct fc_rport_identifiers rport_ids;
3830 struct lpfc_hba *phba = vport->phba;
3832 /* Remote port has reappeared. Re-register w/ FC transport */
3833 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3834 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
3835 rport_ids.port_id = ndlp->nlp_DID;
3836 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3839 * We leave our node pointer in rport->dd_data when we unregister a
3840 * FCP target port. But fc_remote_port_add zeros the space to which
3841 * rport->dd_data points. So, if we're reusing a previously
3842 * registered port, drop the reference that we took the last time we
3843 * registered the port.
3845 if (ndlp->rport && ndlp->rport->dd_data &&
3846 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
3849 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3850 "rport add: did:x%x flg:x%x type x%x",
3851 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3853 /* Don't add the remote port if unloading. */
3854 if (vport->load_flag & FC_UNLOADING)
3857 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
3858 if (!rport || !get_device(&rport->dev)) {
3859 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3860 "Warning: fc_remote_port_add failed\n");
3864 /* initialize static port data */
3865 rport->maxframe_size = ndlp->nlp_maxframe;
3866 rport->supported_classes = ndlp->nlp_class_sup;
3867 rdata = rport->dd_data;
3868 rdata->pnode = lpfc_nlp_get(ndlp);
3870 if (ndlp->nlp_type & NLP_FCP_TARGET)
3871 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3872 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3873 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3875 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3876 fc_remote_port_rolechg(rport, rport_ids.roles);
3878 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3879 "3183 rport register x%06x, rport %p role x%x\n",
3880 ndlp->nlp_DID, rport, rport_ids.roles);
3882 if ((rport->scsi_target_id != -1) &&
3883 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
3884 ndlp->nlp_sid = rport->scsi_target_id;
3890 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
3892 struct fc_rport *rport = ndlp->rport;
3894 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
3895 "rport delete: did:x%x flg:x%x type x%x",
3896 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3898 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3899 "3184 rport unregister x%06x, rport %p\n",
3900 ndlp->nlp_DID, rport);
3902 fc_remote_port_delete(rport);
3908 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
3910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3912 spin_lock_irq(shost->host_lock);
3914 case NLP_STE_UNUSED_NODE:
3915 vport->fc_unused_cnt += count;
3917 case NLP_STE_PLOGI_ISSUE:
3918 vport->fc_plogi_cnt += count;
3920 case NLP_STE_ADISC_ISSUE:
3921 vport->fc_adisc_cnt += count;
3923 case NLP_STE_REG_LOGIN_ISSUE:
3924 vport->fc_reglogin_cnt += count;
3926 case NLP_STE_PRLI_ISSUE:
3927 vport->fc_prli_cnt += count;
3929 case NLP_STE_UNMAPPED_NODE:
3930 vport->fc_unmap_cnt += count;
3932 case NLP_STE_MAPPED_NODE:
3933 vport->fc_map_cnt += count;
3935 case NLP_STE_NPR_NODE:
3936 vport->fc_npr_cnt += count;
3939 spin_unlock_irq(shost->host_lock);
3943 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3944 int old_state, int new_state)
3946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3948 if (new_state == NLP_STE_UNMAPPED_NODE) {
3949 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3950 ndlp->nlp_type |= NLP_FC_NODE;
3952 if (new_state == NLP_STE_MAPPED_NODE)
3953 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3954 if (new_state == NLP_STE_NPR_NODE)
3955 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
3957 /* Transport interface */
3958 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
3959 old_state == NLP_STE_UNMAPPED_NODE)) {
3960 vport->phba->nport_event_cnt++;
3961 lpfc_unregister_remote_port(ndlp);
3964 if (new_state == NLP_STE_MAPPED_NODE ||
3965 new_state == NLP_STE_UNMAPPED_NODE) {
3966 vport->phba->nport_event_cnt++;
3968 * Tell the fc transport about the port, if we haven't
3969 * already. If we have, and it's a scsi entity, be
3970 * sure to unblock any attached scsi devices
3972 lpfc_register_remote_port(vport, ndlp);
3974 if ((new_state == NLP_STE_MAPPED_NODE) &&
3975 (vport->stat_data_enabled)) {
3977 * A new target is discovered, if there is no buffer for
3978 * statistical data collection allocate buffer.
3980 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
3981 sizeof(struct lpfc_scsicmd_bkt),
3984 if (!ndlp->lat_data)
3985 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3986 "0286 lpfc_nlp_state_cleanup failed to "
3987 "allocate statistical data buffer DID "
3988 "0x%x\n", ndlp->nlp_DID);
3991 * if we added to Mapped list, but the remote port
3992 * registration failed or assigned a target id outside
3993 * our presentable range - move the node to the
3996 if (new_state == NLP_STE_MAPPED_NODE &&
3998 ndlp->rport->scsi_target_id == -1 ||
3999 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4000 spin_lock_irq(shost->host_lock);
4001 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4002 spin_unlock_irq(shost->host_lock);
4003 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4008 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4010 static char *states[] = {
4011 [NLP_STE_UNUSED_NODE] = "UNUSED",
4012 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4013 [NLP_STE_ADISC_ISSUE] = "ADISC",
4014 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4015 [NLP_STE_PRLI_ISSUE] = "PRLI",
4016 [NLP_STE_LOGO_ISSUE] = "LOGO",
4017 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4018 [NLP_STE_MAPPED_NODE] = "MAPPED",
4019 [NLP_STE_NPR_NODE] = "NPR",
4022 if (state < NLP_STE_MAX_STATE && states[state])
4023 strlcpy(buffer, states[state], size);
4025 snprintf(buffer, size, "unknown (%d)", state);
4030 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4033 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4034 int old_state = ndlp->nlp_state;
4035 char name1[16], name2[16];
4037 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4038 "0904 NPort state transition x%06x, %s -> %s\n",
4040 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4041 lpfc_nlp_state_name(name2, sizeof(name2), state));
4043 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4044 "node statechg did:x%x old:%d ste:%d",
4045 ndlp->nlp_DID, old_state, state);
4047 if (old_state == NLP_STE_NPR_NODE &&
4048 state != NLP_STE_NPR_NODE)
4049 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4050 if (old_state == NLP_STE_UNMAPPED_NODE) {
4051 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4052 ndlp->nlp_type &= ~NLP_FC_NODE;
4055 if (list_empty(&ndlp->nlp_listp)) {
4056 spin_lock_irq(shost->host_lock);
4057 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4058 spin_unlock_irq(shost->host_lock);
4059 } else if (old_state)
4060 lpfc_nlp_counters(vport, old_state, -1);
4062 ndlp->nlp_state = state;
4063 lpfc_nlp_counters(vport, state, 1);
4064 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4068 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4072 if (list_empty(&ndlp->nlp_listp)) {
4073 spin_lock_irq(shost->host_lock);
4074 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4075 spin_unlock_irq(shost->host_lock);
4080 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4084 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4085 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4086 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4087 spin_lock_irq(shost->host_lock);
4088 list_del_init(&ndlp->nlp_listp);
4089 spin_unlock_irq(shost->host_lock);
4090 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4091 NLP_STE_UNUSED_NODE);
4095 lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4097 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4098 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4099 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4100 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4101 NLP_STE_UNUSED_NODE);
4104 * lpfc_initialize_node - Initialize all fields of node object
4105 * @vport: Pointer to Virtual Port object.
4106 * @ndlp: Pointer to FC node object.
4107 * @did: FC_ID of the node.
4109 * This function is always called when node object need to be initialized.
4110 * It initializes all the fields of the node object. Although the reference
4111 * to phba from @ndlp can be obtained indirectly through it's reference to
4112 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4113 * to the life-span of the @ndlp might go beyond the existence of @vport as
4114 * the final release of ndlp is determined by its reference count. And, the
4115 * operation on @ndlp needs the reference to phba.
4118 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4121 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4122 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4123 init_timer(&ndlp->nlp_delayfunc);
4124 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
4125 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
4126 ndlp->nlp_DID = did;
4127 ndlp->vport = vport;
4128 ndlp->phba = vport->phba;
4129 ndlp->nlp_sid = NLP_NO_SID;
4130 kref_init(&ndlp->kref);
4131 NLP_INT_NODE_ACT(ndlp);
4132 atomic_set(&ndlp->cmd_pending, 0);
4133 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4134 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4135 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
4138 struct lpfc_nodelist *
4139 lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4142 struct lpfc_hba *phba = vport->phba;
4144 unsigned long flags;
4149 spin_lock_irqsave(&phba->ndlp_lock, flags);
4150 /* The ndlp should not be in memory free mode */
4151 if (NLP_CHK_FREE_REQ(ndlp)) {
4152 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4153 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4154 "0277 lpfc_enable_node: ndlp:x%p "
4155 "usgmap:x%x refcnt:%d\n",
4156 (void *)ndlp, ndlp->nlp_usg_map,
4157 atomic_read(&ndlp->kref.refcount));
4160 /* The ndlp should not already be in active mode */
4161 if (NLP_CHK_NODE_ACT(ndlp)) {
4162 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4163 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4164 "0278 lpfc_enable_node: ndlp:x%p "
4165 "usgmap:x%x refcnt:%d\n",
4166 (void *)ndlp, ndlp->nlp_usg_map,
4167 atomic_read(&ndlp->kref.refcount));
4171 /* Keep the original DID */
4172 did = ndlp->nlp_DID;
4174 /* re-initialize ndlp except of ndlp linked list pointer */
4175 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4176 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
4177 lpfc_initialize_node(vport, ndlp, did);
4179 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4181 if (state != NLP_STE_UNUSED_NODE)
4182 lpfc_nlp_set_state(vport, ndlp, state);
4184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4185 "node enable: did:x%x",
4186 ndlp->nlp_DID, 0, 0);
4191 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4194 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4195 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4196 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4197 * until ALL other outstanding threads have completed. We check
4198 * that the ndlp not already in the UNUSED state before we proceed.
4200 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4202 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4203 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4204 lpfc_cleanup_vports_rrqs(vport, ndlp);
4210 * Start / ReStart rescue timer for Discovery / RSCN handling
4213 lpfc_set_disctmo(struct lpfc_vport *vport)
4215 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4216 struct lpfc_hba *phba = vport->phba;
4219 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4220 /* For FAN, timeout should be greater than edtov */
4221 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4223 /* Normal discovery timeout should be > than ELS/CT timeout
4224 * FC spec states we need 3 * ratov for CT requests
4226 tmo = ((phba->fc_ratov * 3) + 3);
4230 if (!timer_pending(&vport->fc_disctmo)) {
4231 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4232 "set disc timer: tmo:x%x state:x%x flg:x%x",
4233 tmo, vport->port_state, vport->fc_flag);
4236 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
4237 spin_lock_irq(shost->host_lock);
4238 vport->fc_flag |= FC_DISC_TMO;
4239 spin_unlock_irq(shost->host_lock);
4241 /* Start Discovery Timer state <hba_state> */
4242 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4243 "0247 Start Discovery Timer state x%x "
4244 "Data: x%x x%lx x%x x%x\n",
4245 vport->port_state, tmo,
4246 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4247 vport->fc_adisc_cnt);
4253 * Cancel rescue timer for Discovery / RSCN handling
4256 lpfc_can_disctmo(struct lpfc_vport *vport)
4258 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4259 unsigned long iflags;
4261 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4262 "can disc timer: state:x%x rtry:x%x flg:x%x",
4263 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4265 /* Turn off discovery timer if its running */
4266 if (vport->fc_flag & FC_DISC_TMO) {
4267 spin_lock_irqsave(shost->host_lock, iflags);
4268 vport->fc_flag &= ~FC_DISC_TMO;
4269 spin_unlock_irqrestore(shost->host_lock, iflags);
4270 del_timer_sync(&vport->fc_disctmo);
4271 spin_lock_irqsave(&vport->work_port_lock, iflags);
4272 vport->work_port_events &= ~WORKER_DISC_TMO;
4273 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4276 /* Cancel Discovery Timer state <hba_state> */
4277 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4278 "0248 Cancel Discovery Timer state x%x "
4279 "Data: x%x x%x x%x\n",
4280 vport->port_state, vport->fc_flag,
4281 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4286 * Check specified ring for outstanding IOCB on the SLI queue
4287 * Return true if iocb matches the specified nport
4290 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4291 struct lpfc_sli_ring *pring,
4292 struct lpfc_iocbq *iocb,
4293 struct lpfc_nodelist *ndlp)
4295 struct lpfc_sli *psli = &phba->sli;
4296 IOCB_t *icmd = &iocb->iocb;
4297 struct lpfc_vport *vport = ndlp->vport;
4299 if (iocb->vport != vport)
4302 if (pring->ringno == LPFC_ELS_RING) {
4303 switch (icmd->ulpCommand) {
4304 case CMD_GEN_REQUEST64_CR:
4305 if (iocb->context_un.ndlp == ndlp)
4307 case CMD_ELS_REQUEST64_CR:
4308 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4310 case CMD_XMIT_ELS_RSP64_CX:
4311 if (iocb->context1 == (uint8_t *) ndlp)
4314 } else if (pring->ringno == psli->extra_ring) {
4316 } else if (pring->ringno == psli->fcp_ring) {
4317 /* Skip match check if waiting to relogin to FCP target */
4318 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4319 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4322 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4325 } else if (pring->ringno == psli->next_ring) {
4332 * Free resources / clean up outstanding I/Os
4333 * associated with nlp_rpi in the LPFC_NODELIST entry.
4336 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
4338 LIST_HEAD(completions);
4339 struct lpfc_sli *psli;
4340 struct lpfc_sli_ring *pring;
4341 struct lpfc_iocbq *iocb, *next_iocb;
4344 lpfc_fabric_abort_nport(ndlp);
4347 * Everything that matches on txcmplq will be returned
4348 * by firmware with a no rpi error.
4351 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4352 /* Now process each ring */
4353 for (i = 0; i < psli->num_rings; i++) {
4354 pring = &psli->ring[i];
4356 spin_lock_irq(&phba->hbalock);
4357 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
4360 * Check to see if iocb matches the nport we are
4363 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
4365 /* It matches, so deque and call compl
4367 list_move_tail(&iocb->list,
4371 spin_unlock_irq(&phba->hbalock);
4375 /* Cancel all the IOCBs from the completions list */
4376 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4383 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4384 * @phba: Pointer to HBA context object.
4385 * @pmb: Pointer to mailbox object.
4387 * This function will issue an ELS LOGO command after completing
4391 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4393 struct lpfc_vport *vport = pmb->vport;
4394 struct lpfc_nodelist *ndlp;
4396 ndlp = (struct lpfc_nodelist *)(pmb->context1);
4399 lpfc_issue_els_logo(vport, ndlp, 0);
4403 * Free rpi associated with LPFC_NODELIST entry.
4404 * This routine is called from lpfc_freenode(), when we are removing
4405 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4406 * LOGO that completes successfully, and we are waiting to PLOGI back
4407 * to the remote NPort. In addition, it is called after we receive
4408 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4409 * we are waiting to PLOGI back to the remote NPort.
4412 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4414 struct lpfc_hba *phba = vport->phba;
4419 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4420 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4422 /* SLI4 ports require the physical rpi value. */
4423 rpi = ndlp->nlp_rpi;
4424 if (phba->sli_rev == LPFC_SLI_REV4)
4425 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4427 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
4428 mbox->vport = vport;
4429 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4430 mbox->context1 = ndlp;
4431 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4433 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4436 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4437 if (rc == MBX_NOT_FINISHED)
4438 mempool_free(mbox, phba->mbox_mem_pool);
4440 lpfc_no_rpi(phba, ndlp);
4442 if (phba->sli_rev != LPFC_SLI_REV4)
4444 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
4445 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4452 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4453 * @phba: pointer to lpfc hba data structure.
4455 * This routine is invoked to unregister all the currently registered RPIs
4459 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4461 struct lpfc_vport **vports;
4462 struct lpfc_nodelist *ndlp;
4463 struct Scsi_Host *shost;
4466 vports = lpfc_create_vport_work_array(phba);
4468 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4469 "2884 Vport array allocation failed \n");
4472 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4473 shost = lpfc_shost_from_vport(vports[i]);
4474 spin_lock_irq(shost->host_lock);
4475 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
4476 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4477 /* The mempool_alloc might sleep */
4478 spin_unlock_irq(shost->host_lock);
4479 lpfc_unreg_rpi(vports[i], ndlp);
4480 spin_lock_irq(shost->host_lock);
4483 spin_unlock_irq(shost->host_lock);
4485 lpfc_destroy_vport_work_array(phba, vports);
4489 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4491 struct lpfc_hba *phba = vport->phba;
4495 if (phba->sli_rev == LPFC_SLI_REV4) {
4496 lpfc_sli4_unreg_all_rpis(vport);
4500 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4502 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
4504 mbox->vport = vport;
4505 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4506 mbox->context1 = NULL;
4507 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4508 if (rc != MBX_TIMEOUT)
4509 mempool_free(mbox, phba->mbox_mem_pool);
4511 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4512 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4513 "1836 Could not issue "
4514 "unreg_login(all_rpis) status %d\n", rc);
4519 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4521 struct lpfc_hba *phba = vport->phba;
4525 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4527 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
4529 mbox->vport = vport;
4530 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4531 mbox->context1 = NULL;
4532 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4533 if (rc != MBX_TIMEOUT)
4534 mempool_free(mbox, phba->mbox_mem_pool);
4536 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4537 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4538 "1815 Could not issue "
4539 "unreg_did (default rpis) status %d\n",
4545 * Free resources associated with LPFC_NODELIST entry
4546 * so it can be freed.
4549 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4551 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4552 struct lpfc_hba *phba = vport->phba;
4553 LPFC_MBOXQ_t *mb, *nextmb;
4554 struct lpfc_dmabuf *mp;
4556 /* Cleanup node for NPort <nlp_DID> */
4557 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4558 "0900 Cleanup node for NPort x%x "
4559 "Data: x%x x%x x%x\n",
4560 ndlp->nlp_DID, ndlp->nlp_flag,
4561 ndlp->nlp_state, ndlp->nlp_rpi);
4562 if (NLP_CHK_FREE_REQ(ndlp)) {
4563 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4564 "0280 lpfc_cleanup_node: ndlp:x%p "
4565 "usgmap:x%x refcnt:%d\n",
4566 (void *)ndlp, ndlp->nlp_usg_map,
4567 atomic_read(&ndlp->kref.refcount));
4568 lpfc_dequeue_node(vport, ndlp);
4570 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4571 "0281 lpfc_cleanup_node: ndlp:x%p "
4572 "usgmap:x%x refcnt:%d\n",
4573 (void *)ndlp, ndlp->nlp_usg_map,
4574 atomic_read(&ndlp->kref.refcount));
4575 lpfc_disable_node(vport, ndlp);
4579 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
4581 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4582 if ((mb = phba->sli.mbox_active)) {
4583 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4584 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
4585 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4586 mb->context2 = NULL;
4587 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4591 spin_lock_irq(&phba->hbalock);
4592 /* Cleanup REG_LOGIN completions which are not yet processed */
4593 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4594 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
4595 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
4596 (ndlp != (struct lpfc_nodelist *) mb->context2))
4599 mb->context2 = NULL;
4600 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4603 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
4604 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4605 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
4606 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4607 mp = (struct lpfc_dmabuf *) (mb->context1);
4609 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
4612 list_del(&mb->list);
4613 mempool_free(mb, phba->mbox_mem_pool);
4614 /* We shall not invoke the lpfc_nlp_put to decrement
4615 * the ndlp reference count as we are in the process
4616 * of lpfc_nlp_release.
4620 spin_unlock_irq(&phba->hbalock);
4622 lpfc_els_abort(phba, ndlp);
4624 spin_lock_irq(shost->host_lock);
4625 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
4626 spin_unlock_irq(shost->host_lock);
4628 ndlp->nlp_last_elscmd = 0;
4629 del_timer_sync(&ndlp->nlp_delayfunc);
4631 list_del_init(&ndlp->els_retry_evt.evt_listp);
4632 list_del_init(&ndlp->dev_loss_evt.evt_listp);
4633 lpfc_cleanup_vports_rrqs(vport, ndlp);
4634 lpfc_unreg_rpi(vport, ndlp);
4640 * Check to see if we can free the nlp back to the freelist.
4641 * If we are in the middle of using the nlp in the discovery state
4642 * machine, defer the free till we reach the end of the state machine.
4645 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4647 struct lpfc_hba *phba = vport->phba;
4648 struct lpfc_rport_data *rdata;
4652 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4653 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
4654 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
4655 !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
4656 /* For this case we need to cleanup the default rpi
4657 * allocated by the firmware.
4659 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4661 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
4662 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
4664 mempool_free(mbox, phba->mbox_mem_pool);
4667 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4668 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4669 mbox->vport = vport;
4670 mbox->context2 = ndlp;
4671 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4672 if (rc == MBX_NOT_FINISHED) {
4673 mempool_free(mbox, phba->mbox_mem_pool);
4678 lpfc_cleanup_node(vport, ndlp);
4681 * We can get here with a non-NULL ndlp->rport because when we
4682 * unregister a rport we don't break the rport/node linkage. So if we
4683 * do, make sure we don't leaving any dangling pointers behind.
4686 rdata = ndlp->rport->dd_data;
4687 rdata->pnode = NULL;
4693 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4696 D_ID mydid, ndlpdid, matchdid;
4698 if (did == Bcast_DID)
4701 /* First check for Direct match */
4702 if (ndlp->nlp_DID == did)
4705 /* Next check for area/domain identically equals 0 match */
4706 mydid.un.word = vport->fc_myDID;
4707 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
4711 matchdid.un.word = did;
4712 ndlpdid.un.word = ndlp->nlp_DID;
4713 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4714 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4715 (mydid.un.b.area == matchdid.un.b.area)) {
4716 if ((ndlpdid.un.b.domain == 0) &&
4717 (ndlpdid.un.b.area == 0)) {
4718 if (ndlpdid.un.b.id)
4724 matchdid.un.word = ndlp->nlp_DID;
4725 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4726 (mydid.un.b.area == ndlpdid.un.b.area)) {
4727 if ((matchdid.un.b.domain == 0) &&
4728 (matchdid.un.b.area == 0)) {
4729 if (matchdid.un.b.id)
4737 /* Search for a nodelist entry */
4738 static struct lpfc_nodelist *
4739 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4741 struct lpfc_nodelist *ndlp;
4744 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4745 if (lpfc_matchdid(vport, ndlp, did)) {
4746 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4747 ((uint32_t) ndlp->nlp_xri << 16) |
4748 ((uint32_t) ndlp->nlp_type << 8) |
4749 ((uint32_t) ndlp->nlp_rpi & 0xff));
4750 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4751 "0929 FIND node DID "
4752 "Data: x%p x%x x%x x%x\n",
4753 ndlp, ndlp->nlp_DID,
4754 ndlp->nlp_flag, data1);
4759 /* FIND node did <did> NOT FOUND */
4760 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4761 "0932 FIND node did x%x NOT FOUND.\n", did);
4765 struct lpfc_nodelist *
4766 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4768 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4769 struct lpfc_nodelist *ndlp;
4770 unsigned long iflags;
4772 spin_lock_irqsave(shost->host_lock, iflags);
4773 ndlp = __lpfc_findnode_did(vport, did);
4774 spin_unlock_irqrestore(shost->host_lock, iflags);
4778 struct lpfc_nodelist *
4779 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
4781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4782 struct lpfc_nodelist *ndlp;
4784 ndlp = lpfc_findnode_did(vport, did);
4786 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4787 lpfc_rscn_payload_check(vport, did) == 0)
4789 ndlp = (struct lpfc_nodelist *)
4790 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
4793 lpfc_nlp_init(vport, ndlp, did);
4794 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4795 spin_lock_irq(shost->host_lock);
4796 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4797 spin_unlock_irq(shost->host_lock);
4799 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4800 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4803 spin_lock_irq(shost->host_lock);
4804 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4805 spin_unlock_irq(shost->host_lock);
4809 if ((vport->fc_flag & FC_RSCN_MODE) &&
4810 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
4811 if (lpfc_rscn_payload_check(vport, did)) {
4812 /* If we've already received a PLOGI from this NPort
4813 * we don't need to try to discover it again.
4815 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
4818 /* Since this node is marked for discovery,
4819 * delay timeout is not needed.
4821 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4822 spin_lock_irq(shost->host_lock);
4823 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4824 spin_unlock_irq(shost->host_lock);
4828 /* If we've already received a PLOGI from this NPort,
4829 * or we are already in the process of discovery on it,
4830 * we don't need to try to discover it again.
4832 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
4833 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4834 ndlp->nlp_flag & NLP_RCV_PLOGI)
4836 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4837 spin_lock_irq(shost->host_lock);
4838 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4839 spin_unlock_irq(shost->host_lock);
4844 /* Build a list of nodes to discover based on the loopmap */
4846 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
4848 struct lpfc_hba *phba = vport->phba;
4850 uint32_t alpa, index;
4852 if (!lpfc_is_link_up(phba))
4855 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
4858 /* Check for loop map present or not */
4859 if (phba->alpa_map[0]) {
4860 for (j = 1; j <= phba->alpa_map[0]; j++) {
4861 alpa = phba->alpa_map[j];
4862 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
4864 lpfc_setup_disc_node(vport, alpa);
4867 /* No alpamap, so try all alpa's */
4868 for (j = 0; j < FC_MAXLOOP; j++) {
4869 /* If cfg_scan_down is set, start from highest
4870 * ALPA (0xef) to lowest (0x1).
4872 if (vport->cfg_scan_down)
4875 index = FC_MAXLOOP - j - 1;
4876 alpa = lpfcAlpaArray[index];
4877 if ((vport->fc_myDID & 0xff) == alpa)
4879 lpfc_setup_disc_node(vport, alpa);
4886 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
4889 struct lpfc_sli *psli = &phba->sli;
4890 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
4891 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
4892 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
4896 * if it's not a physical port or if we already send
4897 * clear_la then don't send it.
4899 if ((phba->link_state >= LPFC_CLEAR_LA) ||
4900 (vport->port_type != LPFC_PHYSICAL_PORT) ||
4901 (phba->sli_rev == LPFC_SLI_REV4))
4904 /* Link up discovery */
4905 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
4906 phba->link_state = LPFC_CLEAR_LA;
4907 lpfc_clear_la(phba, mbox);
4908 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
4909 mbox->vport = vport;
4910 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4911 if (rc == MBX_NOT_FINISHED) {
4912 mempool_free(mbox, phba->mbox_mem_pool);
4913 lpfc_disc_flush_list(vport);
4914 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4915 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4916 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4917 phba->link_state = LPFC_HBA_ERROR;
4922 /* Reg_vpi to tell firmware to resume normal operations */
4924 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4926 LPFC_MBOXQ_t *regvpimbox;
4928 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4930 lpfc_reg_vpi(vport, regvpimbox);
4931 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
4932 regvpimbox->vport = vport;
4933 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
4934 == MBX_NOT_FINISHED) {
4935 mempool_free(regvpimbox, phba->mbox_mem_pool);
4940 /* Start Link up / RSCN discovery on NPR nodes */
4942 lpfc_disc_start(struct lpfc_vport *vport)
4944 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4945 struct lpfc_hba *phba = vport->phba;
4947 uint32_t clear_la_pending;
4950 if (!lpfc_is_link_up(phba))
4953 if (phba->link_state == LPFC_CLEAR_LA)
4954 clear_la_pending = 1;
4956 clear_la_pending = 0;
4958 if (vport->port_state < LPFC_VPORT_READY)
4959 vport->port_state = LPFC_DISC_AUTH;
4961 lpfc_set_disctmo(vport);
4963 if (vport->fc_prevDID == vport->fc_myDID)
4968 vport->fc_prevDID = vport->fc_myDID;
4969 vport->num_disc_nodes = 0;
4971 /* Start Discovery state <hba_state> */
4972 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4973 "0202 Start Discovery hba state x%x "
4974 "Data: x%x x%x x%x\n",
4975 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
4976 vport->fc_adisc_cnt);
4978 /* First do ADISCs - if any */
4979 num_sent = lpfc_els_disc_adisc(vport);
4984 /* Register the VPI for SLI3, NON-NPIV only. */
4985 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4986 !(vport->fc_flag & FC_PT2PT) &&
4987 !(vport->fc_flag & FC_RSCN_MODE) &&
4988 (phba->sli_rev < LPFC_SLI_REV4)) {
4989 lpfc_issue_reg_vpi(phba, vport);
4994 * For SLI2, we need to set port_state to READY and continue
4997 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
4998 /* If we get here, there is nothing to ADISC */
4999 if (vport->port_type == LPFC_PHYSICAL_PORT)
5000 lpfc_issue_clear_la(phba, vport);
5002 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5003 vport->num_disc_nodes = 0;
5004 /* go thru NPR nodes and issue ELS PLOGIs */
5005 if (vport->fc_npr_cnt)
5006 lpfc_els_disc_plogi(vport);
5008 if (!vport->num_disc_nodes) {
5009 spin_lock_irq(shost->host_lock);
5010 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5011 spin_unlock_irq(shost->host_lock);
5012 lpfc_can_disctmo(vport);
5015 vport->port_state = LPFC_VPORT_READY;
5017 /* Next do PLOGIs - if any */
5018 num_sent = lpfc_els_disc_plogi(vport);
5023 if (vport->fc_flag & FC_RSCN_MODE) {
5024 /* Check to see if more RSCNs came in while we
5025 * were processing this one.
5027 if ((vport->fc_rscn_id_cnt == 0) &&
5028 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5029 spin_lock_irq(shost->host_lock);
5030 vport->fc_flag &= ~FC_RSCN_MODE;
5031 spin_unlock_irq(shost->host_lock);
5032 lpfc_can_disctmo(vport);
5034 lpfc_els_handle_rscn(vport);
5041 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5042 * ring the match the sppecified nodelist.
5045 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5047 LIST_HEAD(completions);
5048 struct lpfc_sli *psli;
5050 struct lpfc_iocbq *iocb, *next_iocb;
5051 struct lpfc_sli_ring *pring;
5054 pring = &psli->ring[LPFC_ELS_RING];
5056 /* Error matching iocb on txq or txcmplq
5057 * First check the txq.
5059 spin_lock_irq(&phba->hbalock);
5060 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5061 if (iocb->context1 != ndlp) {
5065 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5066 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5068 list_move_tail(&iocb->list, &completions);
5072 /* Next check the txcmplq */
5073 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5074 if (iocb->context1 != ndlp) {
5078 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5079 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5080 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
5083 spin_unlock_irq(&phba->hbalock);
5085 /* Cancel all the IOCBs from the completions list */
5086 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5091 lpfc_disc_flush_list(struct lpfc_vport *vport)
5093 struct lpfc_nodelist *ndlp, *next_ndlp;
5094 struct lpfc_hba *phba = vport->phba;
5096 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5097 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5099 if (!NLP_CHK_NODE_ACT(ndlp))
5101 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5102 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5103 lpfc_free_tx(phba, ndlp);
5110 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5112 lpfc_els_flush_rscn(vport);
5113 lpfc_els_flush_cmd(vport);
5114 lpfc_disc_flush_list(vport);
5117 /*****************************************************************************/
5119 * NAME: lpfc_disc_timeout
5121 * FUNCTION: Fibre Channel driver discovery timeout routine.
5123 * EXECUTION ENVIRONMENT: interrupt only
5131 /*****************************************************************************/
5133 lpfc_disc_timeout(unsigned long ptr)
5135 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5136 struct lpfc_hba *phba = vport->phba;
5137 uint32_t tmo_posted;
5138 unsigned long flags = 0;
5140 if (unlikely(!phba))
5143 spin_lock_irqsave(&vport->work_port_lock, flags);
5144 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5146 vport->work_port_events |= WORKER_DISC_TMO;
5147 spin_unlock_irqrestore(&vport->work_port_lock, flags);
5150 lpfc_worker_wake_up(phba);
5155 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
5157 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5158 struct lpfc_hba *phba = vport->phba;
5159 struct lpfc_sli *psli = &phba->sli;
5160 struct lpfc_nodelist *ndlp, *next_ndlp;
5161 LPFC_MBOXQ_t *initlinkmbox;
5162 int rc, clrlaerr = 0;
5164 if (!(vport->fc_flag & FC_DISC_TMO))
5167 spin_lock_irq(shost->host_lock);
5168 vport->fc_flag &= ~FC_DISC_TMO;
5169 spin_unlock_irq(shost->host_lock);
5171 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5172 "disc timeout: state:x%x rtry:x%x flg:x%x",
5173 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5175 switch (vport->port_state) {
5177 case LPFC_LOCAL_CFG_LINK:
5178 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
5182 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5183 "0221 FAN timeout\n");
5184 /* Start discovery by sending FLOGI, clean up old rpis */
5185 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5187 if (!NLP_CHK_NODE_ACT(ndlp))
5189 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5191 if (ndlp->nlp_type & NLP_FABRIC) {
5192 /* Clean up the ndlp on Fabric connections */
5193 lpfc_drop_node(vport, ndlp);
5195 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
5196 /* Fail outstanding IO now since device
5197 * is marked for PLOGI.
5199 lpfc_unreg_rpi(vport, ndlp);
5202 if (vport->port_state != LPFC_FLOGI) {
5203 if (phba->sli_rev <= LPFC_SLI_REV3)
5204 lpfc_initial_flogi(vport);
5206 lpfc_issue_init_vfi(vport);
5213 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5214 /* Initial FLOGI timeout */
5215 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5216 "0222 Initial %s timeout\n",
5217 vport->vpi ? "FDISC" : "FLOGI");
5219 /* Assume no Fabric and go on with discovery.
5220 * Check for outstanding ELS FLOGI to abort.
5223 /* FLOGI failed, so just use loop map to make discovery list */
5224 lpfc_disc_list_loopmap(vport);
5226 /* Start discovery */
5227 lpfc_disc_start(vport);
5230 case LPFC_FABRIC_CFG_LINK:
5231 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5233 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5234 "0223 Timeout while waiting for "
5235 "NameServer login\n");
5236 /* Next look for NameServer ndlp */
5237 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5238 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5239 lpfc_els_abort(phba, ndlp);
5241 /* ReStart discovery */
5245 /* Check for wait for NameServer Rsp timeout */
5246 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5247 "0224 NameServer Query timeout "
5249 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5251 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5252 /* Try it one more time */
5253 vport->fc_ns_retry++;
5254 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
5255 vport->fc_ns_retry, 0);
5259 vport->fc_ns_retry = 0;
5263 * Discovery is over.
5264 * set port_state to PORT_READY if SLI2.
5265 * cmpl_reg_vpi will set port_state to READY for SLI3.
5267 if (phba->sli_rev < LPFC_SLI_REV4) {
5268 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5269 lpfc_issue_reg_vpi(phba, vport);
5271 lpfc_issue_clear_la(phba, vport);
5272 vport->port_state = LPFC_VPORT_READY;
5276 /* Setup and issue mailbox INITIALIZE LINK command */
5277 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5278 if (!initlinkmbox) {
5279 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5280 "0206 Device Discovery "
5281 "completion error\n");
5282 phba->link_state = LPFC_HBA_ERROR;
5286 lpfc_linkdown(phba);
5287 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5288 phba->cfg_link_speed);
5289 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5290 initlinkmbox->vport = vport;
5291 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5292 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
5293 lpfc_set_loopback_flag(phba);
5294 if (rc == MBX_NOT_FINISHED)
5295 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5299 case LPFC_DISC_AUTH:
5300 /* Node Authentication timeout */
5301 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5302 "0227 Node Authentication timeout\n");
5303 lpfc_disc_flush_list(vport);
5306 * set port_state to PORT_READY if SLI2.
5307 * cmpl_reg_vpi will set port_state to READY for SLI3.
5309 if (phba->sli_rev < LPFC_SLI_REV4) {
5310 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5311 lpfc_issue_reg_vpi(phba, vport);
5312 else { /* NPIV Not enabled */
5313 lpfc_issue_clear_la(phba, vport);
5314 vport->port_state = LPFC_VPORT_READY;
5319 case LPFC_VPORT_READY:
5320 if (vport->fc_flag & FC_RSCN_MODE) {
5321 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5322 "0231 RSCN timeout Data: x%x "
5324 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5326 /* Cleanup any outstanding ELS commands */
5327 lpfc_els_flush_cmd(vport);
5329 lpfc_els_flush_rscn(vport);
5330 lpfc_disc_flush_list(vport);
5335 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5336 "0273 Unexpected discovery timeout, "
5337 "vport State x%x\n", vport->port_state);
5341 switch (phba->link_state) {
5343 /* CLEAR LA timeout */
5344 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5345 "0228 CLEAR LA timeout\n");
5350 lpfc_issue_clear_la(phba, vport);
5352 case LPFC_LINK_UNKNOWN:
5353 case LPFC_WARM_START:
5354 case LPFC_INIT_START:
5355 case LPFC_INIT_MBX_CMDS:
5356 case LPFC_LINK_DOWN:
5357 case LPFC_HBA_ERROR:
5358 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5359 "0230 Unexpected timeout, hba link "
5360 "state x%x\n", phba->link_state);
5364 case LPFC_HBA_READY:
5369 lpfc_disc_flush_list(vport);
5370 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5371 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5372 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5373 vport->port_state = LPFC_VPORT_READY;
5380 * This routine handles processing a NameServer REG_LOGIN mailbox
5381 * command upon completion. It is setup in the LPFC_MBOXQ
5382 * as the completion routine when the command is
5383 * handed off to the SLI layer.
5386 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5388 MAILBOX_t *mb = &pmb->u.mb;
5389 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
5390 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5391 struct lpfc_vport *vport = pmb->vport;
5393 pmb->context1 = NULL;
5394 pmb->context2 = NULL;
5396 if (phba->sli_rev < LPFC_SLI_REV4)
5397 ndlp->nlp_rpi = mb->un.varWords[0];
5398 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
5399 ndlp->nlp_type |= NLP_FABRIC;
5400 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
5403 * Start issuing Fabric-Device Management Interface (FDMI) command to
5404 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
5405 * fdmi-on=2 (supporting RPA/hostnmae)
5408 if (vport->cfg_fdmi_on == 1)
5409 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
5411 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
5413 /* decrement the node reference count held for this callback
5417 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5419 mempool_free(pmb, phba->mbox_mem_pool);
5425 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5427 uint16_t *rpi = param;
5429 /* check for active node */
5430 if (!NLP_CHK_NODE_ACT(ndlp))
5433 return ndlp->nlp_rpi == *rpi;
5437 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5439 return memcmp(&ndlp->nlp_portname, param,
5440 sizeof(ndlp->nlp_portname)) == 0;
5443 static struct lpfc_nodelist *
5444 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
5446 struct lpfc_nodelist *ndlp;
5448 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5449 if (filter(ndlp, param)) {
5450 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5451 "3185 FIND node filter %p DID "
5452 "Data: x%p x%x x%x\n",
5453 filter, ndlp, ndlp->nlp_DID,
5458 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5459 "3186 FIND node filter %p NOT FOUND.\n", filter);
5464 * This routine looks up the ndlp lists for the given RPI. If rpi found it
5465 * returns the node list element pointer else return NULL.
5467 struct lpfc_nodelist *
5468 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5470 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
5474 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
5475 * returns the node element list pointer else return NULL.
5477 struct lpfc_nodelist *
5478 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
5480 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5481 struct lpfc_nodelist *ndlp;
5483 spin_lock_irq(shost->host_lock);
5484 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5485 spin_unlock_irq(shost->host_lock);
5490 * This routine looks up the ndlp lists for the given RPI. If the rpi
5491 * is found, the routine returns the node element list pointer else
5494 struct lpfc_nodelist *
5495 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5498 struct lpfc_nodelist *ndlp;
5500 spin_lock_irq(shost->host_lock);
5501 ndlp = __lpfc_findnode_rpi(vport, rpi);
5502 spin_unlock_irq(shost->host_lock);
5507 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5508 * @phba: pointer to lpfc hba data structure.
5509 * @vpi: the physical host virtual N_Port identifier.
5511 * This routine finds a vport on a HBA (referred by @phba) through a
5512 * @vpi. The function walks the HBA's vport list and returns the address
5513 * of the vport with the matching @vpi.
5516 * NULL - No vport with the matching @vpi found
5517 * Otherwise - Address to the vport with the matching @vpi.
5520 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5522 struct lpfc_vport *vport;
5523 unsigned long flags;
5526 /* The physical ports are always vpi 0 - translate is unnecessary. */
5529 * Translate the physical vpi to the logical vpi. The
5530 * vport stores the logical vpi.
5532 for (i = 0; i < phba->max_vpi; i++) {
5533 if (vpi == phba->vpi_ids[i])
5537 if (i >= phba->max_vpi) {
5538 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5539 "2936 Could not find Vport mapped "
5540 "to vpi %d\n", vpi);
5545 spin_lock_irqsave(&phba->hbalock, flags);
5546 list_for_each_entry(vport, &phba->port_list, listentry) {
5547 if (vport->vpi == i) {
5548 spin_unlock_irqrestore(&phba->hbalock, flags);
5552 spin_unlock_irqrestore(&phba->hbalock, flags);
5557 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5560 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
5562 lpfc_initialize_node(vport, ndlp, did);
5563 INIT_LIST_HEAD(&ndlp->nlp_listp);
5565 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5566 "node init: did:x%x",
5567 ndlp->nlp_DID, 0, 0);
5572 /* This routine releases all resources associated with a specifc NPort's ndlp
5573 * and mempool_free's the nodelist.
5576 lpfc_nlp_release(struct kref *kref)
5578 struct lpfc_hba *phba;
5579 unsigned long flags;
5580 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5583 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5584 "node release: did:x%x flg:x%x type:x%x",
5585 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5587 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5588 "0279 lpfc_nlp_release: ndlp:x%p did %x "
5589 "usgmap:x%x refcnt:%d\n",
5590 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
5591 atomic_read(&ndlp->kref.refcount));
5593 /* remove ndlp from action. */
5594 lpfc_nlp_remove(ndlp->vport, ndlp);
5596 /* clear the ndlp active flag for all release cases */
5598 spin_lock_irqsave(&phba->ndlp_lock, flags);
5599 NLP_CLR_NODE_ACT(ndlp);
5600 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5601 if (phba->sli_rev == LPFC_SLI_REV4)
5602 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
5604 /* free ndlp memory for final ndlp release */
5605 if (NLP_CHK_FREE_REQ(ndlp)) {
5606 kfree(ndlp->lat_data);
5607 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
5611 /* This routine bumps the reference count for a ndlp structure to ensure
5612 * that one discovery thread won't free a ndlp while another discovery thread
5615 struct lpfc_nodelist *
5616 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5618 struct lpfc_hba *phba;
5619 unsigned long flags;
5622 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5623 "node get: did:x%x flg:x%x refcnt:x%x",
5624 ndlp->nlp_DID, ndlp->nlp_flag,
5625 atomic_read(&ndlp->kref.refcount));
5626 /* The check of ndlp usage to prevent incrementing the
5627 * ndlp reference count that is in the process of being
5631 spin_lock_irqsave(&phba->ndlp_lock, flags);
5632 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5633 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5634 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5635 "0276 lpfc_nlp_get: ndlp:x%p "
5636 "usgmap:x%x refcnt:%d\n",
5637 (void *)ndlp, ndlp->nlp_usg_map,
5638 atomic_read(&ndlp->kref.refcount));
5641 kref_get(&ndlp->kref);
5642 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5647 /* This routine decrements the reference count for a ndlp structure. If the
5648 * count goes to 0, this indicates the the associated nodelist should be
5649 * freed. Returning 1 indicates the ndlp resource has been released; on the
5650 * other hand, returning 0 indicates the ndlp resource has not been released
5654 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
5656 struct lpfc_hba *phba;
5657 unsigned long flags;
5662 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5663 "node put: did:x%x flg:x%x refcnt:x%x",
5664 ndlp->nlp_DID, ndlp->nlp_flag,
5665 atomic_read(&ndlp->kref.refcount));
5667 spin_lock_irqsave(&phba->ndlp_lock, flags);
5668 /* Check the ndlp memory free acknowledge flag to avoid the
5669 * possible race condition that kref_put got invoked again
5670 * after previous one has done ndlp memory free.
5672 if (NLP_CHK_FREE_ACK(ndlp)) {
5673 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5674 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5675 "0274 lpfc_nlp_put: ndlp:x%p "
5676 "usgmap:x%x refcnt:%d\n",
5677 (void *)ndlp, ndlp->nlp_usg_map,
5678 atomic_read(&ndlp->kref.refcount));
5681 /* Check the ndlp inactivate log flag to avoid the possible
5682 * race condition that kref_put got invoked again after ndlp
5683 * is already in inactivating state.
5685 if (NLP_CHK_IACT_REQ(ndlp)) {
5686 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5687 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5688 "0275 lpfc_nlp_put: ndlp:x%p "
5689 "usgmap:x%x refcnt:%d\n",
5690 (void *)ndlp, ndlp->nlp_usg_map,
5691 atomic_read(&ndlp->kref.refcount));
5694 /* For last put, mark the ndlp usage flags to make sure no
5695 * other kref_get and kref_put on the same ndlp shall get
5696 * in between the process when the final kref_put has been
5697 * invoked on this ndlp.
5699 if (atomic_read(&ndlp->kref.refcount) == 1) {
5700 /* Indicate ndlp is put to inactive state. */
5701 NLP_SET_IACT_REQ(ndlp);
5702 /* Acknowledge ndlp memory free has been seen. */
5703 if (NLP_CHK_FREE_REQ(ndlp))
5704 NLP_SET_FREE_ACK(ndlp);
5706 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5707 /* Note, the kref_put returns 1 when decrementing a reference
5708 * count that was 1, it invokes the release callback function,
5709 * but it still left the reference count as 1 (not actually
5710 * performs the last decrementation). Otherwise, it actually
5711 * decrements the reference count and returns 0.
5713 return kref_put(&ndlp->kref, lpfc_nlp_release);
5716 /* This routine free's the specified nodelist if it is not in use
5717 * by any other discovery thread. This routine returns 1 if the
5718 * ndlp has been freed. A return value of 0 indicates the ndlp is
5719 * not yet been released.
5722 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5724 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5725 "node not used: did:x%x flg:x%x refcnt:x%x",
5726 ndlp->nlp_DID, ndlp->nlp_flag,
5727 atomic_read(&ndlp->kref.refcount));
5728 if (atomic_read(&ndlp->kref.refcount) == 1)
5729 if (lpfc_nlp_put(ndlp))
5735 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5736 * @phba: Pointer to hba context object.
5738 * This function iterate through all FC nodes associated
5739 * will all vports to check if there is any node with
5740 * fc_rports associated with it. If there is an fc_rport
5741 * associated with the node, then the node is either in
5742 * discovered state or its devloss_timer is pending.
5745 lpfc_fcf_inuse(struct lpfc_hba *phba)
5747 struct lpfc_vport **vports;
5749 struct lpfc_nodelist *ndlp;
5750 struct Scsi_Host *shost;
5752 vports = lpfc_create_vport_work_array(phba);
5754 /* If driver cannot allocate memory, indicate fcf is in use */
5758 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5759 shost = lpfc_shost_from_vport(vports[i]);
5760 spin_lock_irq(shost->host_lock);
5762 * IF the CVL_RCVD bit is not set then we have sent the
5764 * If dev_loss fires while we are waiting we do not want to
5767 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
5768 spin_unlock_irq(shost->host_lock);
5772 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5773 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5774 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5776 spin_unlock_irq(shost->host_lock);
5778 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5780 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5781 "2624 RPI %x DID %x flag %x "
5782 "still logged in\n",
5783 ndlp->nlp_rpi, ndlp->nlp_DID,
5787 spin_unlock_irq(shost->host_lock);
5790 lpfc_destroy_vport_work_array(phba, vports);
5795 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5796 * @phba: Pointer to hba context object.
5797 * @mboxq: Pointer to mailbox object.
5799 * This function frees memory associated with the mailbox command.
5802 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5804 struct lpfc_vport *vport = mboxq->vport;
5805 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5807 if (mboxq->u.mb.mbxStatus) {
5808 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5809 "2555 UNREG_VFI mbxStatus error x%x "
5811 mboxq->u.mb.mbxStatus, vport->port_state);
5813 spin_lock_irq(shost->host_lock);
5814 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5815 spin_unlock_irq(shost->host_lock);
5816 mempool_free(mboxq, phba->mbox_mem_pool);
5821 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5822 * @phba: Pointer to hba context object.
5823 * @mboxq: Pointer to mailbox object.
5825 * This function frees memory associated with the mailbox command.
5828 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5830 struct lpfc_vport *vport = mboxq->vport;
5832 if (mboxq->u.mb.mbxStatus) {
5833 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5834 "2550 UNREG_FCFI mbxStatus error x%x "
5836 mboxq->u.mb.mbxStatus, vport->port_state);
5838 mempool_free(mboxq, phba->mbox_mem_pool);
5843 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
5844 * @phba: Pointer to hba context object.
5846 * This function prepare the HBA for unregistering the currently registered
5847 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
5851 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
5853 struct lpfc_vport **vports;
5854 struct lpfc_nodelist *ndlp;
5855 struct Scsi_Host *shost;
5858 /* Unregister RPIs */
5859 if (lpfc_fcf_inuse(phba))
5860 lpfc_unreg_hba_rpis(phba);
5862 /* At this point, all discovery is aborted */
5863 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5865 /* Unregister VPIs */
5866 vports = lpfc_create_vport_work_array(phba);
5867 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
5868 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5869 /* Stop FLOGI/FDISC retries */
5870 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
5872 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
5873 lpfc_cleanup_pending_mbox(vports[i]);
5874 if (phba->sli_rev == LPFC_SLI_REV4)
5875 lpfc_sli4_unreg_all_rpis(vports[i]);
5876 lpfc_mbx_unreg_vpi(vports[i]);
5877 shost = lpfc_shost_from_vport(vports[i]);
5878 spin_lock_irq(shost->host_lock);
5879 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
5880 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
5881 spin_unlock_irq(shost->host_lock);
5883 lpfc_destroy_vport_work_array(phba, vports);
5885 /* Cleanup any outstanding ELS commands */
5886 lpfc_els_flush_all_cmd(phba);
5888 /* Unregister the physical port VFI */
5889 rc = lpfc_issue_unreg_vfi(phba->pport);
5894 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
5895 * @phba: Pointer to hba context object.
5897 * This function issues synchronous unregister FCF mailbox command to HBA to
5898 * unregister the currently registered FCF record. The driver does not reset
5899 * the driver FCF usage state flags.
5901 * Return 0 if successfully issued, none-zero otherwise.
5904 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
5909 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5911 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5912 "2551 UNREG_FCFI mbox allocation failed"
5913 "HBA state x%x\n", phba->pport->port_state);
5916 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
5917 mbox->vport = phba->pport;
5918 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
5919 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5921 if (rc == MBX_NOT_FINISHED) {
5922 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5923 "2552 Unregister FCFI command failed rc x%x "
5925 rc, phba->pport->port_state);
5932 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
5933 * @phba: Pointer to hba context object.
5935 * This function unregisters the currently reigstered FCF. This function
5936 * also tries to find another FCF for discovery by rescan the HBA FCF table.
5939 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
5943 /* Preparation for unregistering fcf */
5944 rc = lpfc_unregister_fcf_prep(phba);
5946 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5947 "2748 Failed to prepare for unregistering "
5948 "HBA's FCF record: rc=%d\n", rc);
5952 /* Now, unregister FCF record and reset HBA FCF state */
5953 rc = lpfc_sli4_unregister_fcf(phba);
5956 /* Reset HBA FCF states after successful unregister FCF */
5957 phba->fcf.fcf_flag = 0;
5958 phba->fcf.current_rec.flag = 0;
5961 * If driver is not unloading, check if there is any other
5962 * FCF record that can be used for discovery.
5964 if ((phba->pport->load_flag & FC_UNLOADING) ||
5965 (phba->link_state < LPFC_LINK_UP))
5968 /* This is considered as the initial FCF discovery scan */
5969 spin_lock_irq(&phba->hbalock);
5970 phba->fcf.fcf_flag |= FCF_INIT_DISC;
5971 spin_unlock_irq(&phba->hbalock);
5973 /* Reset FCF roundrobin bmask for new discovery */
5974 lpfc_sli4_clear_fcf_rr_bmask(phba);
5976 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
5979 spin_lock_irq(&phba->hbalock);
5980 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
5981 spin_unlock_irq(&phba->hbalock);
5982 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5983 "2553 lpfc_unregister_unused_fcf failed "
5984 "to read FCF record HBA state x%x\n",
5985 phba->pport->port_state);
5990 * lpfc_unregister_fcf - Unregister the currently registered fcf record
5991 * @phba: Pointer to hba context object.
5993 * This function just unregisters the currently reigstered FCF. It does not
5994 * try to find another FCF for discovery.
5997 lpfc_unregister_fcf(struct lpfc_hba *phba)
6001 /* Preparation for unregistering fcf */
6002 rc = lpfc_unregister_fcf_prep(phba);
6004 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6005 "2749 Failed to prepare for unregistering "
6006 "HBA's FCF record: rc=%d\n", rc);
6010 /* Now, unregister FCF record and reset HBA FCF state */
6011 rc = lpfc_sli4_unregister_fcf(phba);
6014 /* Set proper HBA FCF states after successful unregister FCF */
6015 spin_lock_irq(&phba->hbalock);
6016 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6017 spin_unlock_irq(&phba->hbalock);
6021 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6022 * @phba: Pointer to hba context object.
6024 * This function check if there are any connected remote port for the FCF and
6025 * if all the devices are disconnected, this function unregister FCFI.
6026 * This function also tries to use another FCF for discovery.
6029 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6032 * If HBA is not running in FIP mode, if HBA does not support
6033 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6034 * registered, do nothing.
6036 spin_lock_irq(&phba->hbalock);
6037 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6038 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6039 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6040 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6041 (phba->pport->port_state == LPFC_FLOGI)) {
6042 spin_unlock_irq(&phba->hbalock);
6045 spin_unlock_irq(&phba->hbalock);
6047 if (lpfc_fcf_inuse(phba))
6050 lpfc_unregister_fcf_rescan(phba);
6054 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6055 * @phba: Pointer to hba context object.
6056 * @buff: Buffer containing the FCF connection table as in the config
6058 * This function create driver data structure for the FCF connection
6059 * record table read from config region 23.
6062 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6065 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6066 struct lpfc_fcf_conn_hdr *conn_hdr;
6067 struct lpfc_fcf_conn_rec *conn_rec;
6068 uint32_t record_count;
6071 /* Free the current connect table */
6072 list_for_each_entry_safe(conn_entry, next_conn_entry,
6073 &phba->fcf_conn_rec_list, list) {
6074 list_del_init(&conn_entry->list);
6078 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6079 record_count = conn_hdr->length * sizeof(uint32_t)/
6080 sizeof(struct lpfc_fcf_conn_rec);
6082 conn_rec = (struct lpfc_fcf_conn_rec *)
6083 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6085 for (i = 0; i < record_count; i++) {
6086 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6088 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6091 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6092 "2566 Failed to allocate connection"
6097 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6098 sizeof(struct lpfc_fcf_conn_rec));
6099 conn_entry->conn_rec.vlan_tag =
6100 le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
6101 conn_entry->conn_rec.flags =
6102 le16_to_cpu(conn_entry->conn_rec.flags);
6103 list_add_tail(&conn_entry->list,
6104 &phba->fcf_conn_rec_list);
6109 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6110 * @phba: Pointer to hba context object.
6111 * @buff: Buffer containing the FCoE parameter data structure.
6113 * This function update driver data structure with config
6114 * parameters read from config region 23.
6117 lpfc_read_fcoe_param(struct lpfc_hba *phba,
6120 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6121 struct lpfc_fcoe_params *fcoe_param;
6123 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6125 fcoe_param = (struct lpfc_fcoe_params *)
6126 (buff + sizeof(struct lpfc_fip_param_hdr));
6128 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6129 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6132 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6133 phba->valid_vlan = 1;
6134 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6138 phba->fc_map[0] = fcoe_param->fc_map[0];
6139 phba->fc_map[1] = fcoe_param->fc_map[1];
6140 phba->fc_map[2] = fcoe_param->fc_map[2];
6145 * lpfc_get_rec_conf23 - Get a record type in config region data.
6146 * @buff: Buffer containing config region 23 data.
6147 * @size: Size of the data buffer.
6148 * @rec_type: Record type to be searched.
6150 * This function searches config region data to find the beginning
6151 * of the record specified by record_type. If record found, this
6152 * function return pointer to the record else return NULL.
6155 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6157 uint32_t offset = 0, rec_length;
6159 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6160 (size < sizeof(uint32_t)))
6163 rec_length = buff[offset + 1];
6166 * One TLV record has one word header and number of data words
6167 * specified in the rec_length field of the record header.
6169 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6171 if (buff[offset] == rec_type)
6172 return &buff[offset];
6174 if (buff[offset] == LPFC_REGION23_LAST_REC)
6177 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6178 rec_length = buff[offset + 1];
6184 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6185 * @phba: Pointer to lpfc_hba data structure.
6186 * @buff: Buffer containing config region 23 data.
6187 * @size: Size of the data buffer.
6189 * This function parses the FCoE config parameters in config region 23 and
6190 * populate driver data structure with the parameters.
6193 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6197 uint32_t offset = 0, rec_length;
6201 * If data size is less than 2 words signature and version cannot be
6204 if (size < 2*sizeof(uint32_t))
6207 /* Check the region signature first */
6208 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6209 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6210 "2567 Config region 23 has bad signature\n");
6216 /* Check the data structure version */
6217 if (buff[offset] != LPFC_REGION23_VERSION) {
6218 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6219 "2568 Config region 23 has bad version\n");
6224 rec_length = buff[offset + 1];
6226 /* Read FCoE param record */
6227 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6228 size - offset, FCOE_PARAM_TYPE);
6230 lpfc_read_fcoe_param(phba, rec_ptr);
6232 /* Read FCF connection table */
6233 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6234 size - offset, FCOE_CONN_TBL_TYPE);
6236 lpfc_read_fcf_conn_tbl(phba, rec_ptr);