1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2014 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 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
165 spin_lock_irq(&phba->hbalock);
166 /* We need to hold the node by incrementing the reference
167 * count until this queued work is done
169 if (evtp->evt_arg1) {
170 evtp->evt = LPFC_EVT_DEV_LOSS;
171 list_add_tail(&evtp->evt_listp, &phba->work_list);
172 lpfc_worker_wake_up(phba);
174 spin_unlock_irq(&phba->hbalock);
180 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
181 * @ndlp: Pointer to remote node object.
183 * This function is called from the worker thread when devloss timeout timer
184 * expires. For SLI4 host, this routine shall return 1 when at lease one
185 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
186 * routine shall return 0 when there is no remote node is still in use of FCF
187 * when devloss timeout happened to this @ndlp.
190 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
192 struct lpfc_rport_data *rdata;
193 struct fc_rport *rport;
194 struct lpfc_vport *vport;
195 struct lpfc_hba *phba;
207 rdata = rport->dd_data;
208 name = (uint8_t *) &ndlp->nlp_portname;
212 if (phba->sli_rev == LPFC_SLI_REV4)
213 fcf_inuse = lpfc_fcf_inuse(phba);
215 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
216 "rport devlosstmo:did:x%x type:x%x id:x%x",
217 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
219 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
220 "3182 dev_loss_tmo_handler x%06x, rport %p flg x%x\n",
221 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag);
223 /* Don't defer this if we are in the process of deleting the vport
224 * or unloading the driver. The unload will cleanup the node
225 * appropriately we just need to cleanup the ndlp rport info here.
227 if (vport->load_flag & FC_UNLOADING) {
228 if (ndlp->nlp_sid != NLP_NO_SID) {
229 /* flush the target */
230 lpfc_sli_abort_iocb(vport,
231 &phba->sli.ring[phba->sli.fcp_ring],
232 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
234 put_node = rdata->pnode != NULL;
235 put_rport = ndlp->rport != NULL;
241 put_device(&rport->dev);
245 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
246 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
247 "0284 Devloss timeout Ignored on "
248 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
250 *name, *(name+1), *(name+2), *(name+3),
251 *(name+4), *(name+5), *(name+6), *(name+7),
256 if (ndlp->nlp_type & NLP_FABRIC) {
257 /* We will clean up these Nodes in linkup */
258 put_node = rdata->pnode != NULL;
259 put_rport = ndlp->rport != NULL;
265 put_device(&rport->dev);
269 if (ndlp->nlp_sid != NLP_NO_SID) {
271 /* flush the target */
272 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
273 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
277 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
278 "0203 Devloss timeout on "
279 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
280 "NPort x%06x Data: x%x x%x x%x\n",
281 *name, *(name+1), *(name+2), *(name+3),
282 *(name+4), *(name+5), *(name+6), *(name+7),
283 ndlp->nlp_DID, ndlp->nlp_flag,
284 ndlp->nlp_state, ndlp->nlp_rpi);
286 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
287 "0204 Devloss timeout on "
288 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
289 "NPort x%06x Data: x%x x%x x%x\n",
290 *name, *(name+1), *(name+2), *(name+3),
291 *(name+4), *(name+5), *(name+6), *(name+7),
292 ndlp->nlp_DID, ndlp->nlp_flag,
293 ndlp->nlp_state, ndlp->nlp_rpi);
296 put_node = rdata->pnode != NULL;
297 put_rport = ndlp->rport != NULL;
303 put_device(&rport->dev);
305 if (!(vport->load_flag & FC_UNLOADING) &&
306 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
307 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
308 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
309 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
310 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
311 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
317 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
318 * @phba: Pointer to hba context object.
319 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
320 * @nlp_did: remote node identifer with devloss timeout.
322 * This function is called from the worker thread after invoking devloss
323 * timeout handler and releasing the reference count for the ndlp with
324 * which the devloss timeout was handled for SLI4 host. For the devloss
325 * timeout of the last remote node which had been in use of FCF, when this
326 * routine is invoked, it shall be guaranteed that none of the remote are
327 * in-use of FCF. When devloss timeout to the last remote using the FCF,
328 * if the FIP engine is neither in FCF table scan process nor roundrobin
329 * failover process, the in-use FCF shall be unregistered. If the FIP
330 * engine is in FCF discovery process, the devloss timeout state shall
331 * be set for either the FCF table scan process or roundrobin failover
332 * process to unregister the in-use FCF.
335 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
338 /* If devloss timeout happened to a remote node when FCF had no
339 * longer been in-use, do nothing.
344 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
345 spin_lock_irq(&phba->hbalock);
346 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
347 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
348 spin_unlock_irq(&phba->hbalock);
351 phba->hba_flag |= HBA_DEVLOSS_TMO;
352 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
353 "2847 Last remote node (x%x) using "
354 "FCF devloss tmo\n", nlp_did);
356 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
357 spin_unlock_irq(&phba->hbalock);
358 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
359 "2868 Devloss tmo to FCF rediscovery "
363 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
364 spin_unlock_irq(&phba->hbalock);
365 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
366 "2869 Devloss tmo to idle FIP engine, "
367 "unreg in-use FCF and rescan.\n");
368 /* Unregister in-use FCF and rescan */
369 lpfc_unregister_fcf_rescan(phba);
372 spin_unlock_irq(&phba->hbalock);
373 if (phba->hba_flag & FCF_TS_INPROG)
374 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
375 "2870 FCF table scan in progress\n");
376 if (phba->hba_flag & FCF_RR_INPROG)
377 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
378 "2871 FLOGI roundrobin FCF failover "
381 lpfc_unregister_unused_fcf(phba);
385 * lpfc_alloc_fast_evt - Allocates data structure for posting event
386 * @phba: Pointer to hba context object.
388 * This function is called from the functions which need to post
389 * events from interrupt context. This function allocates data
390 * structure required for posting event. It also keeps track of
391 * number of events pending and prevent event storm when there are
394 struct lpfc_fast_path_event *
395 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
396 struct lpfc_fast_path_event *ret;
398 /* If there are lot of fast event do not exhaust memory due to this */
399 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
402 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
405 atomic_inc(&phba->fast_event_count);
406 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
407 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
413 * lpfc_free_fast_evt - Frees event data structure
414 * @phba: Pointer to hba context object.
415 * @evt: Event object which need to be freed.
417 * This function frees the data structure required for posting
421 lpfc_free_fast_evt(struct lpfc_hba *phba,
422 struct lpfc_fast_path_event *evt) {
424 atomic_dec(&phba->fast_event_count);
429 * lpfc_send_fastpath_evt - Posts events generated from fast path
430 * @phba: Pointer to hba context object.
431 * @evtp: Event data structure.
433 * This function is called from worker thread, when the interrupt
434 * context need to post an event. This function posts the event
435 * to fc transport netlink interface.
438 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
439 struct lpfc_work_evt *evtp)
441 unsigned long evt_category, evt_sub_category;
442 struct lpfc_fast_path_event *fast_evt_data;
444 uint32_t evt_data_size;
445 struct Scsi_Host *shost;
447 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
450 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
451 evt_sub_category = (unsigned long) fast_evt_data->un.
452 fabric_evt.subcategory;
453 shost = lpfc_shost_from_vport(fast_evt_data->vport);
454 if (evt_category == FC_REG_FABRIC_EVENT) {
455 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
456 evt_data = (char *) &fast_evt_data->un.read_check_error;
457 evt_data_size = sizeof(fast_evt_data->un.
459 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
460 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
461 evt_data = (char *) &fast_evt_data->un.fabric_evt;
462 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
464 lpfc_free_fast_evt(phba, fast_evt_data);
467 } else if (evt_category == FC_REG_SCSI_EVENT) {
468 switch (evt_sub_category) {
469 case LPFC_EVENT_QFULL:
470 case LPFC_EVENT_DEVBSY:
471 evt_data = (char *) &fast_evt_data->un.scsi_evt;
472 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
474 case LPFC_EVENT_CHECK_COND:
475 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
476 evt_data_size = sizeof(fast_evt_data->un.
479 case LPFC_EVENT_VARQUEDEPTH:
480 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
481 evt_data_size = sizeof(fast_evt_data->un.
485 lpfc_free_fast_evt(phba, fast_evt_data);
489 lpfc_free_fast_evt(phba, fast_evt_data);
493 fc_host_post_vendor_event(shost,
494 fc_get_event_number(),
499 lpfc_free_fast_evt(phba, fast_evt_data);
504 lpfc_work_list_done(struct lpfc_hba *phba)
506 struct lpfc_work_evt *evtp = NULL;
507 struct lpfc_nodelist *ndlp;
512 spin_lock_irq(&phba->hbalock);
513 while (!list_empty(&phba->work_list)) {
514 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
516 spin_unlock_irq(&phba->hbalock);
519 case LPFC_EVT_ELS_RETRY:
520 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
521 lpfc_els_retry_delay_handler(ndlp);
522 free_evt = 0; /* evt is part of ndlp */
523 /* decrement the node reference count held
524 * for this queued work
528 case LPFC_EVT_DEV_LOSS:
529 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
530 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
532 /* decrement the node reference count held for
535 nlp_did = ndlp->nlp_DID;
537 if (phba->sli_rev == LPFC_SLI_REV4)
538 lpfc_sli4_post_dev_loss_tmo_handler(phba,
542 case LPFC_EVT_ONLINE:
543 if (phba->link_state < LPFC_LINK_DOWN)
544 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
546 *(int *) (evtp->evt_arg1) = 0;
547 complete((struct completion *)(evtp->evt_arg2));
549 case LPFC_EVT_OFFLINE_PREP:
550 if (phba->link_state >= LPFC_LINK_DOWN)
551 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
552 *(int *)(evtp->evt_arg1) = 0;
553 complete((struct completion *)(evtp->evt_arg2));
555 case LPFC_EVT_OFFLINE:
557 lpfc_sli_brdrestart(phba);
558 *(int *)(evtp->evt_arg1) =
559 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
560 lpfc_unblock_mgmt_io(phba);
561 complete((struct completion *)(evtp->evt_arg2));
563 case LPFC_EVT_WARM_START:
565 lpfc_reset_barrier(phba);
566 lpfc_sli_brdreset(phba);
567 lpfc_hba_down_post(phba);
568 *(int *)(evtp->evt_arg1) =
569 lpfc_sli_brdready(phba, HS_MBRDY);
570 lpfc_unblock_mgmt_io(phba);
571 complete((struct completion *)(evtp->evt_arg2));
575 *(int *)(evtp->evt_arg1)
576 = (phba->pport->stopped)
577 ? 0 : lpfc_sli_brdkill(phba);
578 lpfc_unblock_mgmt_io(phba);
579 complete((struct completion *)(evtp->evt_arg2));
581 case LPFC_EVT_FASTPATH_MGMT_EVT:
582 lpfc_send_fastpath_evt(phba, evtp);
585 case LPFC_EVT_RESET_HBA:
586 if (!(phba->pport->load_flag & FC_UNLOADING))
587 lpfc_reset_hba(phba);
592 spin_lock_irq(&phba->hbalock);
594 spin_unlock_irq(&phba->hbalock);
599 lpfc_work_done(struct lpfc_hba *phba)
601 struct lpfc_sli_ring *pring;
602 uint32_t ha_copy, status, control, work_port_events;
603 struct lpfc_vport **vports;
604 struct lpfc_vport *vport;
607 spin_lock_irq(&phba->hbalock);
608 ha_copy = phba->work_ha;
610 spin_unlock_irq(&phba->hbalock);
612 /* First, try to post the next mailbox command to SLI4 device */
613 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
614 lpfc_sli4_post_async_mbox(phba);
616 if (ha_copy & HA_ERATT)
617 /* Handle the error attention event */
618 lpfc_handle_eratt(phba);
620 if (ha_copy & HA_MBATT)
621 lpfc_sli_handle_mb_event(phba);
623 if (ha_copy & HA_LATT)
624 lpfc_handle_latt(phba);
626 /* Process SLI4 events */
627 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
628 if (phba->hba_flag & HBA_RRQ_ACTIVE)
629 lpfc_handle_rrq_active(phba);
630 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
631 lpfc_sli4_fcp_xri_abort_event_proc(phba);
632 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
633 lpfc_sli4_els_xri_abort_event_proc(phba);
634 if (phba->hba_flag & ASYNC_EVENT)
635 lpfc_sli4_async_event_proc(phba);
636 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
637 spin_lock_irq(&phba->hbalock);
638 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
639 spin_unlock_irq(&phba->hbalock);
640 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
642 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
643 lpfc_sli4_fcf_redisc_event_proc(phba);
646 vports = lpfc_create_vport_work_array(phba);
648 for (i = 0; i <= phba->max_vports; i++) {
650 * We could have no vports in array if unloading, so if
651 * this happens then just use the pport
653 if (vports[i] == NULL && i == 0)
659 spin_lock_irq(&vport->work_port_lock);
660 work_port_events = vport->work_port_events;
661 vport->work_port_events &= ~work_port_events;
662 spin_unlock_irq(&vport->work_port_lock);
663 if (work_port_events & WORKER_DISC_TMO)
664 lpfc_disc_timeout_handler(vport);
665 if (work_port_events & WORKER_ELS_TMO)
666 lpfc_els_timeout_handler(vport);
667 if (work_port_events & WORKER_HB_TMO)
668 lpfc_hb_timeout_handler(phba);
669 if (work_port_events & WORKER_MBOX_TMO)
670 lpfc_mbox_timeout_handler(phba);
671 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
672 lpfc_unblock_fabric_iocbs(phba);
673 if (work_port_events & WORKER_FDMI_TMO)
674 lpfc_fdmi_timeout_handler(vport);
675 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
676 lpfc_ramp_down_queue_handler(phba);
677 if (work_port_events & WORKER_DELAYED_DISC_TMO)
678 lpfc_delayed_disc_timeout_handler(vport);
680 lpfc_destroy_vport_work_array(phba, vports);
682 pring = &phba->sli.ring[LPFC_ELS_RING];
683 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
684 status >>= (4*LPFC_ELS_RING);
685 if ((status & HA_RXMASK) ||
686 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
687 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
688 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
689 pring->flag |= LPFC_DEFERRED_RING_EVENT;
690 /* Set the lpfc data pending flag */
691 set_bit(LPFC_DATA_READY, &phba->data_flags);
693 if (phba->link_state >= LPFC_LINK_UP) {
694 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
695 lpfc_sli_handle_slow_ring_event(phba, pring,
700 if ((phba->sli_rev == LPFC_SLI_REV4) &
701 (!list_empty(&pring->txq)))
702 lpfc_drain_txq(phba);
704 * Turn on Ring interrupts
706 if (phba->sli_rev <= LPFC_SLI_REV3) {
707 spin_lock_irq(&phba->hbalock);
708 control = readl(phba->HCregaddr);
709 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
710 lpfc_debugfs_slow_ring_trc(phba,
711 "WRK Enable ring: cntl:x%x hacopy:x%x",
712 control, ha_copy, 0);
714 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
715 writel(control, phba->HCregaddr);
716 readl(phba->HCregaddr); /* flush */
718 lpfc_debugfs_slow_ring_trc(phba,
719 "WRK Ring ok: cntl:x%x hacopy:x%x",
720 control, ha_copy, 0);
722 spin_unlock_irq(&phba->hbalock);
725 lpfc_work_list_done(phba);
729 lpfc_do_work(void *p)
731 struct lpfc_hba *phba = p;
734 set_user_nice(current, MIN_NICE);
735 current->flags |= PF_NOFREEZE;
736 phba->data_flags = 0;
738 while (!kthread_should_stop()) {
739 /* wait and check worker queue activities */
740 rc = wait_event_interruptible(phba->work_waitq,
741 (test_and_clear_bit(LPFC_DATA_READY,
743 || kthread_should_stop()));
744 /* Signal wakeup shall terminate the worker thread */
746 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
747 "0433 Wakeup on signal: rc=x%x\n", rc);
751 /* Attend pending lpfc data processing */
752 lpfc_work_done(phba);
754 phba->worker_thread = NULL;
755 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
756 "0432 Worker thread stopped.\n");
761 * This is only called to handle FC worker events. Since this a rare
762 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
763 * embedding it in the IOCB.
766 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
769 struct lpfc_work_evt *evtp;
773 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
774 * be queued to worker thread for processing
776 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
780 evtp->evt_arg1 = arg1;
781 evtp->evt_arg2 = arg2;
784 spin_lock_irqsave(&phba->hbalock, flags);
785 list_add_tail(&evtp->evt_listp, &phba->work_list);
786 spin_unlock_irqrestore(&phba->hbalock, flags);
788 lpfc_worker_wake_up(phba);
794 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
796 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
797 struct lpfc_hba *phba = vport->phba;
798 struct lpfc_nodelist *ndlp, *next_ndlp;
801 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
802 if (!NLP_CHK_NODE_ACT(ndlp))
804 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
806 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
807 ((vport->port_type == LPFC_NPIV_PORT) &&
808 (ndlp->nlp_DID == NameServer_DID)))
809 lpfc_unreg_rpi(vport, ndlp);
811 /* Leave Fabric nodes alone on link down */
812 if ((phba->sli_rev < LPFC_SLI_REV4) &&
813 (!remove && ndlp->nlp_type & NLP_FABRIC))
815 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
818 : NLP_EVT_DEVICE_RECOVERY);
820 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
821 if (phba->sli_rev == LPFC_SLI_REV4)
822 lpfc_sli4_unreg_all_rpis(vport);
823 lpfc_mbx_unreg_vpi(vport);
824 spin_lock_irq(shost->host_lock);
825 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
826 spin_unlock_irq(shost->host_lock);
831 lpfc_port_link_failure(struct lpfc_vport *vport)
833 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
835 /* Cleanup any outstanding received buffers */
836 lpfc_cleanup_rcv_buffers(vport);
838 /* Cleanup any outstanding RSCN activity */
839 lpfc_els_flush_rscn(vport);
841 /* Cleanup any outstanding ELS commands */
842 lpfc_els_flush_cmd(vport);
844 lpfc_cleanup_rpis(vport, 0);
846 /* Turn off discovery timer if its running */
847 lpfc_can_disctmo(vport);
851 lpfc_linkdown_port(struct lpfc_vport *vport)
853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
855 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
858 "Link Down: state:x%x rtry:x%x flg:x%x",
859 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
861 lpfc_port_link_failure(vport);
863 /* Stop delayed Nport discovery */
864 spin_lock_irq(shost->host_lock);
865 vport->fc_flag &= ~FC_DISC_DELAYED;
866 spin_unlock_irq(shost->host_lock);
867 del_timer_sync(&vport->delayed_disc_tmo);
871 lpfc_linkdown(struct lpfc_hba *phba)
873 struct lpfc_vport *vport = phba->pport;
874 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
875 struct lpfc_vport **vports;
879 if (phba->link_state == LPFC_LINK_DOWN)
882 /* Block all SCSI stack I/Os */
883 lpfc_scsi_dev_block(phba);
885 spin_lock_irq(&phba->hbalock);
886 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
887 spin_unlock_irq(&phba->hbalock);
888 if (phba->link_state > LPFC_LINK_DOWN) {
889 phba->link_state = LPFC_LINK_DOWN;
890 spin_lock_irq(shost->host_lock);
891 phba->pport->fc_flag &= ~FC_LBIT;
892 spin_unlock_irq(shost->host_lock);
894 vports = lpfc_create_vport_work_array(phba);
896 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
897 /* Issue a LINK DOWN event to all nodes */
898 lpfc_linkdown_port(vports[i]);
900 lpfc_destroy_vport_work_array(phba, vports);
901 /* Clean up any firmware default rpi's */
902 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
904 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
906 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
907 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
908 == MBX_NOT_FINISHED) {
909 mempool_free(mb, phba->mbox_mem_pool);
913 /* Setup myDID for link up if we are in pt2pt mode */
914 if (phba->pport->fc_flag & FC_PT2PT) {
915 phba->pport->fc_myDID = 0;
916 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
918 lpfc_config_link(phba, mb);
919 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
921 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
922 == MBX_NOT_FINISHED) {
923 mempool_free(mb, phba->mbox_mem_pool);
926 spin_lock_irq(shost->host_lock);
927 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
928 spin_unlock_irq(shost->host_lock);
935 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
937 struct lpfc_nodelist *ndlp;
939 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
940 if (!NLP_CHK_NODE_ACT(ndlp))
942 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
944 if (ndlp->nlp_type & NLP_FABRIC) {
945 /* On Linkup its safe to clean up the ndlp
946 * from Fabric connections.
948 if (ndlp->nlp_DID != Fabric_DID)
949 lpfc_unreg_rpi(vport, ndlp);
950 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
951 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
952 /* Fail outstanding IO now since device is
955 lpfc_unreg_rpi(vport, ndlp);
961 lpfc_linkup_port(struct lpfc_vport *vport)
963 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
964 struct lpfc_hba *phba = vport->phba;
966 if ((vport->load_flag & FC_UNLOADING) != 0)
969 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
970 "Link Up: top:x%x speed:x%x flg:x%x",
971 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
973 /* If NPIV is not enabled, only bring the physical port up */
974 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
975 (vport != phba->pport))
978 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
980 spin_lock_irq(shost->host_lock);
981 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
982 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
983 vport->fc_flag |= FC_NDISC_ACTIVE;
984 vport->fc_ns_retry = 0;
985 spin_unlock_irq(shost->host_lock);
987 if (vport->fc_flag & FC_LBIT)
988 lpfc_linkup_cleanup_nodes(vport);
993 lpfc_linkup(struct lpfc_hba *phba)
995 struct lpfc_vport **vports;
998 lpfc_cleanup_wt_rrqs(phba);
999 phba->link_state = LPFC_LINK_UP;
1001 /* Unblock fabric iocbs if they are blocked */
1002 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1003 del_timer_sync(&phba->fabric_block_timer);
1005 vports = lpfc_create_vport_work_array(phba);
1007 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1008 lpfc_linkup_port(vports[i]);
1009 lpfc_destroy_vport_work_array(phba, vports);
1015 * This routine handles processing a CLEAR_LA mailbox
1016 * command upon completion. It is setup in the LPFC_MBOXQ
1017 * as the completion routine when the command is
1018 * handed off to the SLI layer.
1021 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1023 struct lpfc_vport *vport = pmb->vport;
1024 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1025 struct lpfc_sli *psli = &phba->sli;
1026 MAILBOX_t *mb = &pmb->u.mb;
1029 /* Since we don't do discovery right now, turn these off here */
1030 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1031 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1032 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1034 /* Check for error */
1035 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1036 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1037 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1038 "0320 CLEAR_LA mbxStatus error x%x hba "
1040 mb->mbxStatus, vport->port_state);
1041 phba->link_state = LPFC_HBA_ERROR;
1045 if (vport->port_type == LPFC_PHYSICAL_PORT)
1046 phba->link_state = LPFC_HBA_READY;
1048 spin_lock_irq(&phba->hbalock);
1049 psli->sli_flag |= LPFC_PROCESS_LA;
1050 control = readl(phba->HCregaddr);
1051 control |= HC_LAINT_ENA;
1052 writel(control, phba->HCregaddr);
1053 readl(phba->HCregaddr); /* flush */
1054 spin_unlock_irq(&phba->hbalock);
1055 mempool_free(pmb, phba->mbox_mem_pool);
1059 /* Device Discovery completes */
1060 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1061 "0225 Device Discovery completes\n");
1062 mempool_free(pmb, phba->mbox_mem_pool);
1064 spin_lock_irq(shost->host_lock);
1065 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1066 spin_unlock_irq(shost->host_lock);
1068 lpfc_can_disctmo(vport);
1070 /* turn on Link Attention interrupts */
1072 spin_lock_irq(&phba->hbalock);
1073 psli->sli_flag |= LPFC_PROCESS_LA;
1074 control = readl(phba->HCregaddr);
1075 control |= HC_LAINT_ENA;
1076 writel(control, phba->HCregaddr);
1077 readl(phba->HCregaddr); /* flush */
1078 spin_unlock_irq(&phba->hbalock);
1085 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1087 struct lpfc_vport *vport = pmb->vport;
1089 if (pmb->u.mb.mbxStatus)
1092 mempool_free(pmb, phba->mbox_mem_pool);
1094 /* don't perform discovery for SLI4 loopback diagnostic test */
1095 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1096 !(phba->hba_flag & HBA_FCOE_MODE) &&
1097 (phba->link_flag & LS_LOOPBACK_MODE))
1100 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1101 vport->fc_flag & FC_PUBLIC_LOOP &&
1102 !(vport->fc_flag & FC_LBIT)) {
1103 /* Need to wait for FAN - use discovery timer
1104 * for timeout. port_state is identically
1105 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1107 lpfc_set_disctmo(vport);
1111 /* Start discovery by sending a FLOGI. port_state is identically
1112 * LPFC_FLOGI while waiting for FLOGI cmpl
1114 if (vport->port_state != LPFC_FLOGI || vport->fc_flag & FC_PT2PT_PLOGI)
1115 lpfc_initial_flogi(vport);
1119 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1120 "0306 CONFIG_LINK mbxStatus error x%x "
1122 pmb->u.mb.mbxStatus, vport->port_state);
1123 mempool_free(pmb, phba->mbox_mem_pool);
1125 lpfc_linkdown(phba);
1127 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1128 "0200 CONFIG_LINK bad hba state x%x\n",
1131 lpfc_issue_clear_la(phba, vport);
1136 * lpfc_sli4_clear_fcf_rr_bmask
1137 * @phba pointer to the struct lpfc_hba for this port.
1138 * This fucnction resets the round robin bit mask and clears the
1139 * fcf priority list. The list deletions are done while holding the
1140 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1141 * from the lpfc_fcf_pri record.
1144 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1146 struct lpfc_fcf_pri *fcf_pri;
1147 struct lpfc_fcf_pri *next_fcf_pri;
1148 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1149 spin_lock_irq(&phba->hbalock);
1150 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1151 &phba->fcf.fcf_pri_list, list) {
1152 list_del_init(&fcf_pri->list);
1153 fcf_pri->fcf_rec.flag = 0;
1155 spin_unlock_irq(&phba->hbalock);
1158 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1160 struct lpfc_vport *vport = mboxq->vport;
1162 if (mboxq->u.mb.mbxStatus) {
1163 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1164 "2017 REG_FCFI mbxStatus error x%x "
1166 mboxq->u.mb.mbxStatus, vport->port_state);
1170 /* Start FCoE discovery by sending a FLOGI. */
1171 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1172 /* Set the FCFI registered flag */
1173 spin_lock_irq(&phba->hbalock);
1174 phba->fcf.fcf_flag |= FCF_REGISTERED;
1175 spin_unlock_irq(&phba->hbalock);
1177 /* If there is a pending FCoE event, restart FCF table scan. */
1178 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1179 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1182 /* Mark successful completion of FCF table scan */
1183 spin_lock_irq(&phba->hbalock);
1184 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1185 phba->hba_flag &= ~FCF_TS_INPROG;
1186 if (vport->port_state != LPFC_FLOGI) {
1187 phba->hba_flag |= FCF_RR_INPROG;
1188 spin_unlock_irq(&phba->hbalock);
1189 lpfc_issue_init_vfi(vport);
1192 spin_unlock_irq(&phba->hbalock);
1196 spin_lock_irq(&phba->hbalock);
1197 phba->hba_flag &= ~FCF_RR_INPROG;
1198 spin_unlock_irq(&phba->hbalock);
1200 mempool_free(mboxq, phba->mbox_mem_pool);
1204 * lpfc_fab_name_match - Check if the fcf fabric name match.
1205 * @fab_name: pointer to fabric name.
1206 * @new_fcf_record: pointer to fcf record.
1208 * This routine compare the fcf record's fabric name with provided
1209 * fabric name. If the fabric name are identical this function
1210 * returns 1 else return 0.
1213 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1215 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1217 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1219 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1221 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1223 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1225 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1227 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1229 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1235 * lpfc_sw_name_match - Check if the fcf switch name match.
1236 * @fab_name: pointer to fabric name.
1237 * @new_fcf_record: pointer to fcf record.
1239 * This routine compare the fcf record's switch name with provided
1240 * switch name. If the switch name are identical this function
1241 * returns 1 else return 0.
1244 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1246 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1248 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1250 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1252 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1254 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1256 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1258 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1260 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1266 * lpfc_mac_addr_match - Check if the fcf mac address match.
1267 * @mac_addr: pointer to mac address.
1268 * @new_fcf_record: pointer to fcf record.
1270 * This routine compare the fcf record's mac address with HBA's
1271 * FCF mac address. If the mac addresses are identical this function
1272 * returns 1 else return 0.
1275 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1277 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1279 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1281 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1283 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1285 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1287 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1293 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1295 return (curr_vlan_id == new_vlan_id);
1299 * lpfc_update_fcf_record - Update driver fcf record
1300 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1301 * @phba: pointer to lpfc hba data structure.
1302 * @fcf_index: Index for the lpfc_fcf_record.
1303 * @new_fcf_record: pointer to hba fcf record.
1305 * This routine updates the driver FCF priority record from the new HBA FCF
1306 * record. This routine is called with the host lock held.
1309 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1310 struct fcf_record *new_fcf_record
1313 struct lpfc_fcf_pri *fcf_pri;
1315 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1316 fcf_pri->fcf_rec.fcf_index = fcf_index;
1317 /* FCF record priority */
1318 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1323 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1324 * @fcf: pointer to driver fcf record.
1325 * @new_fcf_record: pointer to fcf record.
1327 * This routine copies the FCF information from the FCF
1328 * record to lpfc_hba data structure.
1331 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1332 struct fcf_record *new_fcf_record)
1335 fcf_rec->fabric_name[0] =
1336 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1337 fcf_rec->fabric_name[1] =
1338 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1339 fcf_rec->fabric_name[2] =
1340 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1341 fcf_rec->fabric_name[3] =
1342 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1343 fcf_rec->fabric_name[4] =
1344 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1345 fcf_rec->fabric_name[5] =
1346 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1347 fcf_rec->fabric_name[6] =
1348 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1349 fcf_rec->fabric_name[7] =
1350 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1352 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1353 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1354 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1355 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1356 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1357 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1358 /* FCF record index */
1359 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1360 /* FCF record priority */
1361 fcf_rec->priority = new_fcf_record->fip_priority;
1363 fcf_rec->switch_name[0] =
1364 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1365 fcf_rec->switch_name[1] =
1366 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1367 fcf_rec->switch_name[2] =
1368 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1369 fcf_rec->switch_name[3] =
1370 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1371 fcf_rec->switch_name[4] =
1372 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1373 fcf_rec->switch_name[5] =
1374 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1375 fcf_rec->switch_name[6] =
1376 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1377 fcf_rec->switch_name[7] =
1378 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1382 * lpfc_update_fcf_record - Update driver fcf record
1383 * @phba: pointer to lpfc hba data structure.
1384 * @fcf_rec: pointer to driver fcf record.
1385 * @new_fcf_record: pointer to hba fcf record.
1386 * @addr_mode: address mode to be set to the driver fcf record.
1387 * @vlan_id: vlan tag to be set to the driver fcf record.
1388 * @flag: flag bits to be set to the driver fcf record.
1390 * This routine updates the driver FCF record from the new HBA FCF record
1391 * together with the address mode, vlan_id, and other informations. This
1392 * routine is called with the host lock held.
1395 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1396 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1397 uint16_t vlan_id, uint32_t flag)
1399 /* Copy the fields from the HBA's FCF record */
1400 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1401 /* Update other fields of driver FCF record */
1402 fcf_rec->addr_mode = addr_mode;
1403 fcf_rec->vlan_id = vlan_id;
1404 fcf_rec->flag |= (flag | RECORD_VALID);
1405 __lpfc_update_fcf_record_pri(phba,
1406 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1411 * lpfc_register_fcf - Register the FCF with hba.
1412 * @phba: pointer to lpfc hba data structure.
1414 * This routine issues a register fcfi mailbox command to register
1418 lpfc_register_fcf(struct lpfc_hba *phba)
1420 LPFC_MBOXQ_t *fcf_mbxq;
1423 spin_lock_irq(&phba->hbalock);
1424 /* If the FCF is not available do nothing. */
1425 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1426 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1427 spin_unlock_irq(&phba->hbalock);
1431 /* The FCF is already registered, start discovery */
1432 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1433 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1434 phba->hba_flag &= ~FCF_TS_INPROG;
1435 if (phba->pport->port_state != LPFC_FLOGI &&
1436 phba->pport->fc_flag & FC_FABRIC) {
1437 phba->hba_flag |= FCF_RR_INPROG;
1438 spin_unlock_irq(&phba->hbalock);
1439 lpfc_initial_flogi(phba->pport);
1442 spin_unlock_irq(&phba->hbalock);
1445 spin_unlock_irq(&phba->hbalock);
1447 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1449 spin_lock_irq(&phba->hbalock);
1450 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1451 spin_unlock_irq(&phba->hbalock);
1455 lpfc_reg_fcfi(phba, fcf_mbxq);
1456 fcf_mbxq->vport = phba->pport;
1457 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1458 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1459 if (rc == MBX_NOT_FINISHED) {
1460 spin_lock_irq(&phba->hbalock);
1461 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1462 spin_unlock_irq(&phba->hbalock);
1463 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1470 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1471 * @phba: pointer to lpfc hba data structure.
1472 * @new_fcf_record: pointer to fcf record.
1473 * @boot_flag: Indicates if this record used by boot bios.
1474 * @addr_mode: The address mode to be used by this FCF
1475 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1477 * This routine compare the fcf record with connect list obtained from the
1478 * config region to decide if this FCF can be used for SAN discovery. It returns
1479 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1480 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1481 * is used by boot bios and addr_mode will indicate the addressing mode to be
1482 * used for this FCF when the function returns.
1483 * If the FCF record need to be used with a particular vlan id, the vlan is
1484 * set in the vlan_id on return of the function. If not VLAN tagging need to
1485 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1488 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1489 struct fcf_record *new_fcf_record,
1490 uint32_t *boot_flag, uint32_t *addr_mode,
1493 struct lpfc_fcf_conn_entry *conn_entry;
1494 int i, j, fcf_vlan_id = 0;
1496 /* Find the lowest VLAN id in the FCF record */
1497 for (i = 0; i < 512; i++) {
1498 if (new_fcf_record->vlan_bitmap[i]) {
1499 fcf_vlan_id = i * 8;
1501 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1509 /* FCF not valid/available or solicitation in progress */
1510 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1511 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1512 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1515 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1517 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1519 if (phba->valid_vlan)
1520 *vlan_id = phba->vlan_id;
1522 *vlan_id = LPFC_FCOE_NULL_VID;
1527 * If there are no FCF connection table entry, driver connect to all
1530 if (list_empty(&phba->fcf_conn_rec_list)) {
1532 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1536 * When there are no FCF connect entries, use driver's default
1537 * addressing mode - FPMA.
1539 if (*addr_mode & LPFC_FCF_FPMA)
1540 *addr_mode = LPFC_FCF_FPMA;
1542 /* If FCF record report a vlan id use that vlan id */
1544 *vlan_id = fcf_vlan_id;
1546 *vlan_id = LPFC_FCOE_NULL_VID;
1550 list_for_each_entry(conn_entry,
1551 &phba->fcf_conn_rec_list, list) {
1552 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1555 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1556 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1559 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1560 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1563 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1565 * If the vlan bit map does not have the bit set for the
1566 * vlan id to be used, then it is not a match.
1568 if (!(new_fcf_record->vlan_bitmap
1569 [conn_entry->conn_rec.vlan_tag / 8] &
1570 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1575 * If connection record does not support any addressing mode,
1576 * skip the FCF record.
1578 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1579 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1583 * Check if the connection record specifies a required
1586 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1587 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1590 * If SPMA required but FCF not support this continue.
1592 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1593 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1594 new_fcf_record) & LPFC_FCF_SPMA))
1598 * If FPMA required but FCF not support this continue.
1600 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1601 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1602 new_fcf_record) & LPFC_FCF_FPMA))
1607 * This fcf record matches filtering criteria.
1609 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1615 * If user did not specify any addressing mode, or if the
1616 * preferred addressing mode specified by user is not supported
1617 * by FCF, allow fabric to pick the addressing mode.
1619 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1622 * If the user specified a required address mode, assign that
1625 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1626 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1627 *addr_mode = (conn_entry->conn_rec.flags &
1629 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1631 * If the user specified a preferred address mode, use the
1632 * addr mode only if FCF support the addr_mode.
1634 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1635 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1636 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1637 (*addr_mode & LPFC_FCF_SPMA))
1638 *addr_mode = LPFC_FCF_SPMA;
1639 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1640 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1641 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1642 (*addr_mode & LPFC_FCF_FPMA))
1643 *addr_mode = LPFC_FCF_FPMA;
1645 /* If matching connect list has a vlan id, use it */
1646 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1647 *vlan_id = conn_entry->conn_rec.vlan_tag;
1649 * If no vlan id is specified in connect list, use the vlan id
1652 else if (fcf_vlan_id)
1653 *vlan_id = fcf_vlan_id;
1655 *vlan_id = LPFC_FCOE_NULL_VID;
1664 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1665 * @phba: pointer to lpfc hba data structure.
1666 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1668 * This function check if there is any fcoe event pending while driver
1669 * scan FCF entries. If there is any pending event, it will restart the
1670 * FCF saning and return 1 else return 0.
1673 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1676 * If the Link is up and no FCoE events while in the
1677 * FCF discovery, no need to restart FCF discovery.
1679 if ((phba->link_state >= LPFC_LINK_UP) &&
1680 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1683 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1684 "2768 Pending link or FCF event during current "
1685 "handling of the previous event: link_state:x%x, "
1686 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1687 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1688 phba->fcoe_eventtag);
1690 spin_lock_irq(&phba->hbalock);
1691 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1692 spin_unlock_irq(&phba->hbalock);
1694 if (phba->link_state >= LPFC_LINK_UP) {
1695 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1696 "2780 Restart FCF table scan due to "
1697 "pending FCF event:evt_tag_at_scan:x%x, "
1698 "evt_tag_current:x%x\n",
1699 phba->fcoe_eventtag_at_fcf_scan,
1700 phba->fcoe_eventtag);
1701 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1704 * Do not continue FCF discovery and clear FCF_TS_INPROG
1707 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1708 "2833 Stop FCF discovery process due to link "
1709 "state change (x%x)\n", phba->link_state);
1710 spin_lock_irq(&phba->hbalock);
1711 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1712 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
1713 spin_unlock_irq(&phba->hbalock);
1716 /* Unregister the currently registered FCF if required */
1718 spin_lock_irq(&phba->hbalock);
1719 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1720 spin_unlock_irq(&phba->hbalock);
1721 lpfc_sli4_unregister_fcf(phba);
1727 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1728 * @phba: pointer to lpfc hba data structure.
1729 * @fcf_cnt: number of eligible fcf record seen so far.
1731 * This function makes an running random selection decision on FCF record to
1732 * use through a sequence of @fcf_cnt eligible FCF records with equal
1733 * probability. To perform integer manunipulation of random numbers with
1734 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1735 * from prandom_u32() are taken as the random random number generated.
1737 * Returns true when outcome is for the newly read FCF record should be
1738 * chosen; otherwise, return false when outcome is for keeping the previously
1739 * chosen FCF record.
1742 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1746 /* Get 16-bit uniform random number */
1747 rand_num = 0xFFFF & prandom_u32();
1749 /* Decision with probability 1/fcf_cnt */
1750 if ((fcf_cnt * rand_num) < 0xFFFF)
1757 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
1758 * @phba: pointer to lpfc hba data structure.
1759 * @mboxq: pointer to mailbox object.
1760 * @next_fcf_index: pointer to holder of next fcf index.
1762 * This routine parses the non-embedded fcf mailbox command by performing the
1763 * necessarily error checking, non-embedded read FCF record mailbox command
1764 * SGE parsing, and endianness swapping.
1766 * Returns the pointer to the new FCF record in the non-embedded mailbox
1767 * command DMA memory if successfully, other NULL.
1769 static struct fcf_record *
1770 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1771 uint16_t *next_fcf_index)
1774 dma_addr_t phys_addr;
1775 struct lpfc_mbx_sge sge;
1776 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1777 uint32_t shdr_status, shdr_add_status;
1778 union lpfc_sli4_cfg_shdr *shdr;
1779 struct fcf_record *new_fcf_record;
1781 /* Get the first SGE entry from the non-embedded DMA memory. This
1782 * routine only uses a single SGE.
1784 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1785 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1786 if (unlikely(!mboxq->sge_array)) {
1787 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1788 "2524 Failed to get the non-embedded SGE "
1789 "virtual address\n");
1792 virt_addr = mboxq->sge_array->addr[0];
1794 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1795 lpfc_sli_pcimem_bcopy(shdr, shdr,
1796 sizeof(union lpfc_sli4_cfg_shdr));
1797 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
1798 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
1799 if (shdr_status || shdr_add_status) {
1800 if (shdr_status == STATUS_FCF_TABLE_EMPTY)
1801 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1802 "2726 READ_FCF_RECORD Indicates empty "
1805 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1806 "2521 READ_FCF_RECORD mailbox failed "
1807 "with status x%x add_status x%x, "
1808 "mbx\n", shdr_status, shdr_add_status);
1812 /* Interpreting the returned information of the FCF record */
1813 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1814 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1815 sizeof(struct lpfc_mbx_read_fcf_tbl));
1816 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
1817 new_fcf_record = (struct fcf_record *)(virt_addr +
1818 sizeof(struct lpfc_mbx_read_fcf_tbl));
1819 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
1820 offsetof(struct fcf_record, vlan_bitmap));
1821 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1822 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
1824 return new_fcf_record;
1828 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1829 * @phba: pointer to lpfc hba data structure.
1830 * @fcf_record: pointer to the fcf record.
1831 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1832 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1834 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1838 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1839 struct fcf_record *fcf_record,
1841 uint16_t next_fcf_index)
1843 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1844 "2764 READ_FCF_RECORD:\n"
1845 "\tFCF_Index : x%x\n"
1846 "\tFCF_Avail : x%x\n"
1847 "\tFCF_Valid : x%x\n"
1849 "\tFIP_Priority : x%x\n"
1850 "\tMAC_Provider : x%x\n"
1851 "\tLowest VLANID : x%x\n"
1852 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1853 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1854 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1855 "\tNext_FCF_Index: x%x\n",
1856 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1857 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1858 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1859 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
1860 fcf_record->fip_priority,
1861 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1863 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1864 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1865 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1866 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1867 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1868 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1869 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1870 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1871 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1872 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1873 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1874 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1875 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1876 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1877 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1878 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1879 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1880 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1881 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1882 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1883 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1884 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1889 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1890 * @phba: pointer to lpfc hba data structure.
1891 * @fcf_rec: pointer to an existing FCF record.
1892 * @new_fcf_record: pointer to a new FCF record.
1893 * @new_vlan_id: vlan id from the new FCF record.
1895 * This function performs matching test of a new FCF record against an existing
1896 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1897 * will not be used as part of the FCF record matching criteria.
1899 * Returns true if all the fields matching, otherwise returns false.
1902 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1903 struct lpfc_fcf_rec *fcf_rec,
1904 struct fcf_record *new_fcf_record,
1905 uint16_t new_vlan_id)
1907 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1908 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1910 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1912 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1914 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1916 if (fcf_rec->priority != new_fcf_record->fip_priority)
1922 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1923 * @vport: Pointer to vport object.
1924 * @fcf_index: index to next fcf.
1926 * This function processing the roundrobin fcf failover to next fcf index.
1927 * When this function is invoked, there will be a current fcf registered
1929 * Return: 0 for continue retrying flogi on currently registered fcf;
1930 * 1 for stop flogi on currently registered fcf;
1932 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1934 struct lpfc_hba *phba = vport->phba;
1937 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1938 spin_lock_irq(&phba->hbalock);
1939 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1940 spin_unlock_irq(&phba->hbalock);
1941 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1942 "2872 Devloss tmo with no eligible "
1943 "FCF, unregister in-use FCF (x%x) "
1944 "and rescan FCF table\n",
1945 phba->fcf.current_rec.fcf_indx);
1946 lpfc_unregister_fcf_rescan(phba);
1947 goto stop_flogi_current_fcf;
1949 /* Mark the end to FLOGI roundrobin failover */
1950 phba->hba_flag &= ~FCF_RR_INPROG;
1951 /* Allow action to new fcf asynchronous event */
1952 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1953 spin_unlock_irq(&phba->hbalock);
1954 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1955 "2865 No FCF available, stop roundrobin FCF "
1956 "failover and change port state:x%x/x%x\n",
1957 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1958 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1959 goto stop_flogi_current_fcf;
1961 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1962 "2794 Try FLOGI roundrobin FCF failover to "
1963 "(x%x)\n", fcf_index);
1964 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1966 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1967 "2761 FLOGI roundrobin FCF failover "
1968 "failed (rc:x%x) to read FCF (x%x)\n",
1969 rc, phba->fcf.current_rec.fcf_indx);
1971 goto stop_flogi_current_fcf;
1975 stop_flogi_current_fcf:
1976 lpfc_can_disctmo(vport);
1981 * lpfc_sli4_fcf_pri_list_del
1982 * @phba: pointer to lpfc hba data structure.
1983 * @fcf_index the index of the fcf record to delete
1984 * This routine checks the on list flag of the fcf_index to be deleted.
1985 * If it is one the list then it is removed from the list, and the flag
1986 * is cleared. This routine grab the hbalock before removing the fcf
1987 * record from the list.
1989 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
1992 struct lpfc_fcf_pri *new_fcf_pri;
1994 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1995 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1996 "3058 deleting idx x%x pri x%x flg x%x\n",
1997 fcf_index, new_fcf_pri->fcf_rec.priority,
1998 new_fcf_pri->fcf_rec.flag);
1999 spin_lock_irq(&phba->hbalock);
2000 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2001 if (phba->fcf.current_rec.priority ==
2002 new_fcf_pri->fcf_rec.priority)
2003 phba->fcf.eligible_fcf_cnt--;
2004 list_del_init(&new_fcf_pri->list);
2005 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2007 spin_unlock_irq(&phba->hbalock);
2011 * lpfc_sli4_set_fcf_flogi_fail
2012 * @phba: pointer to lpfc hba data structure.
2013 * @fcf_index the index of the fcf record to update
2014 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2015 * flag so the the round robin slection for the particular priority level
2016 * will try a different fcf record that does not have this bit set.
2017 * If the fcf record is re-read for any reason this flag is cleared brfore
2018 * adding it to the priority list.
2021 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2023 struct lpfc_fcf_pri *new_fcf_pri;
2024 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2025 spin_lock_irq(&phba->hbalock);
2026 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2027 spin_unlock_irq(&phba->hbalock);
2031 * lpfc_sli4_fcf_pri_list_add
2032 * @phba: pointer to lpfc hba data structure.
2033 * @fcf_index the index of the fcf record to add
2034 * This routine checks the priority of the fcf_index to be added.
2035 * If it is a lower priority than the current head of the fcf_pri list
2036 * then it is added to the list in the right order.
2037 * If it is the same priority as the current head of the list then it
2038 * is added to the head of the list and its bit in the rr_bmask is set.
2039 * If the fcf_index to be added is of a higher priority than the current
2040 * head of the list then the rr_bmask is cleared, its bit is set in the
2041 * rr_bmask and it is added to the head of the list.
2043 * 0=success 1=failure
2045 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2047 struct fcf_record *new_fcf_record)
2049 uint16_t current_fcf_pri;
2050 uint16_t last_index;
2051 struct lpfc_fcf_pri *fcf_pri;
2052 struct lpfc_fcf_pri *next_fcf_pri;
2053 struct lpfc_fcf_pri *new_fcf_pri;
2056 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2057 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2058 "3059 adding idx x%x pri x%x flg x%x\n",
2059 fcf_index, new_fcf_record->fip_priority,
2060 new_fcf_pri->fcf_rec.flag);
2061 spin_lock_irq(&phba->hbalock);
2062 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2063 list_del_init(&new_fcf_pri->list);
2064 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2065 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2066 if (list_empty(&phba->fcf.fcf_pri_list)) {
2067 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2068 ret = lpfc_sli4_fcf_rr_index_set(phba,
2069 new_fcf_pri->fcf_rec.fcf_index);
2073 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2074 LPFC_SLI4_FCF_TBL_INDX_MAX);
2075 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2076 ret = 0; /* Empty rr list */
2079 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2080 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2081 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2082 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2083 memset(phba->fcf.fcf_rr_bmask, 0,
2084 sizeof(*phba->fcf.fcf_rr_bmask));
2085 /* fcfs_at_this_priority_level = 1; */
2086 phba->fcf.eligible_fcf_cnt = 1;
2088 /* fcfs_at_this_priority_level++; */
2089 phba->fcf.eligible_fcf_cnt++;
2090 ret = lpfc_sli4_fcf_rr_index_set(phba,
2091 new_fcf_pri->fcf_rec.fcf_index);
2095 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2096 &phba->fcf.fcf_pri_list, list) {
2097 if (new_fcf_pri->fcf_rec.priority <=
2098 fcf_pri->fcf_rec.priority) {
2099 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2100 list_add(&new_fcf_pri->list,
2101 &phba->fcf.fcf_pri_list);
2103 list_add(&new_fcf_pri->list,
2104 &((struct lpfc_fcf_pri *)
2105 fcf_pri->list.prev)->list);
2108 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2109 || new_fcf_pri->fcf_rec.priority <
2110 next_fcf_pri->fcf_rec.priority) {
2111 list_add(&new_fcf_pri->list, &fcf_pri->list);
2115 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2121 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2122 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2123 spin_unlock_irq(&phba->hbalock);
2128 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2129 * @phba: pointer to lpfc hba data structure.
2130 * @mboxq: pointer to mailbox object.
2132 * This function iterates through all the fcf records available in
2133 * HBA and chooses the optimal FCF record for discovery. After finding
2134 * the FCF for discovery it registers the FCF record and kicks start
2136 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2137 * use an FCF record which matches fabric name and mac address of the
2138 * currently used FCF record.
2139 * If the driver supports only one FCF, it will try to use the FCF record
2140 * used by BOOT_BIOS.
2143 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2145 struct fcf_record *new_fcf_record;
2146 uint32_t boot_flag, addr_mode;
2147 uint16_t fcf_index, next_fcf_index;
2148 struct lpfc_fcf_rec *fcf_rec = NULL;
2151 bool select_new_fcf;
2154 /* If there is pending FCoE event restart FCF table scan */
2155 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2156 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2160 /* Parse the FCF record from the non-embedded mailbox command */
2161 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2163 if (!new_fcf_record) {
2164 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2165 "2765 Mailbox command READ_FCF_RECORD "
2166 "failed to retrieve a FCF record.\n");
2167 /* Let next new FCF event trigger fast failover */
2168 spin_lock_irq(&phba->hbalock);
2169 phba->hba_flag &= ~FCF_TS_INPROG;
2170 spin_unlock_irq(&phba->hbalock);
2171 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2175 /* Check the FCF record against the connection list */
2176 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2177 &addr_mode, &vlan_id);
2179 /* Log the FCF record information if turned on */
2180 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2184 * If the fcf record does not match with connect list entries
2185 * read the next entry; otherwise, this is an eligible FCF
2186 * record for roundrobin FCF failover.
2189 lpfc_sli4_fcf_pri_list_del(phba,
2190 bf_get(lpfc_fcf_record_fcf_index,
2192 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2193 "2781 FCF (x%x) failed connection "
2194 "list check: (x%x/x%x/%x)\n",
2195 bf_get(lpfc_fcf_record_fcf_index,
2197 bf_get(lpfc_fcf_record_fcf_avail,
2199 bf_get(lpfc_fcf_record_fcf_valid,
2201 bf_get(lpfc_fcf_record_fcf_sol,
2203 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2204 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2205 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2206 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2207 phba->fcf.current_rec.fcf_indx) {
2208 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2209 "2862 FCF (x%x) matches property "
2210 "of in-use FCF (x%x)\n",
2211 bf_get(lpfc_fcf_record_fcf_index,
2213 phba->fcf.current_rec.fcf_indx);
2217 * In case the current in-use FCF record becomes
2218 * invalid/unavailable during FCF discovery that
2219 * was not triggered by fast FCF failover process,
2220 * treat it as fast FCF failover.
2222 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2223 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2224 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2225 "2835 Invalid in-use FCF "
2226 "(x%x), enter FCF failover "
2228 phba->fcf.current_rec.fcf_indx);
2229 spin_lock_irq(&phba->hbalock);
2230 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2231 spin_unlock_irq(&phba->hbalock);
2232 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2233 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2234 LPFC_FCOE_FCF_GET_FIRST);
2240 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2241 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2248 * If this is not the first FCF discovery of the HBA, use last
2249 * FCF record for the discovery. The condition that a rescan
2250 * matches the in-use FCF record: fabric name, switch name, mac
2251 * address, and vlan_id.
2253 spin_lock_irq(&phba->hbalock);
2254 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2255 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2256 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2257 new_fcf_record, vlan_id)) {
2258 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2259 phba->fcf.current_rec.fcf_indx) {
2260 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2261 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2262 /* Stop FCF redisc wait timer */
2263 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2265 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2266 /* Fast failover, mark completed */
2267 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2268 spin_unlock_irq(&phba->hbalock);
2269 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2270 "2836 New FCF matches in-use "
2271 "FCF (x%x), port_state:x%x, "
2273 phba->fcf.current_rec.fcf_indx,
2274 phba->pport->port_state,
2275 phba->pport->fc_flag);
2278 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2279 "2863 New FCF (x%x) matches "
2280 "property of in-use FCF (x%x)\n",
2281 bf_get(lpfc_fcf_record_fcf_index,
2283 phba->fcf.current_rec.fcf_indx);
2286 * Read next FCF record from HBA searching for the matching
2287 * with in-use record only if not during the fast failover
2288 * period. In case of fast failover period, it shall try to
2289 * determine whether the FCF record just read should be the
2292 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2293 spin_unlock_irq(&phba->hbalock);
2298 * Update on failover FCF record only if it's in FCF fast-failover
2299 * period; otherwise, update on current FCF record.
2301 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2302 fcf_rec = &phba->fcf.failover_rec;
2304 fcf_rec = &phba->fcf.current_rec;
2306 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2308 * If the driver FCF record does not have boot flag
2309 * set and new hba fcf record has boot flag set, use
2310 * the new hba fcf record.
2312 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2313 /* Choose this FCF record */
2314 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2315 "2837 Update current FCF record "
2316 "(x%x) with new FCF record (x%x)\n",
2318 bf_get(lpfc_fcf_record_fcf_index,
2320 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2321 addr_mode, vlan_id, BOOT_ENABLE);
2322 spin_unlock_irq(&phba->hbalock);
2326 * If the driver FCF record has boot flag set and the
2327 * new hba FCF record does not have boot flag, read
2328 * the next FCF record.
2330 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2331 spin_unlock_irq(&phba->hbalock);
2335 * If the new hba FCF record has lower priority value
2336 * than the driver FCF record, use the new record.
2338 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2339 /* Choose the new FCF record with lower priority */
2340 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2341 "2838 Update current FCF record "
2342 "(x%x) with new FCF record (x%x)\n",
2344 bf_get(lpfc_fcf_record_fcf_index,
2346 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2347 addr_mode, vlan_id, 0);
2348 /* Reset running random FCF selection count */
2349 phba->fcf.eligible_fcf_cnt = 1;
2350 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2351 /* Update running random FCF selection count */
2352 phba->fcf.eligible_fcf_cnt++;
2353 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2354 phba->fcf.eligible_fcf_cnt);
2355 if (select_new_fcf) {
2356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2357 "2839 Update current FCF record "
2358 "(x%x) with new FCF record (x%x)\n",
2360 bf_get(lpfc_fcf_record_fcf_index,
2362 /* Choose the new FCF by random selection */
2363 __lpfc_update_fcf_record(phba, fcf_rec,
2365 addr_mode, vlan_id, 0);
2368 spin_unlock_irq(&phba->hbalock);
2372 * This is the first suitable FCF record, choose this record for
2373 * initial best-fit FCF.
2376 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2377 "2840 Update initial FCF candidate "
2379 bf_get(lpfc_fcf_record_fcf_index,
2381 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2382 addr_mode, vlan_id, (boot_flag ?
2384 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2385 /* Setup initial running random FCF selection count */
2386 phba->fcf.eligible_fcf_cnt = 1;
2387 /* Seeding the random number generator for random selection */
2388 seed = (uint32_t)(0xFFFFFFFF & jiffies);
2391 spin_unlock_irq(&phba->hbalock);
2395 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2396 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2397 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2399 * Case of FCF fast failover scan
2403 * It has not found any suitable FCF record, cancel
2404 * FCF scan inprogress, and do nothing
2406 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2407 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2408 "2782 No suitable FCF found: "
2410 phba->fcoe_eventtag_at_fcf_scan,
2411 bf_get(lpfc_fcf_record_fcf_index,
2413 spin_lock_irq(&phba->hbalock);
2414 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2415 phba->hba_flag &= ~FCF_TS_INPROG;
2416 spin_unlock_irq(&phba->hbalock);
2417 /* Unregister in-use FCF and rescan */
2418 lpfc_printf_log(phba, KERN_INFO,
2420 "2864 On devloss tmo "
2421 "unreg in-use FCF and "
2422 "rescan FCF table\n");
2423 lpfc_unregister_fcf_rescan(phba);
2427 * Let next new FCF event trigger fast failover
2429 phba->hba_flag &= ~FCF_TS_INPROG;
2430 spin_unlock_irq(&phba->hbalock);
2434 * It has found a suitable FCF record that is not
2435 * the same as in-use FCF record, unregister the
2436 * in-use FCF record, replace the in-use FCF record
2437 * with the new FCF record, mark FCF fast failover
2438 * completed, and then start register the new FCF
2442 /* Unregister the current in-use FCF record */
2443 lpfc_unregister_fcf(phba);
2445 /* Replace in-use record with the new record */
2446 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2447 "2842 Replace in-use FCF (x%x) "
2448 "with failover FCF (x%x)\n",
2449 phba->fcf.current_rec.fcf_indx,
2450 phba->fcf.failover_rec.fcf_indx);
2451 memcpy(&phba->fcf.current_rec,
2452 &phba->fcf.failover_rec,
2453 sizeof(struct lpfc_fcf_rec));
2455 * Mark the fast FCF failover rediscovery completed
2456 * and the start of the first round of the roundrobin
2459 spin_lock_irq(&phba->hbalock);
2460 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2461 spin_unlock_irq(&phba->hbalock);
2462 /* Register to the new FCF record */
2463 lpfc_register_fcf(phba);
2466 * In case of transaction period to fast FCF failover,
2467 * do nothing when search to the end of the FCF table.
2469 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2470 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2473 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2474 phba->fcf.fcf_flag & FCF_IN_USE) {
2476 * In case the current in-use FCF record no
2477 * longer existed during FCF discovery that
2478 * was not triggered by fast FCF failover
2479 * process, treat it as fast FCF failover.
2481 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2482 "2841 In-use FCF record (x%x) "
2483 "not reported, entering fast "
2484 "FCF failover mode scanning.\n",
2485 phba->fcf.current_rec.fcf_indx);
2486 spin_lock_irq(&phba->hbalock);
2487 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2488 spin_unlock_irq(&phba->hbalock);
2489 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2490 LPFC_FCOE_FCF_GET_FIRST);
2493 /* Register to the new FCF record */
2494 lpfc_register_fcf(phba);
2497 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2501 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2502 lpfc_register_fcf(phba);
2508 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2509 * @phba: pointer to lpfc hba data structure.
2510 * @mboxq: pointer to mailbox object.
2512 * This is the callback function for FLOGI failure roundrobin FCF failover
2513 * read FCF record mailbox command from the eligible FCF record bmask for
2514 * performing the failover. If the FCF read back is not valid/available, it
2515 * fails through to retrying FLOGI to the currently registered FCF again.
2516 * Otherwise, if the FCF read back is valid and available, it will set the
2517 * newly read FCF record to the failover FCF record, unregister currently
2518 * registered FCF record, copy the failover FCF record to the current
2519 * FCF record, and then register the current FCF record before proceeding
2520 * to trying FLOGI on the new failover FCF.
2523 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2525 struct fcf_record *new_fcf_record;
2526 uint32_t boot_flag, addr_mode;
2527 uint16_t next_fcf_index, fcf_index;
2528 uint16_t current_fcf_index;
2532 /* If link state is not up, stop the roundrobin failover process */
2533 if (phba->link_state < LPFC_LINK_UP) {
2534 spin_lock_irq(&phba->hbalock);
2535 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2536 phba->hba_flag &= ~FCF_RR_INPROG;
2537 spin_unlock_irq(&phba->hbalock);
2541 /* Parse the FCF record from the non-embedded mailbox command */
2542 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2544 if (!new_fcf_record) {
2545 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2546 "2766 Mailbox command READ_FCF_RECORD "
2547 "failed to retrieve a FCF record. "
2548 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2549 phba->fcf.fcf_flag);
2550 lpfc_unregister_fcf_rescan(phba);
2554 /* Get the needed parameters from FCF record */
2555 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2556 &addr_mode, &vlan_id);
2558 /* Log the FCF record information if turned on */
2559 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2562 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2564 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2565 "2848 Remove ineligible FCF (x%x) from "
2566 "from roundrobin bmask\n", fcf_index);
2567 /* Clear roundrobin bmask bit for ineligible FCF */
2568 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2569 /* Perform next round of roundrobin FCF failover */
2570 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2571 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2577 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2578 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2579 "2760 Perform FLOGI roundrobin FCF failover: "
2580 "FCF (x%x) back to FCF (x%x)\n",
2581 phba->fcf.current_rec.fcf_indx, fcf_index);
2582 /* Wait 500 ms before retrying FLOGI to current FCF */
2584 lpfc_issue_init_vfi(phba->pport);
2588 /* Upload new FCF record to the failover FCF record */
2589 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2590 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2591 phba->fcf.failover_rec.fcf_indx, fcf_index);
2592 spin_lock_irq(&phba->hbalock);
2593 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2594 new_fcf_record, addr_mode, vlan_id,
2595 (boot_flag ? BOOT_ENABLE : 0));
2596 spin_unlock_irq(&phba->hbalock);
2598 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2600 /* Unregister the current in-use FCF record */
2601 lpfc_unregister_fcf(phba);
2603 /* Replace in-use record with the new record */
2604 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2605 sizeof(struct lpfc_fcf_rec));
2607 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2608 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2609 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
2612 lpfc_register_fcf(phba);
2614 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2618 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2619 * @phba: pointer to lpfc hba data structure.
2620 * @mboxq: pointer to mailbox object.
2622 * This is the callback function of read FCF record mailbox command for
2623 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
2624 * failover when a new FCF event happened. If the FCF read back is
2625 * valid/available and it passes the connection list check, it updates
2626 * the bmask for the eligible FCF record for roundrobin failover.
2629 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2631 struct fcf_record *new_fcf_record;
2632 uint32_t boot_flag, addr_mode;
2633 uint16_t fcf_index, next_fcf_index;
2637 /* If link state is not up, no need to proceed */
2638 if (phba->link_state < LPFC_LINK_UP)
2641 /* If FCF discovery period is over, no need to proceed */
2642 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
2645 /* Parse the FCF record from the non-embedded mailbox command */
2646 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2648 if (!new_fcf_record) {
2649 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2650 "2767 Mailbox command READ_FCF_RECORD "
2651 "failed to retrieve a FCF record.\n");
2655 /* Check the connection list for eligibility */
2656 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2657 &addr_mode, &vlan_id);
2659 /* Log the FCF record information if turned on */
2660 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2666 /* Update the eligible FCF record index bmask */
2667 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2669 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
2672 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2676 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2677 * @phba: pointer to lpfc hba data structure.
2678 * @mboxq: pointer to mailbox data structure.
2680 * This function handles completion of init vfi mailbox command.
2683 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2685 struct lpfc_vport *vport = mboxq->vport;
2688 * VFI not supported on interface type 0, just do the flogi
2689 * Also continue if the VFI is in use - just use the same one.
2691 if (mboxq->u.mb.mbxStatus &&
2692 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2693 LPFC_SLI_INTF_IF_TYPE_0) &&
2694 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2695 lpfc_printf_vlog(vport, KERN_ERR,
2697 "2891 Init VFI mailbox failed 0x%x\n",
2698 mboxq->u.mb.mbxStatus);
2699 mempool_free(mboxq, phba->mbox_mem_pool);
2700 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2704 lpfc_initial_flogi(vport);
2705 mempool_free(mboxq, phba->mbox_mem_pool);
2710 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2711 * @vport: pointer to lpfc_vport data structure.
2713 * This function issue a init_vfi mailbox command to initialize the VFI and
2714 * VPI for the physical port.
2717 lpfc_issue_init_vfi(struct lpfc_vport *vport)
2719 LPFC_MBOXQ_t *mboxq;
2721 struct lpfc_hba *phba = vport->phba;
2723 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2725 lpfc_printf_vlog(vport, KERN_ERR,
2726 LOG_MBOX, "2892 Failed to allocate "
2727 "init_vfi mailbox\n");
2730 lpfc_init_vfi(mboxq, vport);
2731 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2732 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2733 if (rc == MBX_NOT_FINISHED) {
2734 lpfc_printf_vlog(vport, KERN_ERR,
2735 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2736 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2741 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2742 * @phba: pointer to lpfc hba data structure.
2743 * @mboxq: pointer to mailbox data structure.
2745 * This function handles completion of init vpi mailbox command.
2748 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2750 struct lpfc_vport *vport = mboxq->vport;
2751 struct lpfc_nodelist *ndlp;
2752 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2754 if (mboxq->u.mb.mbxStatus) {
2755 lpfc_printf_vlog(vport, KERN_ERR,
2757 "2609 Init VPI mailbox failed 0x%x\n",
2758 mboxq->u.mb.mbxStatus);
2759 mempool_free(mboxq, phba->mbox_mem_pool);
2760 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2763 spin_lock_irq(shost->host_lock);
2764 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2765 spin_unlock_irq(shost->host_lock);
2767 /* If this port is physical port or FDISC is done, do reg_vpi */
2768 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2769 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2771 lpfc_printf_vlog(vport, KERN_ERR,
2773 "2731 Cannot find fabric "
2774 "controller node\n");
2776 lpfc_register_new_vport(phba, vport, ndlp);
2777 mempool_free(mboxq, phba->mbox_mem_pool);
2781 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2782 lpfc_initial_fdisc(vport);
2784 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
2785 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2786 "2606 No NPIV Fabric support\n");
2788 mempool_free(mboxq, phba->mbox_mem_pool);
2793 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2794 * @vport: pointer to lpfc_vport data structure.
2796 * This function issue a init_vpi mailbox command to initialize
2797 * VPI for the vport.
2800 lpfc_issue_init_vpi(struct lpfc_vport *vport)
2802 LPFC_MBOXQ_t *mboxq;
2805 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
2806 vpi = lpfc_alloc_vpi(vport->phba);
2808 lpfc_printf_vlog(vport, KERN_ERR,
2810 "3303 Failed to obtain vport vpi\n");
2811 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2817 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2819 lpfc_printf_vlog(vport, KERN_ERR,
2820 LOG_MBOX, "2607 Failed to allocate "
2821 "init_vpi mailbox\n");
2824 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2825 mboxq->vport = vport;
2826 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2827 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2828 if (rc == MBX_NOT_FINISHED) {
2829 lpfc_printf_vlog(vport, KERN_ERR,
2830 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2831 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2836 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2837 * @phba: pointer to lpfc hba data structure.
2839 * This function loops through the list of vports on the @phba and issues an
2840 * FDISC if possible.
2843 lpfc_start_fdiscs(struct lpfc_hba *phba)
2845 struct lpfc_vport **vports;
2848 vports = lpfc_create_vport_work_array(phba);
2849 if (vports != NULL) {
2850 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2851 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2853 /* There are no vpi for this vport */
2854 if (vports[i]->vpi > phba->max_vpi) {
2855 lpfc_vport_set_state(vports[i],
2859 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2860 lpfc_vport_set_state(vports[i],
2864 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
2865 lpfc_issue_init_vpi(vports[i]);
2868 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2869 lpfc_initial_fdisc(vports[i]);
2871 lpfc_vport_set_state(vports[i],
2872 FC_VPORT_NO_FABRIC_SUPP);
2873 lpfc_printf_vlog(vports[i], KERN_ERR,
2876 "Fabric support\n");
2880 lpfc_destroy_vport_work_array(phba, vports);
2884 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2886 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2887 struct lpfc_vport *vport = mboxq->vport;
2888 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2891 * VFI not supported for interface type 0, so ignore any mailbox
2892 * error (except VFI in use) and continue with the discovery.
2894 if (mboxq->u.mb.mbxStatus &&
2895 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
2896 LPFC_SLI_INTF_IF_TYPE_0) &&
2897 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
2898 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2899 "2018 REG_VFI mbxStatus error x%x "
2901 mboxq->u.mb.mbxStatus, vport->port_state);
2902 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
2903 /* FLOGI failed, use loop map to make discovery list */
2904 lpfc_disc_list_loopmap(vport);
2905 /* Start discovery */
2906 lpfc_disc_start(vport);
2909 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2913 /* If the VFI is already registered, there is nothing else to do
2914 * Unless this was a VFI update and we are in PT2PT mode, then
2915 * we should drop through to set the port state to ready.
2917 if (vport->fc_flag & FC_VFI_REGISTERED)
2918 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
2919 vport->fc_flag & FC_PT2PT))
2922 /* The VPI is implicitly registered when the VFI is registered */
2923 spin_lock_irq(shost->host_lock);
2924 vport->vpi_state |= LPFC_VPI_REGISTERED;
2925 vport->fc_flag |= FC_VFI_REGISTERED;
2926 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
2927 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
2928 spin_unlock_irq(shost->host_lock);
2930 /* In case SLI4 FC loopback test, we are ready */
2931 if ((phba->sli_rev == LPFC_SLI_REV4) &&
2932 (phba->link_flag & LS_LOOPBACK_MODE)) {
2933 phba->link_state = LPFC_HBA_READY;
2937 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
2938 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
2939 "alpacnt:%d LinkState:%x topology:%x\n",
2940 vport->port_state, vport->fc_flag, vport->fc_myDID,
2941 vport->phba->alpa_map[0],
2942 phba->link_state, phba->fc_topology);
2944 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
2946 * For private loop or for NPort pt2pt,
2947 * just start discovery and we are done.
2949 if ((vport->fc_flag & FC_PT2PT) ||
2950 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2951 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
2953 /* Use loop map to make discovery list */
2954 lpfc_disc_list_loopmap(vport);
2955 /* Start discovery */
2956 if (vport->fc_flag & FC_PT2PT)
2957 vport->port_state = LPFC_VPORT_READY;
2959 lpfc_disc_start(vport);
2961 lpfc_start_fdiscs(phba);
2962 lpfc_do_scr_ns_plogi(phba, vport);
2967 mempool_free(mboxq, phba->mbox_mem_pool);
2968 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2974 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2976 MAILBOX_t *mb = &pmb->u.mb;
2977 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
2978 struct lpfc_vport *vport = pmb->vport;
2981 /* Check for error */
2982 if (mb->mbxStatus) {
2983 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
2984 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2985 "0319 READ_SPARAM mbxStatus error x%x "
2987 mb->mbxStatus, vport->port_state);
2988 lpfc_linkdown(phba);
2992 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
2993 sizeof (struct serv_parm));
2994 lpfc_update_vport_wwn(vport);
2995 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2996 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
2997 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3000 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3002 mempool_free(pmb, phba->mbox_mem_pool);
3006 pmb->context1 = NULL;
3007 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3009 lpfc_issue_clear_la(phba, vport);
3010 mempool_free(pmb, phba->mbox_mem_pool);
3015 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3017 struct lpfc_vport *vport = phba->pport;
3018 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3019 struct Scsi_Host *shost;
3021 struct lpfc_dmabuf *mp;
3023 struct fcf_record *fcf_record;
3024 uint32_t fc_flags = 0;
3026 spin_lock_irq(&phba->hbalock);
3027 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3028 case LPFC_LINK_SPEED_1GHZ:
3029 case LPFC_LINK_SPEED_2GHZ:
3030 case LPFC_LINK_SPEED_4GHZ:
3031 case LPFC_LINK_SPEED_8GHZ:
3032 case LPFC_LINK_SPEED_10GHZ:
3033 case LPFC_LINK_SPEED_16GHZ:
3034 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3037 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3041 if (phba->fc_topology &&
3042 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3043 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3044 "3314 Toplogy changed was 0x%x is 0x%x\n",
3046 bf_get(lpfc_mbx_read_top_topology, la));
3047 phba->fc_topology_changed = 1;
3050 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3051 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
3053 shost = lpfc_shost_from_vport(vport);
3054 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3055 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3057 /* if npiv is enabled and this adapter supports npiv log
3058 * a message that npiv is not supported in this topology
3060 if (phba->cfg_enable_npiv && phba->max_vpi)
3061 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3062 "1309 Link Up Event npiv not supported in loop "
3064 /* Get Loop Map information */
3065 if (bf_get(lpfc_mbx_read_top_il, la))
3066 fc_flags |= FC_LBIT;
3068 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3069 i = la->lilpBde64.tus.f.bdeSize;
3072 phba->alpa_map[0] = 0;
3074 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3085 numalpa = phba->alpa_map[0];
3087 while (j < numalpa) {
3088 memset(un.pamap, 0, 16);
3089 for (k = 1; j < numalpa; k++) {
3091 phba->alpa_map[j + 1];
3096 /* Link Up Event ALPA map */
3097 lpfc_printf_log(phba,
3100 "1304 Link Up Event "
3101 "ALPA map Data: x%x "
3103 un.pa.wd1, un.pa.wd2,
3104 un.pa.wd3, un.pa.wd4);
3109 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3110 if (phba->max_vpi && phba->cfg_enable_npiv &&
3111 (phba->sli_rev >= LPFC_SLI_REV3))
3112 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3114 vport->fc_myDID = phba->fc_pref_DID;
3115 fc_flags |= FC_LBIT;
3117 spin_unlock_irq(&phba->hbalock);
3120 spin_lock_irq(shost->host_lock);
3121 vport->fc_flag |= fc_flags;
3122 spin_unlock_irq(shost->host_lock);
3126 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3130 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3132 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3135 sparam_mbox->vport = vport;
3136 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3137 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3138 if (rc == MBX_NOT_FINISHED) {
3139 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
3140 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3142 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3146 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3147 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3150 vport->port_state = LPFC_LOCAL_CFG_LINK;
3151 lpfc_config_link(phba, cfglink_mbox);
3152 cfglink_mbox->vport = vport;
3153 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3154 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3155 if (rc == MBX_NOT_FINISHED) {
3156 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3160 vport->port_state = LPFC_VPORT_UNKNOWN;
3162 * Add the driver's default FCF record at FCF index 0 now. This
3163 * is phase 1 implementation that support FCF index 0 and driver
3166 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3167 fcf_record = kzalloc(sizeof(struct fcf_record),
3169 if (unlikely(!fcf_record)) {
3170 lpfc_printf_log(phba, KERN_ERR,
3172 "2554 Could not allocate memory for "
3178 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3179 LPFC_FCOE_FCF_DEF_INDEX);
3180 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3182 lpfc_printf_log(phba, KERN_ERR,
3184 "2013 Could not manually add FCF "
3185 "record 0, status %d\n", rc);
3193 * The driver is expected to do FIP/FCF. Call the port
3194 * and get the FCF Table.
3196 spin_lock_irq(&phba->hbalock);
3197 if (phba->hba_flag & FCF_TS_INPROG) {
3198 spin_unlock_irq(&phba->hbalock);
3201 /* This is the initial FCF discovery scan */
3202 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3203 spin_unlock_irq(&phba->hbalock);
3204 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3205 "2778 Start FCF table scan at linkup\n");
3206 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3207 LPFC_FCOE_FCF_GET_FIRST);
3209 spin_lock_irq(&phba->hbalock);
3210 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3211 spin_unlock_irq(&phba->hbalock);
3214 /* Reset FCF roundrobin bmask for new discovery */
3215 lpfc_sli4_clear_fcf_rr_bmask(phba);
3220 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3221 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3222 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
3223 vport->port_state, sparam_mbox, cfglink_mbox);
3224 lpfc_issue_clear_la(phba, vport);
3229 lpfc_enable_la(struct lpfc_hba *phba)
3232 struct lpfc_sli *psli = &phba->sli;
3233 spin_lock_irq(&phba->hbalock);
3234 psli->sli_flag |= LPFC_PROCESS_LA;
3235 if (phba->sli_rev <= LPFC_SLI_REV3) {
3236 control = readl(phba->HCregaddr);
3237 control |= HC_LAINT_ENA;
3238 writel(control, phba->HCregaddr);
3239 readl(phba->HCregaddr); /* flush */
3241 spin_unlock_irq(&phba->hbalock);
3245 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3247 lpfc_linkdown(phba);
3248 lpfc_enable_la(phba);
3249 lpfc_unregister_unused_fcf(phba);
3250 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3255 * This routine handles processing a READ_TOPOLOGY mailbox
3256 * command upon completion. It is setup in the LPFC_MBOXQ
3257 * as the completion routine when the command is
3258 * handed off to the SLI layer.
3261 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3263 struct lpfc_vport *vport = pmb->vport;
3264 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3265 struct lpfc_mbx_read_top *la;
3266 MAILBOX_t *mb = &pmb->u.mb;
3267 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3269 /* Unblock ELS traffic */
3270 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
3271 /* Check for error */
3272 if (mb->mbxStatus) {
3273 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3274 "1307 READ_LA mbox error x%x state x%x\n",
3275 mb->mbxStatus, vport->port_state);
3276 lpfc_mbx_issue_link_down(phba);
3277 phba->link_state = LPFC_HBA_ERROR;
3278 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3281 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3283 memcpy(&phba->alpa_map[0], mp->virt, 128);
3285 spin_lock_irq(shost->host_lock);
3286 if (bf_get(lpfc_mbx_read_top_pb, la))
3287 vport->fc_flag |= FC_BYPASSED_MODE;
3289 vport->fc_flag &= ~FC_BYPASSED_MODE;
3290 spin_unlock_irq(shost->host_lock);
3292 if (phba->fc_eventTag <= la->eventTag) {
3293 phba->fc_stat.LinkMultiEvent++;
3294 if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
3295 if (phba->fc_eventTag != 0)
3296 lpfc_linkdown(phba);
3299 phba->fc_eventTag = la->eventTag;
3300 if (phba->sli_rev < LPFC_SLI_REV4) {
3301 spin_lock_irq(&phba->hbalock);
3302 if (bf_get(lpfc_mbx_read_top_mm, la))
3303 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3305 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3306 spin_unlock_irq(&phba->hbalock);
3309 phba->link_events++;
3310 if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
3311 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3312 phba->fc_stat.LinkUp++;
3313 if (phba->link_flag & LS_LOOPBACK_MODE) {
3314 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3315 "1306 Link Up Event in loop back mode "
3316 "x%x received Data: x%x x%x x%x x%x\n",
3317 la->eventTag, phba->fc_eventTag,
3318 bf_get(lpfc_mbx_read_top_alpa_granted,
3320 bf_get(lpfc_mbx_read_top_link_spd, la),
3323 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3324 "1303 Link Up Event x%x received "
3325 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3326 la->eventTag, phba->fc_eventTag,
3327 bf_get(lpfc_mbx_read_top_alpa_granted,
3329 bf_get(lpfc_mbx_read_top_link_spd, la),
3331 bf_get(lpfc_mbx_read_top_mm, la),
3332 bf_get(lpfc_mbx_read_top_fa, la),
3333 phba->wait_4_mlo_maint_flg);
3335 lpfc_mbx_process_link_up(phba, la);
3336 } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
3337 LPFC_ATT_LINK_DOWN) {
3338 phba->fc_stat.LinkDown++;
3339 if (phba->link_flag & LS_LOOPBACK_MODE)
3340 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3341 "1308 Link Down Event in loop back mode "
3343 "Data: x%x x%x x%x\n",
3344 la->eventTag, phba->fc_eventTag,
3345 phba->pport->port_state, vport->fc_flag);
3347 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3348 "1305 Link Down Event x%x received "
3349 "Data: x%x x%x x%x x%x x%x\n",
3350 la->eventTag, phba->fc_eventTag,
3351 phba->pport->port_state, vport->fc_flag,
3352 bf_get(lpfc_mbx_read_top_mm, la),
3353 bf_get(lpfc_mbx_read_top_fa, la));
3354 lpfc_mbx_issue_link_down(phba);
3356 if ((phba->sli.sli_flag & LPFC_MENLO_MAINT) &&
3357 ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP))) {
3358 if (phba->link_state != LPFC_LINK_DOWN) {
3359 phba->fc_stat.LinkDown++;
3360 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3361 "1312 Link Down Event x%x received "
3362 "Data: x%x x%x x%x\n",
3363 la->eventTag, phba->fc_eventTag,
3364 phba->pport->port_state, vport->fc_flag);
3365 lpfc_mbx_issue_link_down(phba);
3367 lpfc_enable_la(phba);
3369 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3370 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3371 "Data: x%x x%x x%x\n",
3372 la->eventTag, phba->fc_eventTag,
3373 phba->pport->port_state, vport->fc_flag);
3375 * The cmnd that triggered this will be waiting for this
3378 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3379 if (phba->wait_4_mlo_maint_flg) {
3380 phba->wait_4_mlo_maint_flg = 0;
3381 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3385 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3386 bf_get(lpfc_mbx_read_top_fa, la)) {
3387 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3388 lpfc_issue_clear_la(phba, vport);
3389 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3391 bf_get(lpfc_mbx_read_top_fa, la));
3394 lpfc_mbx_cmpl_read_topology_free_mbuf:
3395 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3397 mempool_free(pmb, phba->mbox_mem_pool);
3402 * This routine handles processing a REG_LOGIN mailbox
3403 * command upon completion. It is setup in the LPFC_MBOXQ
3404 * as the completion routine when the command is
3405 * handed off to the SLI layer.
3408 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3410 struct lpfc_vport *vport = pmb->vport;
3411 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3412 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3415 pmb->context1 = NULL;
3416 pmb->context2 = NULL;
3418 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3419 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3421 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3422 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3423 /* We rcvd a rscn after issuing this
3424 * mbox reg login, we may have cycled
3425 * back through the state and be
3426 * back at reg login state so this
3427 * mbox needs to be ignored becase
3428 * there is another reg login in
3431 spin_lock_irq(shost->host_lock);
3432 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3433 spin_unlock_irq(shost->host_lock);
3435 /* Good status, call state machine */
3436 lpfc_disc_state_machine(vport, ndlp, pmb,
3437 NLP_EVT_CMPL_REG_LOGIN);
3439 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3441 mempool_free(pmb, phba->mbox_mem_pool);
3442 /* decrement the node reference count held for this callback
3451 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3453 MAILBOX_t *mb = &pmb->u.mb;
3454 struct lpfc_vport *vport = pmb->vport;
3455 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3457 switch (mb->mbxStatus) {
3460 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3461 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3464 /* If VPI is busy, reset the HBA */
3466 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3467 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3468 vport->vpi, mb->mbxStatus);
3469 if (!(phba->pport->load_flag & FC_UNLOADING))
3470 lpfc_workq_post_event(phba, NULL, NULL,
3471 LPFC_EVT_RESET_HBA);
3473 spin_lock_irq(shost->host_lock);
3474 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3475 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3476 spin_unlock_irq(shost->host_lock);
3477 vport->unreg_vpi_cmpl = VPORT_OK;
3478 mempool_free(pmb, phba->mbox_mem_pool);
3479 lpfc_cleanup_vports_rrqs(vport, NULL);
3481 * This shost reference might have been taken at the beginning of
3482 * lpfc_vport_delete()
3484 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3485 scsi_host_put(shost);
3489 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3491 struct lpfc_hba *phba = vport->phba;
3495 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3499 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3500 mbox->vport = vport;
3501 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3502 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3503 if (rc == MBX_NOT_FINISHED) {
3504 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3505 "1800 Could not issue unreg_vpi\n");
3506 mempool_free(mbox, phba->mbox_mem_pool);
3507 vport->unreg_vpi_cmpl = VPORT_ERROR;
3514 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3516 struct lpfc_vport *vport = pmb->vport;
3517 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3518 MAILBOX_t *mb = &pmb->u.mb;
3520 switch (mb->mbxStatus) {
3524 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3525 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3527 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3528 spin_lock_irq(shost->host_lock);
3529 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3530 spin_unlock_irq(shost->host_lock);
3531 vport->fc_myDID = 0;
3535 spin_lock_irq(shost->host_lock);
3536 vport->vpi_state |= LPFC_VPI_REGISTERED;
3537 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3538 spin_unlock_irq(shost->host_lock);
3539 vport->num_disc_nodes = 0;
3540 /* go thru NPR list and issue ELS PLOGIs */
3541 if (vport->fc_npr_cnt)
3542 lpfc_els_disc_plogi(vport);
3544 if (!vport->num_disc_nodes) {
3545 spin_lock_irq(shost->host_lock);
3546 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3547 spin_unlock_irq(shost->host_lock);
3548 lpfc_can_disctmo(vport);
3550 vport->port_state = LPFC_VPORT_READY;
3553 mempool_free(pmb, phba->mbox_mem_pool);
3558 * lpfc_create_static_vport - Read HBA config region to create static vports.
3559 * @phba: pointer to lpfc hba data structure.
3561 * This routine issue a DUMP mailbox command for config region 22 to get
3562 * the list of static vports to be created. The function create vports
3563 * based on the information returned from the HBA.
3566 lpfc_create_static_vport(struct lpfc_hba *phba)
3568 LPFC_MBOXQ_t *pmb = NULL;
3570 struct static_vport_info *vport_info;
3571 int mbx_wait_rc = 0, i;
3572 struct fc_vport_identifiers vport_id;
3573 struct fc_vport *new_fc_vport;
3574 struct Scsi_Host *shost;
3575 struct lpfc_vport *vport;
3576 uint16_t offset = 0;
3577 uint8_t *vport_buff;
3578 struct lpfc_dmabuf *mp;
3579 uint32_t byte_count = 0;
3581 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3583 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3584 "0542 lpfc_create_static_vport failed to"
3585 " allocate mailbox memory\n");
3588 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3591 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3593 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3594 "0543 lpfc_create_static_vport failed to"
3595 " allocate vport_info\n");
3596 mempool_free(pmb, phba->mbox_mem_pool);
3600 vport_buff = (uint8_t *) vport_info;
3602 /* free dma buffer from previous round */
3603 if (pmb->context1) {
3604 mp = (struct lpfc_dmabuf *)pmb->context1;
3605 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3608 if (lpfc_dump_static_vport(phba, pmb, offset))
3611 pmb->vport = phba->pport;
3612 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
3615 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
3616 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3617 "0544 lpfc_create_static_vport failed to"
3618 " issue dump mailbox command ret 0x%x "
3620 mbx_wait_rc, mb->mbxStatus);
3624 if (phba->sli_rev == LPFC_SLI_REV4) {
3625 byte_count = pmb->u.mqe.un.mb_words[5];
3626 mp = (struct lpfc_dmabuf *)pmb->context1;
3627 if (byte_count > sizeof(struct static_vport_info) -
3629 byte_count = sizeof(struct static_vport_info)
3631 memcpy(vport_buff + offset, mp->virt, byte_count);
3632 offset += byte_count;
3634 if (mb->un.varDmp.word_cnt >
3635 sizeof(struct static_vport_info) - offset)
3636 mb->un.varDmp.word_cnt =
3637 sizeof(struct static_vport_info)
3639 byte_count = mb->un.varDmp.word_cnt;
3640 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3641 vport_buff + offset,
3644 offset += byte_count;
3647 } while (byte_count &&
3648 offset < sizeof(struct static_vport_info));
3651 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3652 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3653 != VPORT_INFO_REV)) {
3654 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3655 "0545 lpfc_create_static_vport bad"
3656 " information header 0x%x 0x%x\n",
3657 le32_to_cpu(vport_info->signature),
3658 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3663 shost = lpfc_shost_from_vport(phba->pport);
3665 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3666 memset(&vport_id, 0, sizeof(vport_id));
3667 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3668 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3669 if (!vport_id.port_name || !vport_id.node_name)
3672 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3673 vport_id.vport_type = FC_PORTTYPE_NPIV;
3674 vport_id.disable = false;
3675 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3677 if (!new_fc_vport) {
3678 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3679 "0546 lpfc_create_static_vport failed to"
3684 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3685 vport->vport_flag |= STATIC_VPORT;
3690 if (mbx_wait_rc != MBX_TIMEOUT) {
3691 if (pmb->context1) {
3692 mp = (struct lpfc_dmabuf *)pmb->context1;
3693 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3696 mempool_free(pmb, phba->mbox_mem_pool);
3703 * This routine handles processing a Fabric REG_LOGIN mailbox
3704 * command upon completion. It is setup in the LPFC_MBOXQ
3705 * as the completion routine when the command is
3706 * handed off to the SLI layer.
3709 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3711 struct lpfc_vport *vport = pmb->vport;
3712 MAILBOX_t *mb = &pmb->u.mb;
3713 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3714 struct lpfc_nodelist *ndlp;
3715 struct Scsi_Host *shost;
3717 ndlp = (struct lpfc_nodelist *) pmb->context2;
3718 pmb->context1 = NULL;
3719 pmb->context2 = NULL;
3721 if (mb->mbxStatus) {
3722 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3723 "0258 Register Fabric login error: 0x%x\n",
3725 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3727 mempool_free(pmb, phba->mbox_mem_pool);
3729 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3730 /* FLOGI failed, use loop map to make discovery list */
3731 lpfc_disc_list_loopmap(vport);
3733 /* Start discovery */
3734 lpfc_disc_start(vport);
3735 /* Decrement the reference count to ndlp after the
3736 * reference to the ndlp are done.
3742 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3743 /* Decrement the reference count to ndlp after the reference
3744 * to the ndlp are done.
3750 if (phba->sli_rev < LPFC_SLI_REV4)
3751 ndlp->nlp_rpi = mb->un.varWords[0];
3752 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3753 ndlp->nlp_type |= NLP_FABRIC;
3754 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3756 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3757 /* when physical port receive logo donot start
3758 * vport discovery */
3759 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3760 lpfc_start_fdiscs(phba);
3762 shost = lpfc_shost_from_vport(vport);
3763 spin_lock_irq(shost->host_lock);
3764 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
3765 spin_unlock_irq(shost->host_lock);
3767 lpfc_do_scr_ns_plogi(phba, vport);
3770 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3772 mempool_free(pmb, phba->mbox_mem_pool);
3774 /* Drop the reference count from the mbox at the end after
3775 * all the current reference to the ndlp have been done.
3782 * This routine handles processing a NameServer REG_LOGIN mailbox
3783 * command upon completion. It is setup in the LPFC_MBOXQ
3784 * as the completion routine when the command is
3785 * handed off to the SLI layer.
3788 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3790 MAILBOX_t *mb = &pmb->u.mb;
3791 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3792 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3793 struct lpfc_vport *vport = pmb->vport;
3795 pmb->context1 = NULL;
3796 pmb->context2 = NULL;
3798 if (mb->mbxStatus) {
3800 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3801 "0260 Register NameServer error: 0x%x\n",
3803 /* decrement the node reference count held for this
3804 * callback function.
3807 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3809 mempool_free(pmb, phba->mbox_mem_pool);
3811 /* If no other thread is using the ndlp, free it */
3812 lpfc_nlp_not_used(ndlp);
3814 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3816 * RegLogin failed, use loop map to make discovery
3819 lpfc_disc_list_loopmap(vport);
3821 /* Start discovery */
3822 lpfc_disc_start(vport);
3825 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3829 if (phba->sli_rev < LPFC_SLI_REV4)
3830 ndlp->nlp_rpi = mb->un.varWords[0];
3831 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3832 ndlp->nlp_type |= NLP_FABRIC;
3833 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
3835 if (vport->port_state < LPFC_VPORT_READY) {
3836 /* Link up discovery requires Fabric registration. */
3837 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
3838 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3839 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3840 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3841 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3843 /* Issue SCR just before NameServer GID_FT Query */
3844 lpfc_issue_els_scr(vport, SCR_DID, 0);
3847 vport->fc_ns_retry = 0;
3848 /* Good status, issue CT Request to NameServer */
3849 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
3850 /* Cannot issue NameServer Query, so finish up discovery */
3854 /* decrement the node reference count held for this
3855 * callback function.
3858 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3860 mempool_free(pmb, phba->mbox_mem_pool);
3866 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3868 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3869 struct fc_rport *rport;
3870 struct lpfc_rport_data *rdata;
3871 struct fc_rport_identifiers rport_ids;
3872 struct lpfc_hba *phba = vport->phba;
3874 /* Remote port has reappeared. Re-register w/ FC transport */
3875 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3876 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
3877 rport_ids.port_id = ndlp->nlp_DID;
3878 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
3881 * We leave our node pointer in rport->dd_data when we unregister a
3882 * FCP target port. But fc_remote_port_add zeros the space to which
3883 * rport->dd_data points. So, if we're reusing a previously
3884 * registered port, drop the reference that we took the last time we
3885 * registered the port.
3887 if (ndlp->rport && ndlp->rport->dd_data &&
3888 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
3891 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3892 "rport add: did:x%x flg:x%x type x%x",
3893 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3895 /* Don't add the remote port if unloading. */
3896 if (vport->load_flag & FC_UNLOADING)
3899 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
3900 if (!rport || !get_device(&rport->dev)) {
3901 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3902 "Warning: fc_remote_port_add failed\n");
3906 /* initialize static port data */
3907 rport->maxframe_size = ndlp->nlp_maxframe;
3908 rport->supported_classes = ndlp->nlp_class_sup;
3909 rdata = rport->dd_data;
3910 rdata->pnode = lpfc_nlp_get(ndlp);
3912 if (ndlp->nlp_type & NLP_FCP_TARGET)
3913 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3914 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3915 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3917 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3918 fc_remote_port_rolechg(rport, rport_ids.roles);
3920 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3921 "3183 rport register x%06x, rport %p role x%x\n",
3922 ndlp->nlp_DID, rport, rport_ids.roles);
3924 if ((rport->scsi_target_id != -1) &&
3925 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
3926 ndlp->nlp_sid = rport->scsi_target_id;
3932 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
3934 struct fc_rport *rport = ndlp->rport;
3936 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
3937 "rport delete: did:x%x flg:x%x type x%x",
3938 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3940 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3941 "3184 rport unregister x%06x, rport %p\n",
3942 ndlp->nlp_DID, rport);
3944 fc_remote_port_delete(rport);
3950 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
3952 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3954 spin_lock_irq(shost->host_lock);
3956 case NLP_STE_UNUSED_NODE:
3957 vport->fc_unused_cnt += count;
3959 case NLP_STE_PLOGI_ISSUE:
3960 vport->fc_plogi_cnt += count;
3962 case NLP_STE_ADISC_ISSUE:
3963 vport->fc_adisc_cnt += count;
3965 case NLP_STE_REG_LOGIN_ISSUE:
3966 vport->fc_reglogin_cnt += count;
3968 case NLP_STE_PRLI_ISSUE:
3969 vport->fc_prli_cnt += count;
3971 case NLP_STE_UNMAPPED_NODE:
3972 vport->fc_unmap_cnt += count;
3974 case NLP_STE_MAPPED_NODE:
3975 vport->fc_map_cnt += count;
3977 case NLP_STE_NPR_NODE:
3978 if (vport->fc_npr_cnt == 0 && count == -1)
3979 vport->fc_npr_cnt = 0;
3981 vport->fc_npr_cnt += count;
3984 spin_unlock_irq(shost->host_lock);
3988 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3989 int old_state, int new_state)
3991 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3993 if (new_state == NLP_STE_UNMAPPED_NODE) {
3994 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3995 ndlp->nlp_type |= NLP_FC_NODE;
3997 if (new_state == NLP_STE_MAPPED_NODE)
3998 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3999 if (new_state == NLP_STE_NPR_NODE)
4000 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4002 /* Transport interface */
4003 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
4004 old_state == NLP_STE_UNMAPPED_NODE)) {
4005 vport->phba->nport_event_cnt++;
4006 lpfc_unregister_remote_port(ndlp);
4009 if (new_state == NLP_STE_MAPPED_NODE ||
4010 new_state == NLP_STE_UNMAPPED_NODE) {
4011 vport->phba->nport_event_cnt++;
4013 * Tell the fc transport about the port, if we haven't
4014 * already. If we have, and it's a scsi entity, be
4015 * sure to unblock any attached scsi devices
4017 lpfc_register_remote_port(vport, ndlp);
4019 if ((new_state == NLP_STE_MAPPED_NODE) &&
4020 (vport->stat_data_enabled)) {
4022 * A new target is discovered, if there is no buffer for
4023 * statistical data collection allocate buffer.
4025 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4026 sizeof(struct lpfc_scsicmd_bkt),
4029 if (!ndlp->lat_data)
4030 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
4031 "0286 lpfc_nlp_state_cleanup failed to "
4032 "allocate statistical data buffer DID "
4033 "0x%x\n", ndlp->nlp_DID);
4036 * if we added to Mapped list, but the remote port
4037 * registration failed or assigned a target id outside
4038 * our presentable range - move the node to the
4041 if (new_state == NLP_STE_MAPPED_NODE &&
4043 ndlp->rport->scsi_target_id == -1 ||
4044 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4045 spin_lock_irq(shost->host_lock);
4046 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4047 spin_unlock_irq(shost->host_lock);
4048 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4053 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4055 static char *states[] = {
4056 [NLP_STE_UNUSED_NODE] = "UNUSED",
4057 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4058 [NLP_STE_ADISC_ISSUE] = "ADISC",
4059 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4060 [NLP_STE_PRLI_ISSUE] = "PRLI",
4061 [NLP_STE_LOGO_ISSUE] = "LOGO",
4062 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4063 [NLP_STE_MAPPED_NODE] = "MAPPED",
4064 [NLP_STE_NPR_NODE] = "NPR",
4067 if (state < NLP_STE_MAX_STATE && states[state])
4068 strlcpy(buffer, states[state], size);
4070 snprintf(buffer, size, "unknown (%d)", state);
4075 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4078 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4079 int old_state = ndlp->nlp_state;
4080 char name1[16], name2[16];
4082 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4083 "0904 NPort state transition x%06x, %s -> %s\n",
4085 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4086 lpfc_nlp_state_name(name2, sizeof(name2), state));
4088 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4089 "node statechg did:x%x old:%d ste:%d",
4090 ndlp->nlp_DID, old_state, state);
4092 if (old_state == NLP_STE_NPR_NODE &&
4093 state != NLP_STE_NPR_NODE)
4094 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4095 if (old_state == NLP_STE_UNMAPPED_NODE) {
4096 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4097 ndlp->nlp_type &= ~NLP_FC_NODE;
4100 if (list_empty(&ndlp->nlp_listp)) {
4101 spin_lock_irq(shost->host_lock);
4102 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4103 spin_unlock_irq(shost->host_lock);
4104 } else if (old_state)
4105 lpfc_nlp_counters(vport, old_state, -1);
4107 ndlp->nlp_state = state;
4108 lpfc_nlp_counters(vport, state, 1);
4109 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4113 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4115 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4117 if (list_empty(&ndlp->nlp_listp)) {
4118 spin_lock_irq(shost->host_lock);
4119 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4120 spin_unlock_irq(shost->host_lock);
4125 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4127 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4129 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4130 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4131 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4132 spin_lock_irq(shost->host_lock);
4133 list_del_init(&ndlp->nlp_listp);
4134 spin_unlock_irq(shost->host_lock);
4135 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4136 NLP_STE_UNUSED_NODE);
4140 lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4142 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4143 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4144 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4145 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4146 NLP_STE_UNUSED_NODE);
4149 * lpfc_initialize_node - Initialize all fields of node object
4150 * @vport: Pointer to Virtual Port object.
4151 * @ndlp: Pointer to FC node object.
4152 * @did: FC_ID of the node.
4154 * This function is always called when node object need to be initialized.
4155 * It initializes all the fields of the node object. Although the reference
4156 * to phba from @ndlp can be obtained indirectly through it's reference to
4157 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4158 * to the life-span of the @ndlp might go beyond the existence of @vport as
4159 * the final release of ndlp is determined by its reference count. And, the
4160 * operation on @ndlp needs the reference to phba.
4163 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4166 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4167 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4168 init_timer(&ndlp->nlp_delayfunc);
4169 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
4170 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
4171 ndlp->nlp_DID = did;
4172 ndlp->vport = vport;
4173 ndlp->phba = vport->phba;
4174 ndlp->nlp_sid = NLP_NO_SID;
4175 kref_init(&ndlp->kref);
4176 NLP_INT_NODE_ACT(ndlp);
4177 atomic_set(&ndlp->cmd_pending, 0);
4178 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4181 struct lpfc_nodelist *
4182 lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4185 struct lpfc_hba *phba = vport->phba;
4187 unsigned long flags;
4188 unsigned long *active_rrqs_xri_bitmap = NULL;
4193 spin_lock_irqsave(&phba->ndlp_lock, flags);
4194 /* The ndlp should not be in memory free mode */
4195 if (NLP_CHK_FREE_REQ(ndlp)) {
4196 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4197 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4198 "0277 lpfc_enable_node: ndlp:x%p "
4199 "usgmap:x%x refcnt:%d\n",
4200 (void *)ndlp, ndlp->nlp_usg_map,
4201 atomic_read(&ndlp->kref.refcount));
4204 /* The ndlp should not already be in active mode */
4205 if (NLP_CHK_NODE_ACT(ndlp)) {
4206 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4207 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4208 "0278 lpfc_enable_node: ndlp:x%p "
4209 "usgmap:x%x refcnt:%d\n",
4210 (void *)ndlp, ndlp->nlp_usg_map,
4211 atomic_read(&ndlp->kref.refcount));
4215 /* Keep the original DID */
4216 did = ndlp->nlp_DID;
4217 if (phba->sli_rev == LPFC_SLI_REV4)
4218 active_rrqs_xri_bitmap = ndlp->active_rrqs_xri_bitmap;
4220 /* re-initialize ndlp except of ndlp linked list pointer */
4221 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
4222 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
4223 lpfc_initialize_node(vport, ndlp, did);
4225 if (phba->sli_rev == LPFC_SLI_REV4)
4226 ndlp->active_rrqs_xri_bitmap = active_rrqs_xri_bitmap;
4228 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4229 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4230 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
4233 if (state != NLP_STE_UNUSED_NODE)
4234 lpfc_nlp_set_state(vport, ndlp, state);
4236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4237 "node enable: did:x%x",
4238 ndlp->nlp_DID, 0, 0);
4243 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4246 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4247 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4248 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4249 * until ALL other outstanding threads have completed. We check
4250 * that the ndlp not already in the UNUSED state before we proceed.
4252 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4254 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4255 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4256 lpfc_cleanup_vports_rrqs(vport, ndlp);
4262 * Start / ReStart rescue timer for Discovery / RSCN handling
4265 lpfc_set_disctmo(struct lpfc_vport *vport)
4267 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4268 struct lpfc_hba *phba = vport->phba;
4271 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4272 /* For FAN, timeout should be greater than edtov */
4273 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4275 /* Normal discovery timeout should be > than ELS/CT timeout
4276 * FC spec states we need 3 * ratov for CT requests
4278 tmo = ((phba->fc_ratov * 3) + 3);
4282 if (!timer_pending(&vport->fc_disctmo)) {
4283 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4284 "set disc timer: tmo:x%x state:x%x flg:x%x",
4285 tmo, vport->port_state, vport->fc_flag);
4288 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
4289 spin_lock_irq(shost->host_lock);
4290 vport->fc_flag |= FC_DISC_TMO;
4291 spin_unlock_irq(shost->host_lock);
4293 /* Start Discovery Timer state <hba_state> */
4294 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4295 "0247 Start Discovery Timer state x%x "
4296 "Data: x%x x%lx x%x x%x\n",
4297 vport->port_state, tmo,
4298 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
4299 vport->fc_adisc_cnt);
4305 * Cancel rescue timer for Discovery / RSCN handling
4308 lpfc_can_disctmo(struct lpfc_vport *vport)
4310 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4311 unsigned long iflags;
4313 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4314 "can disc timer: state:x%x rtry:x%x flg:x%x",
4315 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4317 /* Turn off discovery timer if its running */
4318 if (vport->fc_flag & FC_DISC_TMO) {
4319 spin_lock_irqsave(shost->host_lock, iflags);
4320 vport->fc_flag &= ~FC_DISC_TMO;
4321 spin_unlock_irqrestore(shost->host_lock, iflags);
4322 del_timer_sync(&vport->fc_disctmo);
4323 spin_lock_irqsave(&vport->work_port_lock, iflags);
4324 vport->work_port_events &= ~WORKER_DISC_TMO;
4325 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
4328 /* Cancel Discovery Timer state <hba_state> */
4329 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4330 "0248 Cancel Discovery Timer state x%x "
4331 "Data: x%x x%x x%x\n",
4332 vport->port_state, vport->fc_flag,
4333 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
4338 * Check specified ring for outstanding IOCB on the SLI queue
4339 * Return true if iocb matches the specified nport
4342 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
4343 struct lpfc_sli_ring *pring,
4344 struct lpfc_iocbq *iocb,
4345 struct lpfc_nodelist *ndlp)
4347 struct lpfc_sli *psli = &phba->sli;
4348 IOCB_t *icmd = &iocb->iocb;
4349 struct lpfc_vport *vport = ndlp->vport;
4351 if (iocb->vport != vport)
4354 if (pring->ringno == LPFC_ELS_RING) {
4355 switch (icmd->ulpCommand) {
4356 case CMD_GEN_REQUEST64_CR:
4357 if (iocb->context_un.ndlp == ndlp)
4359 case CMD_ELS_REQUEST64_CR:
4360 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4362 case CMD_XMIT_ELS_RSP64_CX:
4363 if (iocb->context1 == (uint8_t *) ndlp)
4366 } else if (pring->ringno == psli->extra_ring) {
4368 } else if (pring->ringno == psli->fcp_ring) {
4369 /* Skip match check if waiting to relogin to FCP target */
4370 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4371 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
4374 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
4377 } else if (pring->ringno == psli->next_ring) {
4384 * Free resources / clean up outstanding I/Os
4385 * associated with nlp_rpi in the LPFC_NODELIST entry.
4388 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
4390 LIST_HEAD(completions);
4391 struct lpfc_sli *psli;
4392 struct lpfc_sli_ring *pring;
4393 struct lpfc_iocbq *iocb, *next_iocb;
4396 lpfc_fabric_abort_nport(ndlp);
4399 * Everything that matches on txcmplq will be returned
4400 * by firmware with a no rpi error.
4403 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4404 /* Now process each ring */
4405 for (i = 0; i < psli->num_rings; i++) {
4406 pring = &psli->ring[i];
4408 spin_lock_irq(&phba->hbalock);
4409 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
4412 * Check to see if iocb matches the nport we are
4415 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
4417 /* It matches, so deque and call compl
4419 list_move_tail(&iocb->list,
4423 spin_unlock_irq(&phba->hbalock);
4427 /* Cancel all the IOCBs from the completions list */
4428 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4435 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
4436 * @phba: Pointer to HBA context object.
4437 * @pmb: Pointer to mailbox object.
4439 * This function will issue an ELS LOGO command after completing
4443 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4445 struct lpfc_vport *vport = pmb->vport;
4446 struct lpfc_nodelist *ndlp;
4448 ndlp = (struct lpfc_nodelist *)(pmb->context1);
4451 lpfc_issue_els_logo(vport, ndlp, 0);
4452 mempool_free(pmb, phba->mbox_mem_pool);
4456 * Free rpi associated with LPFC_NODELIST entry.
4457 * This routine is called from lpfc_freenode(), when we are removing
4458 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4459 * LOGO that completes successfully, and we are waiting to PLOGI back
4460 * to the remote NPort. In addition, it is called after we receive
4461 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4462 * we are waiting to PLOGI back to the remote NPort.
4465 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4467 struct lpfc_hba *phba = vport->phba;
4472 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4473 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
4474 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
4475 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4476 "3366 RPI x%x needs to be "
4477 "unregistered nlp_flag x%x "
4479 ndlp->nlp_rpi, ndlp->nlp_flag,
4481 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4483 /* SLI4 ports require the physical rpi value. */
4484 rpi = ndlp->nlp_rpi;
4485 if (phba->sli_rev == LPFC_SLI_REV4)
4486 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
4488 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
4489 mbox->vport = vport;
4490 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
4491 mbox->context1 = ndlp;
4492 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
4494 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4497 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4498 if (rc == MBX_NOT_FINISHED)
4499 mempool_free(mbox, phba->mbox_mem_pool);
4501 lpfc_no_rpi(phba, ndlp);
4503 if (phba->sli_rev != LPFC_SLI_REV4)
4505 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
4506 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4513 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4514 * @phba: pointer to lpfc hba data structure.
4516 * This routine is invoked to unregister all the currently registered RPIs
4520 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4522 struct lpfc_vport **vports;
4523 struct lpfc_nodelist *ndlp;
4524 struct Scsi_Host *shost;
4527 vports = lpfc_create_vport_work_array(phba);
4529 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4530 "2884 Vport array allocation failed \n");
4533 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4534 shost = lpfc_shost_from_vport(vports[i]);
4535 spin_lock_irq(shost->host_lock);
4536 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
4537 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
4538 /* The mempool_alloc might sleep */
4539 spin_unlock_irq(shost->host_lock);
4540 lpfc_unreg_rpi(vports[i], ndlp);
4541 spin_lock_irq(shost->host_lock);
4544 spin_unlock_irq(shost->host_lock);
4546 lpfc_destroy_vport_work_array(phba, vports);
4550 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4552 struct lpfc_hba *phba = vport->phba;
4556 if (phba->sli_rev == LPFC_SLI_REV4) {
4557 lpfc_sli4_unreg_all_rpis(vport);
4561 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4563 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
4565 mbox->vport = vport;
4566 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4567 mbox->context1 = NULL;
4568 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4569 if (rc != MBX_TIMEOUT)
4570 mempool_free(mbox, phba->mbox_mem_pool);
4572 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4573 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4574 "1836 Could not issue "
4575 "unreg_login(all_rpis) status %d\n", rc);
4580 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4582 struct lpfc_hba *phba = vport->phba;
4586 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4588 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
4590 mbox->vport = vport;
4591 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4592 mbox->context1 = NULL;
4593 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
4594 if (rc != MBX_TIMEOUT)
4595 mempool_free(mbox, phba->mbox_mem_pool);
4597 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4598 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4599 "1815 Could not issue "
4600 "unreg_did (default rpis) status %d\n",
4606 * Free resources associated with LPFC_NODELIST entry
4607 * so it can be freed.
4610 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4612 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4613 struct lpfc_hba *phba = vport->phba;
4614 LPFC_MBOXQ_t *mb, *nextmb;
4615 struct lpfc_dmabuf *mp;
4617 /* Cleanup node for NPort <nlp_DID> */
4618 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4619 "0900 Cleanup node for NPort x%x "
4620 "Data: x%x x%x x%x\n",
4621 ndlp->nlp_DID, ndlp->nlp_flag,
4622 ndlp->nlp_state, ndlp->nlp_rpi);
4623 if (NLP_CHK_FREE_REQ(ndlp)) {
4624 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4625 "0280 lpfc_cleanup_node: ndlp:x%p "
4626 "usgmap:x%x refcnt:%d\n",
4627 (void *)ndlp, ndlp->nlp_usg_map,
4628 atomic_read(&ndlp->kref.refcount));
4629 lpfc_dequeue_node(vport, ndlp);
4631 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4632 "0281 lpfc_cleanup_node: ndlp:x%p "
4633 "usgmap:x%x refcnt:%d\n",
4634 (void *)ndlp, ndlp->nlp_usg_map,
4635 atomic_read(&ndlp->kref.refcount));
4636 lpfc_disable_node(vport, ndlp);
4640 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
4642 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4643 if ((mb = phba->sli.mbox_active)) {
4644 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4645 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
4646 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4647 mb->context2 = NULL;
4648 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4652 spin_lock_irq(&phba->hbalock);
4653 /* Cleanup REG_LOGIN completions which are not yet processed */
4654 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4655 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
4656 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
4657 (ndlp != (struct lpfc_nodelist *) mb->context2))
4660 mb->context2 = NULL;
4661 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4664 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
4665 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
4666 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
4667 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4668 mp = (struct lpfc_dmabuf *) (mb->context1);
4670 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
4673 list_del(&mb->list);
4674 mempool_free(mb, phba->mbox_mem_pool);
4675 /* We shall not invoke the lpfc_nlp_put to decrement
4676 * the ndlp reference count as we are in the process
4677 * of lpfc_nlp_release.
4681 spin_unlock_irq(&phba->hbalock);
4683 lpfc_els_abort(phba, ndlp);
4685 spin_lock_irq(shost->host_lock);
4686 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
4687 spin_unlock_irq(shost->host_lock);
4689 ndlp->nlp_last_elscmd = 0;
4690 del_timer_sync(&ndlp->nlp_delayfunc);
4692 list_del_init(&ndlp->els_retry_evt.evt_listp);
4693 list_del_init(&ndlp->dev_loss_evt.evt_listp);
4694 lpfc_cleanup_vports_rrqs(vport, ndlp);
4695 lpfc_unreg_rpi(vport, ndlp);
4701 * Check to see if we can free the nlp back to the freelist.
4702 * If we are in the middle of using the nlp in the discovery state
4703 * machine, defer the free till we reach the end of the state machine.
4706 lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4708 struct lpfc_hba *phba = vport->phba;
4709 struct lpfc_rport_data *rdata;
4713 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4714 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
4715 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
4716 !(ndlp->nlp_flag & NLP_RPI_REGISTERED)) {
4717 /* For this case we need to cleanup the default rpi
4718 * allocated by the firmware.
4720 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4722 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
4723 (uint8_t *) &vport->fc_sparam, mbox, ndlp->nlp_rpi);
4725 mempool_free(mbox, phba->mbox_mem_pool);
4728 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4729 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4730 mbox->vport = vport;
4731 mbox->context2 = ndlp;
4732 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4733 if (rc == MBX_NOT_FINISHED) {
4734 mempool_free(mbox, phba->mbox_mem_pool);
4739 lpfc_cleanup_node(vport, ndlp);
4742 * We can get here with a non-NULL ndlp->rport because when we
4743 * unregister a rport we don't break the rport/node linkage. So if we
4744 * do, make sure we don't leaving any dangling pointers behind.
4747 rdata = ndlp->rport->dd_data;
4748 rdata->pnode = NULL;
4754 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4757 D_ID mydid, ndlpdid, matchdid;
4759 if (did == Bcast_DID)
4762 /* First check for Direct match */
4763 if (ndlp->nlp_DID == did)
4766 /* Next check for area/domain identically equals 0 match */
4767 mydid.un.word = vport->fc_myDID;
4768 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
4772 matchdid.un.word = did;
4773 ndlpdid.un.word = ndlp->nlp_DID;
4774 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4775 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4776 (mydid.un.b.area == matchdid.un.b.area)) {
4777 if ((ndlpdid.un.b.domain == 0) &&
4778 (ndlpdid.un.b.area == 0)) {
4779 if (ndlpdid.un.b.id)
4785 matchdid.un.word = ndlp->nlp_DID;
4786 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4787 (mydid.un.b.area == ndlpdid.un.b.area)) {
4788 if ((matchdid.un.b.domain == 0) &&
4789 (matchdid.un.b.area == 0)) {
4790 if (matchdid.un.b.id)
4798 /* Search for a nodelist entry */
4799 static struct lpfc_nodelist *
4800 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4802 struct lpfc_nodelist *ndlp;
4805 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4806 if (lpfc_matchdid(vport, ndlp, did)) {
4807 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4808 ((uint32_t) ndlp->nlp_xri << 16) |
4809 ((uint32_t) ndlp->nlp_type << 8) |
4810 ((uint32_t) ndlp->nlp_rpi & 0xff));
4811 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4812 "0929 FIND node DID "
4813 "Data: x%p x%x x%x x%x %p\n",
4814 ndlp, ndlp->nlp_DID,
4815 ndlp->nlp_flag, data1,
4816 ndlp->active_rrqs_xri_bitmap);
4821 /* FIND node did <did> NOT FOUND */
4822 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4823 "0932 FIND node did x%x NOT FOUND.\n", did);
4827 struct lpfc_nodelist *
4828 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
4830 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4831 struct lpfc_nodelist *ndlp;
4832 unsigned long iflags;
4834 spin_lock_irqsave(shost->host_lock, iflags);
4835 ndlp = __lpfc_findnode_did(vport, did);
4836 spin_unlock_irqrestore(shost->host_lock, iflags);
4840 struct lpfc_nodelist *
4841 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
4843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4844 struct lpfc_nodelist *ndlp;
4846 ndlp = lpfc_findnode_did(vport, did);
4848 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4849 lpfc_rscn_payload_check(vport, did) == 0)
4851 ndlp = (struct lpfc_nodelist *)
4852 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
4855 lpfc_nlp_init(vport, ndlp, did);
4856 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4857 spin_lock_irq(shost->host_lock);
4858 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4859 spin_unlock_irq(shost->host_lock);
4861 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4862 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4865 spin_lock_irq(shost->host_lock);
4866 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4867 spin_unlock_irq(shost->host_lock);
4871 if ((vport->fc_flag & FC_RSCN_MODE) &&
4872 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
4873 if (lpfc_rscn_payload_check(vport, did)) {
4874 /* If we've already received a PLOGI from this NPort
4875 * we don't need to try to discover it again.
4877 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
4880 /* Since this node is marked for discovery,
4881 * delay timeout is not needed.
4883 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4884 spin_lock_irq(shost->host_lock);
4885 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4886 spin_unlock_irq(shost->host_lock);
4890 /* If we've already received a PLOGI from this NPort,
4891 * or we are already in the process of discovery on it,
4892 * we don't need to try to discover it again.
4894 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
4895 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4896 ndlp->nlp_flag & NLP_RCV_PLOGI)
4898 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4899 spin_lock_irq(shost->host_lock);
4900 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4901 spin_unlock_irq(shost->host_lock);
4906 /* Build a list of nodes to discover based on the loopmap */
4908 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
4910 struct lpfc_hba *phba = vport->phba;
4912 uint32_t alpa, index;
4914 if (!lpfc_is_link_up(phba))
4917 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
4920 /* Check for loop map present or not */
4921 if (phba->alpa_map[0]) {
4922 for (j = 1; j <= phba->alpa_map[0]; j++) {
4923 alpa = phba->alpa_map[j];
4924 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
4926 lpfc_setup_disc_node(vport, alpa);
4929 /* No alpamap, so try all alpa's */
4930 for (j = 0; j < FC_MAXLOOP; j++) {
4931 /* If cfg_scan_down is set, start from highest
4932 * ALPA (0xef) to lowest (0x1).
4934 if (vport->cfg_scan_down)
4937 index = FC_MAXLOOP - j - 1;
4938 alpa = lpfcAlpaArray[index];
4939 if ((vport->fc_myDID & 0xff) == alpa)
4941 lpfc_setup_disc_node(vport, alpa);
4948 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
4951 struct lpfc_sli *psli = &phba->sli;
4952 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
4953 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
4954 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
4958 * if it's not a physical port or if we already send
4959 * clear_la then don't send it.
4961 if ((phba->link_state >= LPFC_CLEAR_LA) ||
4962 (vport->port_type != LPFC_PHYSICAL_PORT) ||
4963 (phba->sli_rev == LPFC_SLI_REV4))
4966 /* Link up discovery */
4967 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
4968 phba->link_state = LPFC_CLEAR_LA;
4969 lpfc_clear_la(phba, mbox);
4970 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
4971 mbox->vport = vport;
4972 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4973 if (rc == MBX_NOT_FINISHED) {
4974 mempool_free(mbox, phba->mbox_mem_pool);
4975 lpfc_disc_flush_list(vport);
4976 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4977 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4978 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4979 phba->link_state = LPFC_HBA_ERROR;
4984 /* Reg_vpi to tell firmware to resume normal operations */
4986 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4988 LPFC_MBOXQ_t *regvpimbox;
4990 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4992 lpfc_reg_vpi(vport, regvpimbox);
4993 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
4994 regvpimbox->vport = vport;
4995 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
4996 == MBX_NOT_FINISHED) {
4997 mempool_free(regvpimbox, phba->mbox_mem_pool);
5002 /* Start Link up / RSCN discovery on NPR nodes */
5004 lpfc_disc_start(struct lpfc_vport *vport)
5006 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5007 struct lpfc_hba *phba = vport->phba;
5009 uint32_t clear_la_pending;
5012 if (!lpfc_is_link_up(phba)) {
5013 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5014 "3315 Link is not up %x\n",
5019 if (phba->link_state == LPFC_CLEAR_LA)
5020 clear_la_pending = 1;
5022 clear_la_pending = 0;
5024 if (vport->port_state < LPFC_VPORT_READY)
5025 vport->port_state = LPFC_DISC_AUTH;
5027 lpfc_set_disctmo(vport);
5029 if (vport->fc_prevDID == vport->fc_myDID)
5034 vport->fc_prevDID = vport->fc_myDID;
5035 vport->num_disc_nodes = 0;
5037 /* Start Discovery state <hba_state> */
5038 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5039 "0202 Start Discovery hba state x%x "
5040 "Data: x%x x%x x%x\n",
5041 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5042 vport->fc_adisc_cnt);
5044 /* First do ADISCs - if any */
5045 num_sent = lpfc_els_disc_adisc(vport);
5050 /* Register the VPI for SLI3, NPIV only. */
5051 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5052 !(vport->fc_flag & FC_PT2PT) &&
5053 !(vport->fc_flag & FC_RSCN_MODE) &&
5054 (phba->sli_rev < LPFC_SLI_REV4)) {
5055 if (vport->port_type == LPFC_PHYSICAL_PORT)
5056 lpfc_issue_clear_la(phba, vport);
5057 lpfc_issue_reg_vpi(phba, vport);
5062 * For SLI2, we need to set port_state to READY and continue
5065 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5066 /* If we get here, there is nothing to ADISC */
5067 if (vport->port_type == LPFC_PHYSICAL_PORT)
5068 lpfc_issue_clear_la(phba, vport);
5070 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5071 vport->num_disc_nodes = 0;
5072 /* go thru NPR nodes and issue ELS PLOGIs */
5073 if (vport->fc_npr_cnt)
5074 lpfc_els_disc_plogi(vport);
5076 if (!vport->num_disc_nodes) {
5077 spin_lock_irq(shost->host_lock);
5078 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5079 spin_unlock_irq(shost->host_lock);
5080 lpfc_can_disctmo(vport);
5083 vport->port_state = LPFC_VPORT_READY;
5085 /* Next do PLOGIs - if any */
5086 num_sent = lpfc_els_disc_plogi(vport);
5091 if (vport->fc_flag & FC_RSCN_MODE) {
5092 /* Check to see if more RSCNs came in while we
5093 * were processing this one.
5095 if ((vport->fc_rscn_id_cnt == 0) &&
5096 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5097 spin_lock_irq(shost->host_lock);
5098 vport->fc_flag &= ~FC_RSCN_MODE;
5099 spin_unlock_irq(shost->host_lock);
5100 lpfc_can_disctmo(vport);
5102 lpfc_els_handle_rscn(vport);
5109 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5110 * ring the match the sppecified nodelist.
5113 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5115 LIST_HEAD(completions);
5116 struct lpfc_sli *psli;
5118 struct lpfc_iocbq *iocb, *next_iocb;
5119 struct lpfc_sli_ring *pring;
5122 pring = &psli->ring[LPFC_ELS_RING];
5124 /* Error matching iocb on txq or txcmplq
5125 * First check the txq.
5127 spin_lock_irq(&phba->hbalock);
5128 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5129 if (iocb->context1 != ndlp) {
5133 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
5134 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
5136 list_move_tail(&iocb->list, &completions);
5140 /* Next check the txcmplq */
5141 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
5142 if (iocb->context1 != ndlp) {
5146 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
5147 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
5148 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
5151 spin_unlock_irq(&phba->hbalock);
5153 /* Cancel all the IOCBs from the completions list */
5154 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5159 lpfc_disc_flush_list(struct lpfc_vport *vport)
5161 struct lpfc_nodelist *ndlp, *next_ndlp;
5162 struct lpfc_hba *phba = vport->phba;
5164 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
5165 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5167 if (!NLP_CHK_NODE_ACT(ndlp))
5169 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5170 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
5171 lpfc_free_tx(phba, ndlp);
5178 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
5180 lpfc_els_flush_rscn(vport);
5181 lpfc_els_flush_cmd(vport);
5182 lpfc_disc_flush_list(vport);
5185 /*****************************************************************************/
5187 * NAME: lpfc_disc_timeout
5189 * FUNCTION: Fibre Channel driver discovery timeout routine.
5191 * EXECUTION ENVIRONMENT: interrupt only
5199 /*****************************************************************************/
5201 lpfc_disc_timeout(unsigned long ptr)
5203 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5204 struct lpfc_hba *phba = vport->phba;
5205 uint32_t tmo_posted;
5206 unsigned long flags = 0;
5208 if (unlikely(!phba))
5211 spin_lock_irqsave(&vport->work_port_lock, flags);
5212 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
5214 vport->work_port_events |= WORKER_DISC_TMO;
5215 spin_unlock_irqrestore(&vport->work_port_lock, flags);
5218 lpfc_worker_wake_up(phba);
5223 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
5225 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5226 struct lpfc_hba *phba = vport->phba;
5227 struct lpfc_sli *psli = &phba->sli;
5228 struct lpfc_nodelist *ndlp, *next_ndlp;
5229 LPFC_MBOXQ_t *initlinkmbox;
5230 int rc, clrlaerr = 0;
5232 if (!(vport->fc_flag & FC_DISC_TMO))
5235 spin_lock_irq(shost->host_lock);
5236 vport->fc_flag &= ~FC_DISC_TMO;
5237 spin_unlock_irq(shost->host_lock);
5239 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5240 "disc timeout: state:x%x rtry:x%x flg:x%x",
5241 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5243 switch (vport->port_state) {
5245 case LPFC_LOCAL_CFG_LINK:
5246 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
5250 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
5251 "0221 FAN timeout\n");
5252 /* Start discovery by sending FLOGI, clean up old rpis */
5253 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
5255 if (!NLP_CHK_NODE_ACT(ndlp))
5257 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
5259 if (ndlp->nlp_type & NLP_FABRIC) {
5260 /* Clean up the ndlp on Fabric connections */
5261 lpfc_drop_node(vport, ndlp);
5263 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
5264 /* Fail outstanding IO now since device
5265 * is marked for PLOGI.
5267 lpfc_unreg_rpi(vport, ndlp);
5270 if (vport->port_state != LPFC_FLOGI) {
5271 if (phba->sli_rev <= LPFC_SLI_REV3)
5272 lpfc_initial_flogi(vport);
5274 lpfc_issue_init_vfi(vport);
5281 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
5282 /* Initial FLOGI timeout */
5283 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5284 "0222 Initial %s timeout\n",
5285 vport->vpi ? "FDISC" : "FLOGI");
5287 /* Assume no Fabric and go on with discovery.
5288 * Check for outstanding ELS FLOGI to abort.
5291 /* FLOGI failed, so just use loop map to make discovery list */
5292 lpfc_disc_list_loopmap(vport);
5294 /* Start discovery */
5295 lpfc_disc_start(vport);
5298 case LPFC_FABRIC_CFG_LINK:
5299 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
5301 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5302 "0223 Timeout while waiting for "
5303 "NameServer login\n");
5304 /* Next look for NameServer ndlp */
5305 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5306 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5307 lpfc_els_abort(phba, ndlp);
5309 /* ReStart discovery */
5313 /* Check for wait for NameServer Rsp timeout */
5314 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5315 "0224 NameServer Query timeout "
5317 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5319 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
5320 /* Try it one more time */
5321 vport->fc_ns_retry++;
5322 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
5323 vport->fc_ns_retry, 0);
5327 vport->fc_ns_retry = 0;
5331 * Discovery is over.
5332 * set port_state to PORT_READY if SLI2.
5333 * cmpl_reg_vpi will set port_state to READY for SLI3.
5335 if (phba->sli_rev < LPFC_SLI_REV4) {
5336 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5337 lpfc_issue_reg_vpi(phba, vport);
5339 lpfc_issue_clear_la(phba, vport);
5340 vport->port_state = LPFC_VPORT_READY;
5344 /* Setup and issue mailbox INITIALIZE LINK command */
5345 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5346 if (!initlinkmbox) {
5347 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5348 "0206 Device Discovery "
5349 "completion error\n");
5350 phba->link_state = LPFC_HBA_ERROR;
5354 lpfc_linkdown(phba);
5355 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
5356 phba->cfg_link_speed);
5357 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5358 initlinkmbox->vport = vport;
5359 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5360 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
5361 lpfc_set_loopback_flag(phba);
5362 if (rc == MBX_NOT_FINISHED)
5363 mempool_free(initlinkmbox, phba->mbox_mem_pool);
5367 case LPFC_DISC_AUTH:
5368 /* Node Authentication timeout */
5369 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5370 "0227 Node Authentication timeout\n");
5371 lpfc_disc_flush_list(vport);
5374 * set port_state to PORT_READY if SLI2.
5375 * cmpl_reg_vpi will set port_state to READY for SLI3.
5377 if (phba->sli_rev < LPFC_SLI_REV4) {
5378 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
5379 lpfc_issue_reg_vpi(phba, vport);
5380 else { /* NPIV Not enabled */
5381 lpfc_issue_clear_la(phba, vport);
5382 vport->port_state = LPFC_VPORT_READY;
5387 case LPFC_VPORT_READY:
5388 if (vport->fc_flag & FC_RSCN_MODE) {
5389 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5390 "0231 RSCN timeout Data: x%x "
5392 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
5394 /* Cleanup any outstanding ELS commands */
5395 lpfc_els_flush_cmd(vport);
5397 lpfc_els_flush_rscn(vport);
5398 lpfc_disc_flush_list(vport);
5403 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5404 "0273 Unexpected discovery timeout, "
5405 "vport State x%x\n", vport->port_state);
5409 switch (phba->link_state) {
5411 /* CLEAR LA timeout */
5412 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5413 "0228 CLEAR LA timeout\n");
5418 lpfc_issue_clear_la(phba, vport);
5420 case LPFC_LINK_UNKNOWN:
5421 case LPFC_WARM_START:
5422 case LPFC_INIT_START:
5423 case LPFC_INIT_MBX_CMDS:
5424 case LPFC_LINK_DOWN:
5425 case LPFC_HBA_ERROR:
5426 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5427 "0230 Unexpected timeout, hba link "
5428 "state x%x\n", phba->link_state);
5432 case LPFC_HBA_READY:
5437 lpfc_disc_flush_list(vport);
5438 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5439 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5440 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5441 vport->port_state = LPFC_VPORT_READY;
5448 * This routine handles processing a NameServer REG_LOGIN mailbox
5449 * command upon completion. It is setup in the LPFC_MBOXQ
5450 * as the completion routine when the command is
5451 * handed off to the SLI layer.
5454 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5456 MAILBOX_t *mb = &pmb->u.mb;
5457 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
5458 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5459 struct lpfc_vport *vport = pmb->vport;
5461 pmb->context1 = NULL;
5462 pmb->context2 = NULL;
5464 if (phba->sli_rev < LPFC_SLI_REV4)
5465 ndlp->nlp_rpi = mb->un.varWords[0];
5466 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
5467 ndlp->nlp_type |= NLP_FABRIC;
5468 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
5471 * Start issuing Fabric-Device Management Interface (FDMI) command to
5472 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
5473 * fdmi-on=2 (supporting RPA/hostnmae)
5476 if (vport->cfg_fdmi_on == 1)
5477 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
5479 mod_timer(&vport->fc_fdmitmo,
5480 jiffies + msecs_to_jiffies(1000 * 60));
5482 /* decrement the node reference count held for this callback
5486 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5488 mempool_free(pmb, phba->mbox_mem_pool);
5494 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5496 uint16_t *rpi = param;
5498 /* check for active node */
5499 if (!NLP_CHK_NODE_ACT(ndlp))
5502 return ndlp->nlp_rpi == *rpi;
5506 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5508 return memcmp(&ndlp->nlp_portname, param,
5509 sizeof(ndlp->nlp_portname)) == 0;
5512 static struct lpfc_nodelist *
5513 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
5515 struct lpfc_nodelist *ndlp;
5517 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5518 if (filter(ndlp, param)) {
5519 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5520 "3185 FIND node filter %p DID "
5521 "Data: x%p x%x x%x\n",
5522 filter, ndlp, ndlp->nlp_DID,
5527 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5528 "3186 FIND node filter %p NOT FOUND.\n", filter);
5533 * This routine looks up the ndlp lists for the given RPI. If rpi found it
5534 * returns the node list element pointer else return NULL.
5536 struct lpfc_nodelist *
5537 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5539 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
5543 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
5544 * returns the node element list pointer else return NULL.
5546 struct lpfc_nodelist *
5547 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
5549 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5550 struct lpfc_nodelist *ndlp;
5552 spin_lock_irq(shost->host_lock);
5553 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5554 spin_unlock_irq(shost->host_lock);
5559 * This routine looks up the ndlp lists for the given RPI. If the rpi
5560 * is found, the routine returns the node element list pointer else
5563 struct lpfc_nodelist *
5564 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
5566 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5567 struct lpfc_nodelist *ndlp;
5569 spin_lock_irq(shost->host_lock);
5570 ndlp = __lpfc_findnode_rpi(vport, rpi);
5571 spin_unlock_irq(shost->host_lock);
5576 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
5577 * @phba: pointer to lpfc hba data structure.
5578 * @vpi: the physical host virtual N_Port identifier.
5580 * This routine finds a vport on a HBA (referred by @phba) through a
5581 * @vpi. The function walks the HBA's vport list and returns the address
5582 * of the vport with the matching @vpi.
5585 * NULL - No vport with the matching @vpi found
5586 * Otherwise - Address to the vport with the matching @vpi.
5589 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5591 struct lpfc_vport *vport;
5592 unsigned long flags;
5595 /* The physical ports are always vpi 0 - translate is unnecessary. */
5598 * Translate the physical vpi to the logical vpi. The
5599 * vport stores the logical vpi.
5601 for (i = 0; i < phba->max_vpi; i++) {
5602 if (vpi == phba->vpi_ids[i])
5606 if (i >= phba->max_vpi) {
5607 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
5608 "2936 Could not find Vport mapped "
5609 "to vpi %d\n", vpi);
5614 spin_lock_irqsave(&phba->hbalock, flags);
5615 list_for_each_entry(vport, &phba->port_list, listentry) {
5616 if (vport->vpi == i) {
5617 spin_unlock_irqrestore(&phba->hbalock, flags);
5621 spin_unlock_irqrestore(&phba->hbalock, flags);
5626 lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5629 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
5631 lpfc_initialize_node(vport, ndlp, did);
5632 INIT_LIST_HEAD(&ndlp->nlp_listp);
5633 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
5634 ndlp->nlp_rpi = lpfc_sli4_alloc_rpi(vport->phba);
5635 ndlp->active_rrqs_xri_bitmap =
5636 mempool_alloc(vport->phba->active_rrq_pool,
5638 if (ndlp->active_rrqs_xri_bitmap)
5639 memset(ndlp->active_rrqs_xri_bitmap, 0,
5640 ndlp->phba->cfg_rrq_xri_bitmap_sz);
5645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5646 "node init: did:x%x",
5647 ndlp->nlp_DID, 0, 0);
5652 /* This routine releases all resources associated with a specifc NPort's ndlp
5653 * and mempool_free's the nodelist.
5656 lpfc_nlp_release(struct kref *kref)
5658 struct lpfc_hba *phba;
5659 unsigned long flags;
5660 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5663 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5664 "node release: did:x%x flg:x%x type:x%x",
5665 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5667 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5668 "0279 lpfc_nlp_release: ndlp:x%p did %x "
5669 "usgmap:x%x refcnt:%d\n",
5670 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map,
5671 atomic_read(&ndlp->kref.refcount));
5673 /* remove ndlp from action. */
5674 lpfc_nlp_remove(ndlp->vport, ndlp);
5676 /* clear the ndlp active flag for all release cases */
5678 spin_lock_irqsave(&phba->ndlp_lock, flags);
5679 NLP_CLR_NODE_ACT(ndlp);
5680 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5681 if (phba->sli_rev == LPFC_SLI_REV4)
5682 lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi);
5684 /* free ndlp memory for final ndlp release */
5685 if (NLP_CHK_FREE_REQ(ndlp)) {
5686 kfree(ndlp->lat_data);
5687 if (phba->sli_rev == LPFC_SLI_REV4)
5688 mempool_free(ndlp->active_rrqs_xri_bitmap,
5689 ndlp->phba->active_rrq_pool);
5690 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
5694 /* This routine bumps the reference count for a ndlp structure to ensure
5695 * that one discovery thread won't free a ndlp while another discovery thread
5698 struct lpfc_nodelist *
5699 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5701 struct lpfc_hba *phba;
5702 unsigned long flags;
5705 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5706 "node get: did:x%x flg:x%x refcnt:x%x",
5707 ndlp->nlp_DID, ndlp->nlp_flag,
5708 atomic_read(&ndlp->kref.refcount));
5709 /* The check of ndlp usage to prevent incrementing the
5710 * ndlp reference count that is in the process of being
5714 spin_lock_irqsave(&phba->ndlp_lock, flags);
5715 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5716 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5717 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5718 "0276 lpfc_nlp_get: ndlp:x%p "
5719 "usgmap:x%x refcnt:%d\n",
5720 (void *)ndlp, ndlp->nlp_usg_map,
5721 atomic_read(&ndlp->kref.refcount));
5724 kref_get(&ndlp->kref);
5725 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5730 /* This routine decrements the reference count for a ndlp structure. If the
5731 * count goes to 0, this indicates the the associated nodelist should be
5732 * freed. Returning 1 indicates the ndlp resource has been released; on the
5733 * other hand, returning 0 indicates the ndlp resource has not been released
5737 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
5739 struct lpfc_hba *phba;
5740 unsigned long flags;
5745 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5746 "node put: did:x%x flg:x%x refcnt:x%x",
5747 ndlp->nlp_DID, ndlp->nlp_flag,
5748 atomic_read(&ndlp->kref.refcount));
5750 spin_lock_irqsave(&phba->ndlp_lock, flags);
5751 /* Check the ndlp memory free acknowledge flag to avoid the
5752 * possible race condition that kref_put got invoked again
5753 * after previous one has done ndlp memory free.
5755 if (NLP_CHK_FREE_ACK(ndlp)) {
5756 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5757 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5758 "0274 lpfc_nlp_put: ndlp:x%p "
5759 "usgmap:x%x refcnt:%d\n",
5760 (void *)ndlp, ndlp->nlp_usg_map,
5761 atomic_read(&ndlp->kref.refcount));
5764 /* Check the ndlp inactivate log flag to avoid the possible
5765 * race condition that kref_put got invoked again after ndlp
5766 * is already in inactivating state.
5768 if (NLP_CHK_IACT_REQ(ndlp)) {
5769 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5770 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5771 "0275 lpfc_nlp_put: ndlp:x%p "
5772 "usgmap:x%x refcnt:%d\n",
5773 (void *)ndlp, ndlp->nlp_usg_map,
5774 atomic_read(&ndlp->kref.refcount));
5777 /* For last put, mark the ndlp usage flags to make sure no
5778 * other kref_get and kref_put on the same ndlp shall get
5779 * in between the process when the final kref_put has been
5780 * invoked on this ndlp.
5782 if (atomic_read(&ndlp->kref.refcount) == 1) {
5783 /* Indicate ndlp is put to inactive state. */
5784 NLP_SET_IACT_REQ(ndlp);
5785 /* Acknowledge ndlp memory free has been seen. */
5786 if (NLP_CHK_FREE_REQ(ndlp))
5787 NLP_SET_FREE_ACK(ndlp);
5789 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5790 /* Note, the kref_put returns 1 when decrementing a reference
5791 * count that was 1, it invokes the release callback function,
5792 * but it still left the reference count as 1 (not actually
5793 * performs the last decrementation). Otherwise, it actually
5794 * decrements the reference count and returns 0.
5796 return kref_put(&ndlp->kref, lpfc_nlp_release);
5799 /* This routine free's the specified nodelist if it is not in use
5800 * by any other discovery thread. This routine returns 1 if the
5801 * ndlp has been freed. A return value of 0 indicates the ndlp is
5802 * not yet been released.
5805 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5807 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5808 "node not used: did:x%x flg:x%x refcnt:x%x",
5809 ndlp->nlp_DID, ndlp->nlp_flag,
5810 atomic_read(&ndlp->kref.refcount));
5811 if (atomic_read(&ndlp->kref.refcount) == 1)
5812 if (lpfc_nlp_put(ndlp))
5818 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5819 * @phba: Pointer to hba context object.
5821 * This function iterate through all FC nodes associated
5822 * will all vports to check if there is any node with
5823 * fc_rports associated with it. If there is an fc_rport
5824 * associated with the node, then the node is either in
5825 * discovered state or its devloss_timer is pending.
5828 lpfc_fcf_inuse(struct lpfc_hba *phba)
5830 struct lpfc_vport **vports;
5832 struct lpfc_nodelist *ndlp;
5833 struct Scsi_Host *shost;
5835 vports = lpfc_create_vport_work_array(phba);
5837 /* If driver cannot allocate memory, indicate fcf is in use */
5841 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5842 shost = lpfc_shost_from_vport(vports[i]);
5843 spin_lock_irq(shost->host_lock);
5845 * IF the CVL_RCVD bit is not set then we have sent the
5847 * If dev_loss fires while we are waiting we do not want to
5850 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
5851 spin_unlock_irq(shost->host_lock);
5855 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5856 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5857 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5859 spin_unlock_irq(shost->host_lock);
5861 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5863 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5864 "2624 RPI %x DID %x flag %x "
5865 "still logged in\n",
5866 ndlp->nlp_rpi, ndlp->nlp_DID,
5870 spin_unlock_irq(shost->host_lock);
5873 lpfc_destroy_vport_work_array(phba, vports);
5878 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5879 * @phba: Pointer to hba context object.
5880 * @mboxq: Pointer to mailbox object.
5882 * This function frees memory associated with the mailbox command.
5885 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5887 struct lpfc_vport *vport = mboxq->vport;
5888 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5890 if (mboxq->u.mb.mbxStatus) {
5891 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5892 "2555 UNREG_VFI mbxStatus error x%x "
5894 mboxq->u.mb.mbxStatus, vport->port_state);
5896 spin_lock_irq(shost->host_lock);
5897 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5898 spin_unlock_irq(shost->host_lock);
5899 mempool_free(mboxq, phba->mbox_mem_pool);
5904 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5905 * @phba: Pointer to hba context object.
5906 * @mboxq: Pointer to mailbox object.
5908 * This function frees memory associated with the mailbox command.
5911 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5913 struct lpfc_vport *vport = mboxq->vport;
5915 if (mboxq->u.mb.mbxStatus) {
5916 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5917 "2550 UNREG_FCFI mbxStatus error x%x "
5919 mboxq->u.mb.mbxStatus, vport->port_state);
5921 mempool_free(mboxq, phba->mbox_mem_pool);
5926 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
5927 * @phba: Pointer to hba context object.
5929 * This function prepare the HBA for unregistering the currently registered
5930 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
5934 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
5936 struct lpfc_vport **vports;
5937 struct lpfc_nodelist *ndlp;
5938 struct Scsi_Host *shost;
5941 /* Unregister RPIs */
5942 if (lpfc_fcf_inuse(phba))
5943 lpfc_unreg_hba_rpis(phba);
5945 /* At this point, all discovery is aborted */
5946 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
5948 /* Unregister VPIs */
5949 vports = lpfc_create_vport_work_array(phba);
5950 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
5951 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5952 /* Stop FLOGI/FDISC retries */
5953 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
5955 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
5956 lpfc_cleanup_pending_mbox(vports[i]);
5957 if (phba->sli_rev == LPFC_SLI_REV4)
5958 lpfc_sli4_unreg_all_rpis(vports[i]);
5959 lpfc_mbx_unreg_vpi(vports[i]);
5960 shost = lpfc_shost_from_vport(vports[i]);
5961 spin_lock_irq(shost->host_lock);
5962 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
5963 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
5964 spin_unlock_irq(shost->host_lock);
5966 lpfc_destroy_vport_work_array(phba, vports);
5967 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
5968 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
5970 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
5971 lpfc_cleanup_pending_mbox(phba->pport);
5972 if (phba->sli_rev == LPFC_SLI_REV4)
5973 lpfc_sli4_unreg_all_rpis(phba->pport);
5974 lpfc_mbx_unreg_vpi(phba->pport);
5975 shost = lpfc_shost_from_vport(phba->pport);
5976 spin_lock_irq(shost->host_lock);
5977 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
5978 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
5979 spin_unlock_irq(shost->host_lock);
5982 /* Cleanup any outstanding ELS commands */
5983 lpfc_els_flush_all_cmd(phba);
5985 /* Unregister the physical port VFI */
5986 rc = lpfc_issue_unreg_vfi(phba->pport);
5991 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
5992 * @phba: Pointer to hba context object.
5994 * This function issues synchronous unregister FCF mailbox command to HBA to
5995 * unregister the currently registered FCF record. The driver does not reset
5996 * the driver FCF usage state flags.
5998 * Return 0 if successfully issued, none-zero otherwise.
6001 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6006 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6008 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6009 "2551 UNREG_FCFI mbox allocation failed"
6010 "HBA state x%x\n", phba->pport->port_state);
6013 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6014 mbox->vport = phba->pport;
6015 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6016 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6018 if (rc == MBX_NOT_FINISHED) {
6019 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
6020 "2552 Unregister FCFI command failed rc x%x "
6022 rc, phba->pport->port_state);
6029 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6030 * @phba: Pointer to hba context object.
6032 * This function unregisters the currently reigstered FCF. This function
6033 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6036 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6040 /* Preparation for unregistering fcf */
6041 rc = lpfc_unregister_fcf_prep(phba);
6043 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6044 "2748 Failed to prepare for unregistering "
6045 "HBA's FCF record: rc=%d\n", rc);
6049 /* Now, unregister FCF record and reset HBA FCF state */
6050 rc = lpfc_sli4_unregister_fcf(phba);
6053 /* Reset HBA FCF states after successful unregister FCF */
6054 phba->fcf.fcf_flag = 0;
6055 phba->fcf.current_rec.flag = 0;
6058 * If driver is not unloading, check if there is any other
6059 * FCF record that can be used for discovery.
6061 if ((phba->pport->load_flag & FC_UNLOADING) ||
6062 (phba->link_state < LPFC_LINK_UP))
6065 /* This is considered as the initial FCF discovery scan */
6066 spin_lock_irq(&phba->hbalock);
6067 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6068 spin_unlock_irq(&phba->hbalock);
6070 /* Reset FCF roundrobin bmask for new discovery */
6071 lpfc_sli4_clear_fcf_rr_bmask(phba);
6073 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6076 spin_lock_irq(&phba->hbalock);
6077 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6078 spin_unlock_irq(&phba->hbalock);
6079 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
6080 "2553 lpfc_unregister_unused_fcf failed "
6081 "to read FCF record HBA state x%x\n",
6082 phba->pport->port_state);
6087 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6088 * @phba: Pointer to hba context object.
6090 * This function just unregisters the currently reigstered FCF. It does not
6091 * try to find another FCF for discovery.
6094 lpfc_unregister_fcf(struct lpfc_hba *phba)
6098 /* Preparation for unregistering fcf */
6099 rc = lpfc_unregister_fcf_prep(phba);
6101 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
6102 "2749 Failed to prepare for unregistering "
6103 "HBA's FCF record: rc=%d\n", rc);
6107 /* Now, unregister FCF record and reset HBA FCF state */
6108 rc = lpfc_sli4_unregister_fcf(phba);
6111 /* Set proper HBA FCF states after successful unregister FCF */
6112 spin_lock_irq(&phba->hbalock);
6113 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
6114 spin_unlock_irq(&phba->hbalock);
6118 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
6119 * @phba: Pointer to hba context object.
6121 * This function check if there are any connected remote port for the FCF and
6122 * if all the devices are disconnected, this function unregister FCFI.
6123 * This function also tries to use another FCF for discovery.
6126 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
6129 * If HBA is not running in FIP mode, if HBA does not support
6130 * FCoE, if FCF discovery is ongoing, or if FCF has not been
6131 * registered, do nothing.
6133 spin_lock_irq(&phba->hbalock);
6134 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
6135 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
6136 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
6137 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
6138 (phba->pport->port_state == LPFC_FLOGI)) {
6139 spin_unlock_irq(&phba->hbalock);
6142 spin_unlock_irq(&phba->hbalock);
6144 if (lpfc_fcf_inuse(phba))
6147 lpfc_unregister_fcf_rescan(phba);
6151 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
6152 * @phba: Pointer to hba context object.
6153 * @buff: Buffer containing the FCF connection table as in the config
6155 * This function create driver data structure for the FCF connection
6156 * record table read from config region 23.
6159 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
6162 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
6163 struct lpfc_fcf_conn_hdr *conn_hdr;
6164 struct lpfc_fcf_conn_rec *conn_rec;
6165 uint32_t record_count;
6168 /* Free the current connect table */
6169 list_for_each_entry_safe(conn_entry, next_conn_entry,
6170 &phba->fcf_conn_rec_list, list) {
6171 list_del_init(&conn_entry->list);
6175 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
6176 record_count = conn_hdr->length * sizeof(uint32_t)/
6177 sizeof(struct lpfc_fcf_conn_rec);
6179 conn_rec = (struct lpfc_fcf_conn_rec *)
6180 (buff + sizeof(struct lpfc_fcf_conn_hdr));
6182 for (i = 0; i < record_count; i++) {
6183 if (!(conn_rec[i].flags & FCFCNCT_VALID))
6185 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
6188 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6189 "2566 Failed to allocate connection"
6194 memcpy(&conn_entry->conn_rec, &conn_rec[i],
6195 sizeof(struct lpfc_fcf_conn_rec));
6196 list_add_tail(&conn_entry->list,
6197 &phba->fcf_conn_rec_list);
6200 if (!list_empty(&phba->fcf_conn_rec_list)) {
6202 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
6204 conn_rec = &conn_entry->conn_rec;
6205 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6206 "3345 FCF connection list rec[%02d]: "
6207 "flags:x%04x, vtag:x%04x, "
6208 "fabric_name:x%02x:%02x:%02x:%02x:"
6209 "%02x:%02x:%02x:%02x, "
6210 "switch_name:x%02x:%02x:%02x:%02x:"
6211 "%02x:%02x:%02x:%02x\n", i++,
6212 conn_rec->flags, conn_rec->vlan_tag,
6213 conn_rec->fabric_name[0],
6214 conn_rec->fabric_name[1],
6215 conn_rec->fabric_name[2],
6216 conn_rec->fabric_name[3],
6217 conn_rec->fabric_name[4],
6218 conn_rec->fabric_name[5],
6219 conn_rec->fabric_name[6],
6220 conn_rec->fabric_name[7],
6221 conn_rec->switch_name[0],
6222 conn_rec->switch_name[1],
6223 conn_rec->switch_name[2],
6224 conn_rec->switch_name[3],
6225 conn_rec->switch_name[4],
6226 conn_rec->switch_name[5],
6227 conn_rec->switch_name[6],
6228 conn_rec->switch_name[7]);
6234 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
6235 * @phba: Pointer to hba context object.
6236 * @buff: Buffer containing the FCoE parameter data structure.
6238 * This function update driver data structure with config
6239 * parameters read from config region 23.
6242 lpfc_read_fcoe_param(struct lpfc_hba *phba,
6245 struct lpfc_fip_param_hdr *fcoe_param_hdr;
6246 struct lpfc_fcoe_params *fcoe_param;
6248 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
6250 fcoe_param = (struct lpfc_fcoe_params *)
6251 (buff + sizeof(struct lpfc_fip_param_hdr));
6253 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
6254 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
6257 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
6258 phba->valid_vlan = 1;
6259 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
6263 phba->fc_map[0] = fcoe_param->fc_map[0];
6264 phba->fc_map[1] = fcoe_param->fc_map[1];
6265 phba->fc_map[2] = fcoe_param->fc_map[2];
6270 * lpfc_get_rec_conf23 - Get a record type in config region data.
6271 * @buff: Buffer containing config region 23 data.
6272 * @size: Size of the data buffer.
6273 * @rec_type: Record type to be searched.
6275 * This function searches config region data to find the beginning
6276 * of the record specified by record_type. If record found, this
6277 * function return pointer to the record else return NULL.
6280 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
6282 uint32_t offset = 0, rec_length;
6284 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
6285 (size < sizeof(uint32_t)))
6288 rec_length = buff[offset + 1];
6291 * One TLV record has one word header and number of data words
6292 * specified in the rec_length field of the record header.
6294 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
6296 if (buff[offset] == rec_type)
6297 return &buff[offset];
6299 if (buff[offset] == LPFC_REGION23_LAST_REC)
6302 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
6303 rec_length = buff[offset + 1];
6309 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
6310 * @phba: Pointer to lpfc_hba data structure.
6311 * @buff: Buffer containing config region 23 data.
6312 * @size: Size of the data buffer.
6314 * This function parses the FCoE config parameters in config region 23 and
6315 * populate driver data structure with the parameters.
6318 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
6322 uint32_t offset = 0, rec_length;
6326 * If data size is less than 2 words signature and version cannot be
6329 if (size < 2*sizeof(uint32_t))
6332 /* Check the region signature first */
6333 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
6334 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6335 "2567 Config region 23 has bad signature\n");
6341 /* Check the data structure version */
6342 if (buff[offset] != LPFC_REGION23_VERSION) {
6343 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
6344 "2568 Config region 23 has bad version\n");
6349 rec_length = buff[offset + 1];
6351 /* Read FCoE param record */
6352 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6353 size - offset, FCOE_PARAM_TYPE);
6355 lpfc_read_fcoe_param(phba, rec_ptr);
6357 /* Read FCF connection table */
6358 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
6359 size - offset, FCOE_CONN_TBL_TYPE);
6361 lpfc_read_fcf_conn_tbl(phba, rec_ptr);