1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2023 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/kthread.h>
29 #include <linux/interrupt.h>
30 #include <linux/lockdep.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_disc.h"
44 #include "lpfc_sli4.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* AlpaArray for assignment of scsid for scan-down and bind_method */
54 static uint8_t lpfcAlpaArray[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
70 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
71 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
72 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
73 static int lpfc_fcf_inuse(struct lpfc_hba *);
74 static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
75 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba);
76 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba);
79 lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp)
81 if (ndlp->nlp_fc4_type ||
82 ndlp->nlp_type & NLP_FABRIC)
86 /* The source of a terminate rport I/O is either a dev_loss_tmo
87 * event or a call to fc_remove_host. While the rport should be
88 * valid during these downcalls, the transport can call twice
89 * in a single event. This routine provides somoe protection
90 * as the NDLP isn't really free, just released to the pool.
93 lpfc_rport_invalid(struct fc_rport *rport)
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist *ndlp;
99 pr_err("**** %s: NULL rport, exit.\n", __func__);
103 rdata = rport->dd_data;
105 pr_err("**** %s: NULL dd_data on rport x%px SID x%x\n",
106 __func__, rport, rport->scsi_target_id);
112 pr_info("**** %s: NULL ndlp on rport x%px SID x%x\n",
113 __func__, rport, rport->scsi_target_id);
118 pr_err("**** %s: Null vport on ndlp x%px, DID x%x rport x%px "
119 "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport,
120 rport->scsi_target_id);
127 lpfc_terminate_rport_io(struct fc_rport *rport)
129 struct lpfc_rport_data *rdata;
130 struct lpfc_nodelist *ndlp;
131 struct lpfc_vport *vport;
133 if (lpfc_rport_invalid(rport))
136 rdata = rport->dd_data;
139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
140 "rport terminate: sid:x%x did:x%x flg:x%x",
141 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
143 if (ndlp->nlp_sid != NLP_NO_SID)
144 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
148 * This function will be called when dev_loss_tmo fire.
151 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
153 struct lpfc_nodelist *ndlp;
154 struct lpfc_vport *vport;
155 struct lpfc_hba *phba;
156 struct lpfc_work_evt *evtp;
157 unsigned long iflags;
159 ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode;
166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
167 "rport devlosscb: sid:x%x did:x%x flg:x%x",
168 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
170 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
171 "3181 dev_loss_callbk x%06x, rport x%px flg x%x "
172 "load_flag x%x refcnt %u state %d xpt x%x\n",
173 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
174 vport->load_flag, kref_read(&ndlp->kref),
175 ndlp->nlp_state, ndlp->fc4_xpt_flags);
177 /* Don't schedule a worker thread event if the vport is going down. */
178 if (vport->load_flag & FC_UNLOADING) {
179 spin_lock_irqsave(&ndlp->lock, iflags);
182 /* The scsi_transport is done with the rport so lpfc cannot
183 * call to unregister. Remove the scsi transport reference
184 * and clean up the SCSI transport node details.
186 if (ndlp->fc4_xpt_flags & (NLP_XPT_REGD | SCSI_XPT_REGD)) {
187 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
189 /* NVME transport-registered rports need the
190 * NLP_XPT_REGD flag to complete an unregister.
192 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
193 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
194 spin_unlock_irqrestore(&ndlp->lock, iflags);
196 spin_lock_irqsave(&ndlp->lock, iflags);
199 /* Only 1 thread can drop the initial node reference. If
200 * another thread has set NLP_DROPPED, this thread is done.
202 if (!(ndlp->nlp_flag & NLP_DROPPED)) {
203 ndlp->nlp_flag |= NLP_DROPPED;
204 spin_unlock_irqrestore(&ndlp->lock, iflags);
206 spin_lock_irqsave(&ndlp->lock, iflags);
209 spin_unlock_irqrestore(&ndlp->lock, iflags);
213 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
216 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
217 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
218 "6789 rport name %llx != node port name %llx",
220 wwn_to_u64(ndlp->nlp_portname.u.wwn));
222 evtp = &ndlp->dev_loss_evt;
224 if (!list_empty(&evtp->evt_listp)) {
225 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
226 "6790 rport name %llx dev_loss_evt pending\n",
231 spin_lock_irqsave(&ndlp->lock, iflags);
232 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
234 /* If there is a PLOGI in progress, and we are in a
235 * NLP_NPR_2B_DISC state, don't turn off the flag.
237 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
238 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
241 * The backend does not expect any more calls associated with this
242 * rport. Remove the association between rport and ndlp.
244 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
245 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
247 spin_unlock_irqrestore(&ndlp->lock, iflags);
249 if (phba->worker_thread) {
250 /* We need to hold the node by incrementing the reference
251 * count until this queued work is done
253 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
255 spin_lock_irqsave(&phba->hbalock, iflags);
256 if (evtp->evt_arg1) {
257 evtp->evt = LPFC_EVT_DEV_LOSS;
258 list_add_tail(&evtp->evt_listp, &phba->work_list);
259 lpfc_worker_wake_up(phba);
261 spin_unlock_irqrestore(&phba->hbalock, iflags);
263 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
264 "3188 worker thread is stopped %s x%06x, "
265 " rport x%px flg x%x load_flag x%x refcnt "
266 "%d\n", __func__, ndlp->nlp_DID,
267 ndlp->rport, ndlp->nlp_flag,
268 vport->load_flag, kref_read(&ndlp->kref));
269 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD)) {
270 spin_lock_irqsave(&ndlp->lock, iflags);
271 /* Node is in dev loss. No further transaction. */
272 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
273 spin_unlock_irqrestore(&ndlp->lock, iflags);
274 lpfc_disc_state_machine(vport, ndlp, NULL,
284 * lpfc_check_inactive_vmid_one - VMID inactivity checker for a vport
285 * @vport: Pointer to vport context object.
287 * This function checks for idle VMID entries related to a particular vport. If
288 * found unused/idle, free them accordingly.
290 static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport)
293 u32 difftime = 0, r, bucket;
296 struct lpfc_vmid *vmp;
298 write_lock(&vport->vmid_lock);
300 if (!vport->cur_vmid_cnt)
303 /* iterate through the table */
304 hash_for_each(vport->hash_table, bucket, vmp, hnode) {
306 if (vmp->flag & LPFC_VMID_REGISTERED) {
307 /* check if the particular VMID is in use */
308 /* for all available per cpu variable */
309 for_each_possible_cpu(cpu) {
310 /* if last access time is less than timeout */
311 lta = per_cpu_ptr(vmp->last_io_time, cpu);
314 difftime = (jiffies) - (*lta);
315 if ((vport->vmid_inactivity_timeout *
316 JIFFIES_PER_HR) > difftime) {
322 /* if none of the cpus have been used by the vm, */
323 /* remove the entry if already registered */
325 /* mark the entry for deregistration */
326 vmp->flag = LPFC_VMID_DE_REGISTER;
327 write_unlock(&vport->vmid_lock);
328 if (vport->vmid_priority_tagging)
329 r = lpfc_vmid_uvem(vport, vmp, false);
331 r = lpfc_vmid_cmd(vport,
335 /* decrement number of active vms and mark */
336 /* entry in slot as free */
337 write_lock(&vport->vmid_lock);
339 struct lpfc_vmid *ht = vmp;
341 vport->cur_vmid_cnt--;
342 ht->flag = LPFC_VMID_SLOT_FREE;
343 free_percpu(ht->last_io_time);
344 ht->last_io_time = NULL;
345 hash_del(&ht->hnode);
351 write_unlock(&vport->vmid_lock);
355 * lpfc_check_inactive_vmid - VMID inactivity checker
356 * @phba: Pointer to hba context object.
358 * This function is called from the worker thread to determine if an entry in
359 * the VMID table can be released since there was no I/O activity seen from that
360 * particular VM for the specified time. When this happens, the entry in the
361 * table is released and also the resources on the switch cleared.
364 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba)
366 struct lpfc_vport *vport;
367 struct lpfc_vport **vports;
370 vports = lpfc_create_vport_work_array(phba);
374 for (i = 0; i <= phba->max_vports; i++) {
375 if ((!vports[i]) && (i == 0))
382 lpfc_check_inactive_vmid_one(vport);
384 lpfc_destroy_vport_work_array(phba, vports);
388 * lpfc_check_nlp_post_devloss - Check to restore ndlp refcnt after devloss
389 * @vport: Pointer to vport object.
390 * @ndlp: Pointer to remote node object.
392 * If NLP_IN_RECOV_POST_DEV_LOSS flag was set due to outstanding recovery of
393 * node during dev_loss_tmo processing, then this function restores the nlp_put
394 * kref decrement from lpfc_dev_loss_tmo_handler.
397 lpfc_check_nlp_post_devloss(struct lpfc_vport *vport,
398 struct lpfc_nodelist *ndlp)
400 unsigned long iflags;
402 spin_lock_irqsave(&ndlp->lock, iflags);
403 if (ndlp->save_flags & NLP_IN_RECOV_POST_DEV_LOSS) {
404 ndlp->save_flags &= ~NLP_IN_RECOV_POST_DEV_LOSS;
405 spin_unlock_irqrestore(&ndlp->lock, iflags);
407 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_NODE,
408 "8438 Devloss timeout reversed on DID x%x "
409 "refcnt %d ndlp %p flag x%x "
410 "port_state = x%x\n",
411 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp,
412 ndlp->nlp_flag, vport->port_state);
413 spin_lock_irqsave(&ndlp->lock, iflags);
415 spin_unlock_irqrestore(&ndlp->lock, iflags);
419 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
420 * @ndlp: Pointer to remote node object.
422 * This function is called from the worker thread when devloss timeout timer
423 * expires. For SLI4 host, this routine shall return 1 when at lease one
424 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
425 * routine shall return 0 when there is no remote node is still in use of FCF
426 * when devloss timeout happened to this @ndlp.
429 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
431 struct lpfc_vport *vport;
432 struct lpfc_hba *phba;
436 bool recovering = false;
437 struct fc_vport *fc_vport = NULL;
438 unsigned long iflags;
441 name = (uint8_t *)&ndlp->nlp_portname;
444 if (phba->sli_rev == LPFC_SLI_REV4)
445 fcf_inuse = lpfc_fcf_inuse(phba);
447 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
448 "rport devlosstmo:did:x%x type:x%x id:x%x",
449 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
451 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
452 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
453 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
454 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
456 /* If the driver is recovering the rport, ignore devloss. */
457 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
458 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
459 "0284 Devloss timeout Ignored on "
460 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
462 *name, *(name+1), *(name+2), *(name+3),
463 *(name+4), *(name+5), *(name+6), *(name+7),
466 spin_lock_irqsave(&ndlp->lock, iflags);
467 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
468 spin_unlock_irqrestore(&ndlp->lock, iflags);
472 /* Fabric nodes are done. */
473 if (ndlp->nlp_type & NLP_FABRIC) {
474 spin_lock_irqsave(&ndlp->lock, iflags);
476 /* The driver has to account for a race between any fabric
477 * node that's in recovery when dev_loss_tmo expires. When this
478 * happens, the driver has to allow node recovery.
480 switch (ndlp->nlp_DID) {
482 fc_vport = vport->fc_vport;
485 if (fc_vport->vport_state ==
486 FC_VPORT_INITIALIZING)
489 /* Physical port path. */
490 if (phba->hba_flag & HBA_FLOGI_OUTSTANDING)
494 case Fabric_Cntl_DID:
495 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
501 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
502 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE)
506 /* Ensure the nlp_DID at least has the correct prefix.
507 * The fabric domain controller's last three nibbles
508 * vary so we handle it in the default case.
510 if (ndlp->nlp_DID & Fabric_DID_MASK) {
511 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
512 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE)
517 spin_unlock_irqrestore(&ndlp->lock, iflags);
519 /* Mark an NLP_IN_RECOV_POST_DEV_LOSS flag to know if reversing
520 * the following lpfc_nlp_put is necessary after fabric node is
524 lpfc_printf_vlog(vport, KERN_INFO,
525 LOG_DISCOVERY | LOG_NODE,
526 "8436 Devloss timeout marked on "
527 "DID x%x refcnt %d ndlp %p "
528 "flag x%x port_state = x%x\n",
529 ndlp->nlp_DID, kref_read(&ndlp->kref),
530 ndlp, ndlp->nlp_flag,
532 spin_lock_irqsave(&ndlp->lock, iflags);
533 ndlp->save_flags |= NLP_IN_RECOV_POST_DEV_LOSS;
534 spin_unlock_irqrestore(&ndlp->lock, iflags);
535 } else if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
536 /* Fabric node fully recovered before this dev_loss_tmo
537 * queue work is processed. Thus, ignore the
538 * dev_loss_tmo event.
540 lpfc_printf_vlog(vport, KERN_INFO,
541 LOG_DISCOVERY | LOG_NODE,
542 "8437 Devloss timeout ignored on "
543 "DID x%x refcnt %d ndlp %p "
544 "flag x%x port_state = x%x\n",
545 ndlp->nlp_DID, kref_read(&ndlp->kref),
546 ndlp, ndlp->nlp_flag,
551 spin_lock_irqsave(&ndlp->lock, iflags);
552 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
553 spin_unlock_irqrestore(&ndlp->lock, iflags);
558 if (ndlp->nlp_sid != NLP_NO_SID) {
560 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
564 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
565 "0203 Devloss timeout on "
566 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
567 "NPort x%06x Data: x%x x%x x%x refcnt %d\n",
568 *name, *(name+1), *(name+2), *(name+3),
569 *(name+4), *(name+5), *(name+6), *(name+7),
570 ndlp->nlp_DID, ndlp->nlp_flag,
571 ndlp->nlp_state, ndlp->nlp_rpi,
572 kref_read(&ndlp->kref));
574 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
575 "0204 Devloss timeout on "
576 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
577 "NPort x%06x Data: x%x x%x x%x\n",
578 *name, *(name+1), *(name+2), *(name+3),
579 *(name+4), *(name+5), *(name+6), *(name+7),
580 ndlp->nlp_DID, ndlp->nlp_flag,
581 ndlp->nlp_state, ndlp->nlp_rpi);
583 spin_lock_irqsave(&ndlp->lock, iflags);
584 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
585 spin_unlock_irqrestore(&ndlp->lock, iflags);
587 /* If we are devloss, but we are in the process of rediscovering the
588 * ndlp, don't issue a NLP_EVT_DEVICE_RM event.
590 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
591 ndlp->nlp_state <= NLP_STE_PRLI_ISSUE) {
595 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
596 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
601 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba)
603 struct lpfc_vport *vport;
604 struct lpfc_vport **vports;
607 vports = lpfc_create_vport_work_array(phba);
611 for (i = 0; i <= phba->max_vports; i++) {
612 if ((!vports[i]) && (i == 0))
619 if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) {
620 if (!lpfc_issue_els_qfpa(vport))
621 vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA;
624 lpfc_destroy_vport_work_array(phba, vports);
628 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
629 * @phba: Pointer to hba context object.
630 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
631 * @nlp_did: remote node identifer with devloss timeout.
633 * This function is called from the worker thread after invoking devloss
634 * timeout handler and releasing the reference count for the ndlp with
635 * which the devloss timeout was handled for SLI4 host. For the devloss
636 * timeout of the last remote node which had been in use of FCF, when this
637 * routine is invoked, it shall be guaranteed that none of the remote are
638 * in-use of FCF. When devloss timeout to the last remote using the FCF,
639 * if the FIP engine is neither in FCF table scan process nor roundrobin
640 * failover process, the in-use FCF shall be unregistered. If the FIP
641 * engine is in FCF discovery process, the devloss timeout state shall
642 * be set for either the FCF table scan process or roundrobin failover
643 * process to unregister the in-use FCF.
646 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
649 /* If devloss timeout happened to a remote node when FCF had no
650 * longer been in-use, do nothing.
655 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
656 spin_lock_irq(&phba->hbalock);
657 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
658 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
659 spin_unlock_irq(&phba->hbalock);
662 phba->hba_flag |= HBA_DEVLOSS_TMO;
663 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
664 "2847 Last remote node (x%x) using "
665 "FCF devloss tmo\n", nlp_did);
667 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
668 spin_unlock_irq(&phba->hbalock);
669 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
670 "2868 Devloss tmo to FCF rediscovery "
674 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
675 spin_unlock_irq(&phba->hbalock);
676 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
677 "2869 Devloss tmo to idle FIP engine, "
678 "unreg in-use FCF and rescan.\n");
679 /* Unregister in-use FCF and rescan */
680 lpfc_unregister_fcf_rescan(phba);
683 spin_unlock_irq(&phba->hbalock);
684 if (phba->hba_flag & FCF_TS_INPROG)
685 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
686 "2870 FCF table scan in progress\n");
687 if (phba->hba_flag & FCF_RR_INPROG)
688 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
689 "2871 FLOGI roundrobin FCF failover "
692 lpfc_unregister_unused_fcf(phba);
696 * lpfc_alloc_fast_evt - Allocates data structure for posting event
697 * @phba: Pointer to hba context object.
699 * This function is called from the functions which need to post
700 * events from interrupt context. This function allocates data
701 * structure required for posting event. It also keeps track of
702 * number of events pending and prevent event storm when there are
705 struct lpfc_fast_path_event *
706 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
707 struct lpfc_fast_path_event *ret;
709 /* If there are lot of fast event do not exhaust memory due to this */
710 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
713 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
716 atomic_inc(&phba->fast_event_count);
717 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
718 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
724 * lpfc_free_fast_evt - Frees event data structure
725 * @phba: Pointer to hba context object.
726 * @evt: Event object which need to be freed.
728 * This function frees the data structure required for posting
732 lpfc_free_fast_evt(struct lpfc_hba *phba,
733 struct lpfc_fast_path_event *evt) {
735 atomic_dec(&phba->fast_event_count);
740 * lpfc_send_fastpath_evt - Posts events generated from fast path
741 * @phba: Pointer to hba context object.
742 * @evtp: Event data structure.
744 * This function is called from worker thread, when the interrupt
745 * context need to post an event. This function posts the event
746 * to fc transport netlink interface.
749 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
750 struct lpfc_work_evt *evtp)
752 unsigned long evt_category, evt_sub_category;
753 struct lpfc_fast_path_event *fast_evt_data;
755 uint32_t evt_data_size;
756 struct Scsi_Host *shost;
758 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
761 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
762 evt_sub_category = (unsigned long) fast_evt_data->un.
763 fabric_evt.subcategory;
764 shost = lpfc_shost_from_vport(fast_evt_data->vport);
765 if (evt_category == FC_REG_FABRIC_EVENT) {
766 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
767 evt_data = (char *) &fast_evt_data->un.read_check_error;
768 evt_data_size = sizeof(fast_evt_data->un.
770 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
771 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
772 evt_data = (char *) &fast_evt_data->un.fabric_evt;
773 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
775 lpfc_free_fast_evt(phba, fast_evt_data);
778 } else if (evt_category == FC_REG_SCSI_EVENT) {
779 switch (evt_sub_category) {
780 case LPFC_EVENT_QFULL:
781 case LPFC_EVENT_DEVBSY:
782 evt_data = (char *) &fast_evt_data->un.scsi_evt;
783 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
785 case LPFC_EVENT_CHECK_COND:
786 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
787 evt_data_size = sizeof(fast_evt_data->un.
790 case LPFC_EVENT_VARQUEDEPTH:
791 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
792 evt_data_size = sizeof(fast_evt_data->un.
796 lpfc_free_fast_evt(phba, fast_evt_data);
800 lpfc_free_fast_evt(phba, fast_evt_data);
804 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
805 fc_host_post_vendor_event(shost,
806 fc_get_event_number(),
811 lpfc_free_fast_evt(phba, fast_evt_data);
816 lpfc_work_list_done(struct lpfc_hba *phba)
818 struct lpfc_work_evt *evtp = NULL;
819 struct lpfc_nodelist *ndlp;
825 spin_lock_irq(&phba->hbalock);
826 while (!list_empty(&phba->work_list)) {
827 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
829 spin_unlock_irq(&phba->hbalock);
830 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
833 case LPFC_EVT_ELS_RETRY:
834 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
836 lpfc_els_retry_delay_handler(ndlp);
837 free_evt = 0; /* evt is part of ndlp */
839 /* decrement the node reference count held
840 * for this queued work
844 case LPFC_EVT_DEV_LOSS:
845 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
846 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
848 /* decrement the node reference count held for
851 nlp_did = ndlp->nlp_DID;
853 if (phba->sli_rev == LPFC_SLI_REV4)
854 lpfc_sli4_post_dev_loss_tmo_handler(phba,
858 case LPFC_EVT_RECOVER_PORT:
859 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
861 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
864 /* decrement the node reference count held for
869 case LPFC_EVT_ONLINE:
870 if (phba->link_state < LPFC_LINK_DOWN)
871 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
873 *(int *) (evtp->evt_arg1) = 0;
874 complete((struct completion *)(evtp->evt_arg2));
876 case LPFC_EVT_OFFLINE_PREP:
877 if (phba->link_state >= LPFC_LINK_DOWN)
878 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
879 *(int *)(evtp->evt_arg1) = 0;
880 complete((struct completion *)(evtp->evt_arg2));
882 case LPFC_EVT_OFFLINE:
884 lpfc_sli_brdrestart(phba);
885 *(int *)(evtp->evt_arg1) =
886 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
887 lpfc_unblock_mgmt_io(phba);
888 complete((struct completion *)(evtp->evt_arg2));
890 case LPFC_EVT_WARM_START:
892 lpfc_reset_barrier(phba);
893 lpfc_sli_brdreset(phba);
894 lpfc_hba_down_post(phba);
895 *(int *)(evtp->evt_arg1) =
896 lpfc_sli_brdready(phba, HS_MBRDY);
897 lpfc_unblock_mgmt_io(phba);
898 complete((struct completion *)(evtp->evt_arg2));
902 *(int *)(evtp->evt_arg1)
903 = (phba->pport->stopped)
904 ? 0 : lpfc_sli_brdkill(phba);
905 lpfc_unblock_mgmt_io(phba);
906 complete((struct completion *)(evtp->evt_arg2));
908 case LPFC_EVT_FASTPATH_MGMT_EVT:
909 lpfc_send_fastpath_evt(phba, evtp);
912 case LPFC_EVT_RESET_HBA:
913 if (!(phba->pport->load_flag & FC_UNLOADING))
914 lpfc_reset_hba(phba);
919 spin_lock_irq(&phba->hbalock);
921 spin_unlock_irq(&phba->hbalock);
926 lpfc_work_done(struct lpfc_hba *phba)
928 struct lpfc_sli_ring *pring;
929 uint32_t ha_copy, status, control, work_port_events;
930 struct lpfc_vport **vports;
931 struct lpfc_vport *vport;
935 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
936 spin_lock_irq(&phba->hbalock);
937 ha_copy = phba->work_ha;
939 spin_unlock_irq(&phba->hbalock);
943 /* First, try to post the next mailbox command to SLI4 device */
944 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC && !hba_pci_err)
945 lpfc_sli4_post_async_mbox(phba);
947 if (ha_copy & HA_ERATT) {
948 /* Handle the error attention event */
949 lpfc_handle_eratt(phba);
951 if (phba->fw_dump_cmpl) {
952 complete(phba->fw_dump_cmpl);
953 phba->fw_dump_cmpl = NULL;
957 if (ha_copy & HA_MBATT)
958 lpfc_sli_handle_mb_event(phba);
960 if (ha_copy & HA_LATT)
961 lpfc_handle_latt(phba);
963 /* Handle VMID Events */
964 if (lpfc_is_vmid_enabled(phba) && !hba_pci_err) {
965 if (phba->pport->work_port_events &
966 WORKER_CHECK_VMID_ISSUE_QFPA) {
967 lpfc_check_vmid_qfpa_issue(phba);
968 phba->pport->work_port_events &=
969 ~WORKER_CHECK_VMID_ISSUE_QFPA;
971 if (phba->pport->work_port_events &
972 WORKER_CHECK_INACTIVE_VMID) {
973 lpfc_check_inactive_vmid(phba);
974 phba->pport->work_port_events &=
975 ~WORKER_CHECK_INACTIVE_VMID;
979 /* Process SLI4 events */
980 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
981 if (phba->hba_flag & HBA_RRQ_ACTIVE)
982 lpfc_handle_rrq_active(phba);
983 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
984 lpfc_sli4_els_xri_abort_event_proc(phba);
985 if (phba->hba_flag & ASYNC_EVENT)
986 lpfc_sli4_async_event_proc(phba);
987 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
988 spin_lock_irq(&phba->hbalock);
989 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
990 spin_unlock_irq(&phba->hbalock);
991 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
993 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
994 lpfc_sli4_fcf_redisc_event_proc(phba);
997 vports = lpfc_create_vport_work_array(phba);
999 for (i = 0; i <= phba->max_vports; i++) {
1001 * We could have no vports in array if unloading, so if
1002 * this happens then just use the pport
1004 if (vports[i] == NULL && i == 0)
1005 vport = phba->pport;
1010 spin_lock_irq(&vport->work_port_lock);
1011 work_port_events = vport->work_port_events;
1012 vport->work_port_events &= ~work_port_events;
1013 spin_unlock_irq(&vport->work_port_lock);
1016 if (work_port_events & WORKER_DISC_TMO)
1017 lpfc_disc_timeout_handler(vport);
1018 if (work_port_events & WORKER_ELS_TMO)
1019 lpfc_els_timeout_handler(vport);
1020 if (work_port_events & WORKER_HB_TMO)
1021 lpfc_hb_timeout_handler(phba);
1022 if (work_port_events & WORKER_MBOX_TMO)
1023 lpfc_mbox_timeout_handler(phba);
1024 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
1025 lpfc_unblock_fabric_iocbs(phba);
1026 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
1027 lpfc_ramp_down_queue_handler(phba);
1028 if (work_port_events & WORKER_DELAYED_DISC_TMO)
1029 lpfc_delayed_disc_timeout_handler(vport);
1031 lpfc_destroy_vport_work_array(phba, vports);
1033 pring = lpfc_phba_elsring(phba);
1034 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
1035 status >>= (4*LPFC_ELS_RING);
1036 if (pring && (status & HA_RXMASK ||
1037 pring->flag & LPFC_DEFERRED_RING_EVENT ||
1038 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
1039 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
1040 pring->flag |= LPFC_DEFERRED_RING_EVENT;
1041 /* Preserve legacy behavior. */
1042 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
1043 set_bit(LPFC_DATA_READY, &phba->data_flags);
1045 /* Driver could have abort request completed in queue
1046 * when link goes down. Allow for this transition.
1048 if (phba->link_state >= LPFC_LINK_DOWN ||
1049 phba->link_flag & LS_MDS_LOOPBACK) {
1050 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
1051 lpfc_sli_handle_slow_ring_event(phba, pring,
1056 if (phba->sli_rev == LPFC_SLI_REV4)
1057 lpfc_drain_txq(phba);
1059 * Turn on Ring interrupts
1061 if (phba->sli_rev <= LPFC_SLI_REV3) {
1062 spin_lock_irq(&phba->hbalock);
1063 control = readl(phba->HCregaddr);
1064 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
1065 lpfc_debugfs_slow_ring_trc(phba,
1066 "WRK Enable ring: cntl:x%x hacopy:x%x",
1067 control, ha_copy, 0);
1069 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
1070 writel(control, phba->HCregaddr);
1071 readl(phba->HCregaddr); /* flush */
1073 lpfc_debugfs_slow_ring_trc(phba,
1074 "WRK Ring ok: cntl:x%x hacopy:x%x",
1075 control, ha_copy, 0);
1077 spin_unlock_irq(&phba->hbalock);
1080 lpfc_work_list_done(phba);
1084 lpfc_do_work(void *p)
1086 struct lpfc_hba *phba = p;
1089 set_user_nice(current, MIN_NICE);
1090 current->flags |= PF_NOFREEZE;
1091 phba->data_flags = 0;
1093 while (!kthread_should_stop()) {
1094 /* wait and check worker queue activities */
1095 rc = wait_event_interruptible(phba->work_waitq,
1096 (test_and_clear_bit(LPFC_DATA_READY,
1098 || kthread_should_stop()));
1099 /* Signal wakeup shall terminate the worker thread */
1101 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1102 "0433 Wakeup on signal: rc=x%x\n", rc);
1106 /* Attend pending lpfc data processing */
1107 lpfc_work_done(phba);
1109 phba->worker_thread = NULL;
1110 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1111 "0432 Worker thread stopped.\n");
1116 * This is only called to handle FC worker events. Since this a rare
1117 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
1118 * embedding it in the IOCB.
1121 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
1124 struct lpfc_work_evt *evtp;
1125 unsigned long flags;
1128 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
1129 * be queued to worker thread for processing
1131 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
1135 evtp->evt_arg1 = arg1;
1136 evtp->evt_arg2 = arg2;
1139 spin_lock_irqsave(&phba->hbalock, flags);
1140 list_add_tail(&evtp->evt_listp, &phba->work_list);
1141 spin_unlock_irqrestore(&phba->hbalock, flags);
1143 lpfc_worker_wake_up(phba);
1149 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
1151 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1152 struct lpfc_hba *phba = vport->phba;
1153 struct lpfc_nodelist *ndlp, *next_ndlp;
1155 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1156 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
1157 ((vport->port_type == LPFC_NPIV_PORT) &&
1158 ((ndlp->nlp_DID == NameServer_DID) ||
1159 (ndlp->nlp_DID == FDMI_DID) ||
1160 (ndlp->nlp_DID == Fabric_Cntl_DID))))
1161 lpfc_unreg_rpi(vport, ndlp);
1163 /* Leave Fabric nodes alone on link down */
1164 if ((phba->sli_rev < LPFC_SLI_REV4) &&
1165 (!remove && ndlp->nlp_type & NLP_FABRIC))
1168 /* Notify transport of connectivity loss to trigger cleanup. */
1169 if (phba->nvmet_support &&
1170 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
1171 lpfc_nvmet_invalidate_host(phba, ndlp);
1173 lpfc_disc_state_machine(vport, ndlp, NULL,
1176 : NLP_EVT_DEVICE_RECOVERY);
1178 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
1179 if (phba->sli_rev == LPFC_SLI_REV4)
1180 lpfc_sli4_unreg_all_rpis(vport);
1181 lpfc_mbx_unreg_vpi(vport);
1182 spin_lock_irq(shost->host_lock);
1183 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1184 spin_unlock_irq(shost->host_lock);
1189 lpfc_port_link_failure(struct lpfc_vport *vport)
1191 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
1193 /* Cleanup any outstanding received buffers */
1194 lpfc_cleanup_rcv_buffers(vport);
1196 /* Cleanup any outstanding RSCN activity */
1197 lpfc_els_flush_rscn(vport);
1199 /* Cleanup any outstanding ELS commands */
1200 lpfc_els_flush_cmd(vport);
1202 lpfc_cleanup_rpis(vport, 0);
1204 /* Turn off discovery timer if its running */
1205 lpfc_can_disctmo(vport);
1209 lpfc_linkdown_port(struct lpfc_vport *vport)
1211 struct lpfc_hba *phba = vport->phba;
1212 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1214 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1215 fc_host_post_event(shost, fc_get_event_number(),
1216 FCH_EVT_LINKDOWN, 0);
1218 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1219 "Link Down: state:x%x rtry:x%x flg:x%x",
1220 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1222 lpfc_port_link_failure(vport);
1224 /* Stop delayed Nport discovery */
1225 spin_lock_irq(shost->host_lock);
1226 vport->fc_flag &= ~FC_DISC_DELAYED;
1227 spin_unlock_irq(shost->host_lock);
1228 del_timer_sync(&vport->delayed_disc_tmo);
1230 if (phba->sli_rev == LPFC_SLI_REV4 &&
1231 vport->port_type == LPFC_PHYSICAL_PORT &&
1232 phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG) {
1233 /* Assume success on link up */
1234 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
1239 lpfc_linkdown(struct lpfc_hba *phba)
1241 struct lpfc_vport *vport = phba->pport;
1242 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1243 struct lpfc_vport **vports;
1248 if (phba->link_state == LPFC_LINK_DOWN)
1251 /* Block all SCSI stack I/Os */
1252 lpfc_scsi_dev_block(phba);
1253 offline = pci_channel_offline(phba->pcidev);
1255 phba->defer_flogi_acc_flag = false;
1257 /* Clear external loopback plug detected flag */
1258 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
1260 spin_lock_irq(&phba->hbalock);
1261 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1262 spin_unlock_irq(&phba->hbalock);
1263 if (phba->link_state > LPFC_LINK_DOWN) {
1264 phba->link_state = LPFC_LINK_DOWN;
1265 if (phba->sli4_hba.conf_trunk) {
1266 phba->trunk_link.link0.state = 0;
1267 phba->trunk_link.link1.state = 0;
1268 phba->trunk_link.link2.state = 0;
1269 phba->trunk_link.link3.state = 0;
1270 phba->trunk_link.phy_lnk_speed =
1271 LPFC_LINK_SPEED_UNKNOWN;
1272 phba->sli4_hba.link_state.logical_speed =
1273 LPFC_LINK_SPEED_UNKNOWN;
1275 spin_lock_irq(shost->host_lock);
1276 phba->pport->fc_flag &= ~FC_LBIT;
1277 spin_unlock_irq(shost->host_lock);
1279 vports = lpfc_create_vport_work_array(phba);
1280 if (vports != NULL) {
1281 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1282 /* Issue a LINK DOWN event to all nodes */
1283 lpfc_linkdown_port(vports[i]);
1285 vports[i]->fc_myDID = 0;
1287 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1288 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1289 if (phba->nvmet_support)
1290 lpfc_nvmet_update_targetport(phba);
1292 lpfc_nvme_update_localport(vports[i]);
1296 lpfc_destroy_vport_work_array(phba, vports);
1298 /* Clean up any SLI3 firmware default rpi's */
1299 if (phba->sli_rev > LPFC_SLI_REV3 || offline)
1300 goto skip_unreg_did;
1302 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1304 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
1306 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1307 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1308 == MBX_NOT_FINISHED) {
1309 mempool_free(mb, phba->mbox_mem_pool);
1314 /* Setup myDID for link up if we are in pt2pt mode */
1315 if (phba->pport->fc_flag & FC_PT2PT) {
1316 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1318 lpfc_config_link(phba, mb);
1319 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1321 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1322 == MBX_NOT_FINISHED) {
1323 mempool_free(mb, phba->mbox_mem_pool);
1326 spin_lock_irq(shost->host_lock);
1327 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
1328 phba->pport->rcv_flogi_cnt = 0;
1329 spin_unlock_irq(shost->host_lock);
1335 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
1337 struct lpfc_nodelist *ndlp;
1339 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1340 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
1342 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1344 if (ndlp->nlp_type & NLP_FABRIC) {
1345 /* On Linkup its safe to clean up the ndlp
1346 * from Fabric connections.
1348 if (ndlp->nlp_DID != Fabric_DID)
1349 lpfc_unreg_rpi(vport, ndlp);
1350 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1351 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
1352 /* Fail outstanding IO now since device is
1355 lpfc_unreg_rpi(vport, ndlp);
1361 lpfc_linkup_port(struct lpfc_vport *vport)
1363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1364 struct lpfc_hba *phba = vport->phba;
1366 if ((vport->load_flag & FC_UNLOADING) != 0)
1369 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1370 "Link Up: top:x%x speed:x%x flg:x%x",
1371 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1373 /* If NPIV is not enabled, only bring the physical port up */
1374 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1375 (vport != phba->pport))
1378 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1379 fc_host_post_event(shost, fc_get_event_number(),
1382 spin_lock_irq(shost->host_lock);
1383 if (phba->defer_flogi_acc_flag)
1384 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_RSCN_MODE |
1385 FC_NLP_MORE | FC_RSCN_DISCOVERY);
1387 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI |
1388 FC_ABORT_DISCOVERY | FC_RSCN_MODE |
1389 FC_NLP_MORE | FC_RSCN_DISCOVERY);
1390 vport->fc_flag |= FC_NDISC_ACTIVE;
1391 vport->fc_ns_retry = 0;
1392 spin_unlock_irq(shost->host_lock);
1393 lpfc_setup_fdmi_mask(vport);
1395 lpfc_linkup_cleanup_nodes(vport);
1399 lpfc_linkup(struct lpfc_hba *phba)
1401 struct lpfc_vport **vports;
1403 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1405 phba->link_state = LPFC_LINK_UP;
1407 /* Unblock fabric iocbs if they are blocked */
1408 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1409 del_timer_sync(&phba->fabric_block_timer);
1411 vports = lpfc_create_vport_work_array(phba);
1413 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1414 lpfc_linkup_port(vports[i]);
1415 lpfc_destroy_vport_work_array(phba, vports);
1417 /* Clear the pport flogi counter in case the link down was
1418 * absorbed without an ACQE. No lock here - in worker thread
1419 * and discovery is synchronized.
1421 spin_lock_irq(shost->host_lock);
1422 phba->pport->rcv_flogi_cnt = 0;
1423 spin_unlock_irq(shost->host_lock);
1425 /* reinitialize initial HBA flag */
1426 phba->hba_flag &= ~(HBA_FLOGI_ISSUED | HBA_RHBA_CMPL);
1432 * This routine handles processing a CLEAR_LA mailbox
1433 * command upon completion. It is setup in the LPFC_MBOXQ
1434 * as the completion routine when the command is
1435 * handed off to the SLI layer. SLI3 only.
1438 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1440 struct lpfc_vport *vport = pmb->vport;
1441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1442 struct lpfc_sli *psli = &phba->sli;
1443 MAILBOX_t *mb = &pmb->u.mb;
1446 /* Since we don't do discovery right now, turn these off here */
1447 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1448 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1450 /* Check for error */
1451 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1452 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1453 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1454 "0320 CLEAR_LA mbxStatus error x%x hba "
1456 mb->mbxStatus, vport->port_state);
1457 phba->link_state = LPFC_HBA_ERROR;
1461 if (vport->port_type == LPFC_PHYSICAL_PORT)
1462 phba->link_state = LPFC_HBA_READY;
1464 spin_lock_irq(&phba->hbalock);
1465 psli->sli_flag |= LPFC_PROCESS_LA;
1466 control = readl(phba->HCregaddr);
1467 control |= HC_LAINT_ENA;
1468 writel(control, phba->HCregaddr);
1469 readl(phba->HCregaddr); /* flush */
1470 spin_unlock_irq(&phba->hbalock);
1471 mempool_free(pmb, phba->mbox_mem_pool);
1475 /* Device Discovery completes */
1476 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1477 "0225 Device Discovery completes\n");
1478 mempool_free(pmb, phba->mbox_mem_pool);
1480 spin_lock_irq(shost->host_lock);
1481 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1482 spin_unlock_irq(shost->host_lock);
1484 lpfc_can_disctmo(vport);
1486 /* turn on Link Attention interrupts */
1488 spin_lock_irq(&phba->hbalock);
1489 psli->sli_flag |= LPFC_PROCESS_LA;
1490 control = readl(phba->HCregaddr);
1491 control |= HC_LAINT_ENA;
1492 writel(control, phba->HCregaddr);
1493 readl(phba->HCregaddr); /* flush */
1494 spin_unlock_irq(&phba->hbalock);
1500 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1502 struct lpfc_vport *vport = pmb->vport;
1503 LPFC_MBOXQ_t *sparam_mb;
1504 u16 status = pmb->u.mb.mbxStatus;
1507 mempool_free(pmb, phba->mbox_mem_pool);
1512 /* don't perform discovery for SLI4 loopback diagnostic test */
1513 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1514 !(phba->hba_flag & HBA_FCOE_MODE) &&
1515 (phba->link_flag & LS_LOOPBACK_MODE))
1518 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1519 vport->fc_flag & FC_PUBLIC_LOOP &&
1520 !(vport->fc_flag & FC_LBIT)) {
1521 /* Need to wait for FAN - use discovery timer
1522 * for timeout. port_state is identically
1523 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1525 lpfc_set_disctmo(vport);
1529 /* Start discovery by sending a FLOGI. port_state is identically
1530 * LPFC_FLOGI while waiting for FLOGI cmpl.
1532 if (vport->port_state != LPFC_FLOGI) {
1533 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1534 * bb-credit recovery is in place.
1536 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1537 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1538 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1543 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1545 mempool_free(sparam_mb, phba->mbox_mem_pool);
1548 sparam_mb->vport = vport;
1549 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1550 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1551 if (rc == MBX_NOT_FINISHED) {
1552 lpfc_mbox_rsrc_cleanup(phba, sparam_mb,
1557 phba->hba_flag |= HBA_DEFER_FLOGI;
1559 lpfc_initial_flogi(vport);
1562 if (vport->fc_flag & FC_PT2PT)
1563 lpfc_disc_start(vport);
1568 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1569 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1570 status, vport->port_state);
1573 lpfc_linkdown(phba);
1575 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1576 "0200 CONFIG_LINK bad hba state x%x\n",
1579 lpfc_issue_clear_la(phba, vport);
1584 * lpfc_sli4_clear_fcf_rr_bmask
1585 * @phba: pointer to the struct lpfc_hba for this port.
1586 * This fucnction resets the round robin bit mask and clears the
1587 * fcf priority list. The list deletions are done while holding the
1588 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1589 * from the lpfc_fcf_pri record.
1592 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1594 struct lpfc_fcf_pri *fcf_pri;
1595 struct lpfc_fcf_pri *next_fcf_pri;
1596 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1597 spin_lock_irq(&phba->hbalock);
1598 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1599 &phba->fcf.fcf_pri_list, list) {
1600 list_del_init(&fcf_pri->list);
1601 fcf_pri->fcf_rec.flag = 0;
1603 spin_unlock_irq(&phba->hbalock);
1606 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1608 struct lpfc_vport *vport = mboxq->vport;
1610 if (mboxq->u.mb.mbxStatus) {
1611 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1612 "2017 REG_FCFI mbxStatus error x%x "
1613 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1618 /* Start FCoE discovery by sending a FLOGI. */
1619 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1620 /* Set the FCFI registered flag */
1621 spin_lock_irq(&phba->hbalock);
1622 phba->fcf.fcf_flag |= FCF_REGISTERED;
1623 spin_unlock_irq(&phba->hbalock);
1625 /* If there is a pending FCoE event, restart FCF table scan. */
1626 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1627 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1630 /* Mark successful completion of FCF table scan */
1631 spin_lock_irq(&phba->hbalock);
1632 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1633 phba->hba_flag &= ~FCF_TS_INPROG;
1634 if (vport->port_state != LPFC_FLOGI) {
1635 phba->hba_flag |= FCF_RR_INPROG;
1636 spin_unlock_irq(&phba->hbalock);
1637 lpfc_issue_init_vfi(vport);
1640 spin_unlock_irq(&phba->hbalock);
1644 spin_lock_irq(&phba->hbalock);
1645 phba->hba_flag &= ~FCF_RR_INPROG;
1646 spin_unlock_irq(&phba->hbalock);
1648 mempool_free(mboxq, phba->mbox_mem_pool);
1652 * lpfc_fab_name_match - Check if the fcf fabric name match.
1653 * @fab_name: pointer to fabric name.
1654 * @new_fcf_record: pointer to fcf record.
1656 * This routine compare the fcf record's fabric name with provided
1657 * fabric name. If the fabric name are identical this function
1658 * returns 1 else return 0.
1661 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1663 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1665 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1667 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1669 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1671 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1673 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1675 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1677 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1683 * lpfc_sw_name_match - Check if the fcf switch name match.
1684 * @sw_name: pointer to switch name.
1685 * @new_fcf_record: pointer to fcf record.
1687 * This routine compare the fcf record's switch name with provided
1688 * switch name. If the switch name are identical this function
1689 * returns 1 else return 0.
1692 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1694 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1696 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1698 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1700 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1702 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1704 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1706 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1708 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1714 * lpfc_mac_addr_match - Check if the fcf mac address match.
1715 * @mac_addr: pointer to mac address.
1716 * @new_fcf_record: pointer to fcf record.
1718 * This routine compare the fcf record's mac address with HBA's
1719 * FCF mac address. If the mac addresses are identical this function
1720 * returns 1 else return 0.
1723 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1725 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1727 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1729 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1731 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1733 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1735 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1741 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1743 return (curr_vlan_id == new_vlan_id);
1747 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1748 * @phba: pointer to lpfc hba data structure.
1749 * @fcf_index: Index for the lpfc_fcf_record.
1750 * @new_fcf_record: pointer to hba fcf record.
1752 * This routine updates the driver FCF priority record from the new HBA FCF
1753 * record. The hbalock is asserted held in the code path calling this
1757 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1758 struct fcf_record *new_fcf_record
1761 struct lpfc_fcf_pri *fcf_pri;
1763 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1764 fcf_pri->fcf_rec.fcf_index = fcf_index;
1765 /* FCF record priority */
1766 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1771 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1772 * @fcf_rec: pointer to driver fcf record.
1773 * @new_fcf_record: pointer to fcf record.
1775 * This routine copies the FCF information from the FCF
1776 * record to lpfc_hba data structure.
1779 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1780 struct fcf_record *new_fcf_record)
1783 fcf_rec->fabric_name[0] =
1784 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1785 fcf_rec->fabric_name[1] =
1786 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1787 fcf_rec->fabric_name[2] =
1788 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1789 fcf_rec->fabric_name[3] =
1790 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1791 fcf_rec->fabric_name[4] =
1792 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1793 fcf_rec->fabric_name[5] =
1794 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1795 fcf_rec->fabric_name[6] =
1796 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1797 fcf_rec->fabric_name[7] =
1798 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1800 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1801 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1802 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1803 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1804 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1805 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1806 /* FCF record index */
1807 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1808 /* FCF record priority */
1809 fcf_rec->priority = new_fcf_record->fip_priority;
1811 fcf_rec->switch_name[0] =
1812 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1813 fcf_rec->switch_name[1] =
1814 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1815 fcf_rec->switch_name[2] =
1816 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1817 fcf_rec->switch_name[3] =
1818 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1819 fcf_rec->switch_name[4] =
1820 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1821 fcf_rec->switch_name[5] =
1822 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1823 fcf_rec->switch_name[6] =
1824 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1825 fcf_rec->switch_name[7] =
1826 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1830 * __lpfc_update_fcf_record - Update driver fcf record
1831 * @phba: pointer to lpfc hba data structure.
1832 * @fcf_rec: pointer to driver fcf record.
1833 * @new_fcf_record: pointer to hba fcf record.
1834 * @addr_mode: address mode to be set to the driver fcf record.
1835 * @vlan_id: vlan tag to be set to the driver fcf record.
1836 * @flag: flag bits to be set to the driver fcf record.
1838 * This routine updates the driver FCF record from the new HBA FCF record
1839 * together with the address mode, vlan_id, and other informations. This
1840 * routine is called with the hbalock held.
1843 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1844 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1845 uint16_t vlan_id, uint32_t flag)
1847 lockdep_assert_held(&phba->hbalock);
1849 /* Copy the fields from the HBA's FCF record */
1850 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1851 /* Update other fields of driver FCF record */
1852 fcf_rec->addr_mode = addr_mode;
1853 fcf_rec->vlan_id = vlan_id;
1854 fcf_rec->flag |= (flag | RECORD_VALID);
1855 __lpfc_update_fcf_record_pri(phba,
1856 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1861 * lpfc_register_fcf - Register the FCF with hba.
1862 * @phba: pointer to lpfc hba data structure.
1864 * This routine issues a register fcfi mailbox command to register
1868 lpfc_register_fcf(struct lpfc_hba *phba)
1870 LPFC_MBOXQ_t *fcf_mbxq;
1873 spin_lock_irq(&phba->hbalock);
1874 /* If the FCF is not available do nothing. */
1875 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1876 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1877 spin_unlock_irq(&phba->hbalock);
1881 /* The FCF is already registered, start discovery */
1882 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1883 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1884 phba->hba_flag &= ~FCF_TS_INPROG;
1885 if (phba->pport->port_state != LPFC_FLOGI &&
1886 phba->pport->fc_flag & FC_FABRIC) {
1887 phba->hba_flag |= FCF_RR_INPROG;
1888 spin_unlock_irq(&phba->hbalock);
1889 lpfc_initial_flogi(phba->pport);
1892 spin_unlock_irq(&phba->hbalock);
1895 spin_unlock_irq(&phba->hbalock);
1897 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1899 spin_lock_irq(&phba->hbalock);
1900 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1901 spin_unlock_irq(&phba->hbalock);
1905 lpfc_reg_fcfi(phba, fcf_mbxq);
1906 fcf_mbxq->vport = phba->pport;
1907 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1908 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1909 if (rc == MBX_NOT_FINISHED) {
1910 spin_lock_irq(&phba->hbalock);
1911 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1912 spin_unlock_irq(&phba->hbalock);
1913 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1920 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1921 * @phba: pointer to lpfc hba data structure.
1922 * @new_fcf_record: pointer to fcf record.
1923 * @boot_flag: Indicates if this record used by boot bios.
1924 * @addr_mode: The address mode to be used by this FCF
1925 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1927 * This routine compare the fcf record with connect list obtained from the
1928 * config region to decide if this FCF can be used for SAN discovery. It returns
1929 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1930 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1931 * is used by boot bios and addr_mode will indicate the addressing mode to be
1932 * used for this FCF when the function returns.
1933 * If the FCF record need to be used with a particular vlan id, the vlan is
1934 * set in the vlan_id on return of the function. If not VLAN tagging need to
1935 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1938 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1939 struct fcf_record *new_fcf_record,
1940 uint32_t *boot_flag, uint32_t *addr_mode,
1943 struct lpfc_fcf_conn_entry *conn_entry;
1944 int i, j, fcf_vlan_id = 0;
1946 /* Find the lowest VLAN id in the FCF record */
1947 for (i = 0; i < 512; i++) {
1948 if (new_fcf_record->vlan_bitmap[i]) {
1949 fcf_vlan_id = i * 8;
1951 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1959 /* FCF not valid/available or solicitation in progress */
1960 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1961 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1962 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1965 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1967 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1969 if (phba->valid_vlan)
1970 *vlan_id = phba->vlan_id;
1972 *vlan_id = LPFC_FCOE_NULL_VID;
1977 * If there are no FCF connection table entry, driver connect to all
1980 if (list_empty(&phba->fcf_conn_rec_list)) {
1982 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1986 * When there are no FCF connect entries, use driver's default
1987 * addressing mode - FPMA.
1989 if (*addr_mode & LPFC_FCF_FPMA)
1990 *addr_mode = LPFC_FCF_FPMA;
1992 /* If FCF record report a vlan id use that vlan id */
1994 *vlan_id = fcf_vlan_id;
1996 *vlan_id = LPFC_FCOE_NULL_VID;
2000 list_for_each_entry(conn_entry,
2001 &phba->fcf_conn_rec_list, list) {
2002 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
2005 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
2006 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
2009 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
2010 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
2013 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
2015 * If the vlan bit map does not have the bit set for the
2016 * vlan id to be used, then it is not a match.
2018 if (!(new_fcf_record->vlan_bitmap
2019 [conn_entry->conn_rec.vlan_tag / 8] &
2020 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
2025 * If connection record does not support any addressing mode,
2026 * skip the FCF record.
2028 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
2029 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
2033 * Check if the connection record specifies a required
2036 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2037 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
2040 * If SPMA required but FCF not support this continue.
2042 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2043 !(bf_get(lpfc_fcf_record_mac_addr_prov,
2044 new_fcf_record) & LPFC_FCF_SPMA))
2048 * If FPMA required but FCF not support this continue.
2050 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2051 !(bf_get(lpfc_fcf_record_mac_addr_prov,
2052 new_fcf_record) & LPFC_FCF_FPMA))
2057 * This fcf record matches filtering criteria.
2059 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
2065 * If user did not specify any addressing mode, or if the
2066 * preferred addressing mode specified by user is not supported
2067 * by FCF, allow fabric to pick the addressing mode.
2069 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
2072 * If the user specified a required address mode, assign that
2075 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2076 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
2077 *addr_mode = (conn_entry->conn_rec.flags &
2079 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
2081 * If the user specified a preferred address mode, use the
2082 * addr mode only if FCF support the addr_mode.
2084 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2085 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2086 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2087 (*addr_mode & LPFC_FCF_SPMA))
2088 *addr_mode = LPFC_FCF_SPMA;
2089 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2090 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2091 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2092 (*addr_mode & LPFC_FCF_FPMA))
2093 *addr_mode = LPFC_FCF_FPMA;
2095 /* If matching connect list has a vlan id, use it */
2096 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
2097 *vlan_id = conn_entry->conn_rec.vlan_tag;
2099 * If no vlan id is specified in connect list, use the vlan id
2102 else if (fcf_vlan_id)
2103 *vlan_id = fcf_vlan_id;
2105 *vlan_id = LPFC_FCOE_NULL_VID;
2114 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
2115 * @phba: pointer to lpfc hba data structure.
2116 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
2118 * This function check if there is any fcoe event pending while driver
2119 * scan FCF entries. If there is any pending event, it will restart the
2120 * FCF saning and return 1 else return 0.
2123 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
2126 * If the Link is up and no FCoE events while in the
2127 * FCF discovery, no need to restart FCF discovery.
2129 if ((phba->link_state >= LPFC_LINK_UP) &&
2130 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
2133 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2134 "2768 Pending link or FCF event during current "
2135 "handling of the previous event: link_state:x%x, "
2136 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
2137 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
2138 phba->fcoe_eventtag);
2140 spin_lock_irq(&phba->hbalock);
2141 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
2142 spin_unlock_irq(&phba->hbalock);
2144 if (phba->link_state >= LPFC_LINK_UP) {
2145 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2146 "2780 Restart FCF table scan due to "
2147 "pending FCF event:evt_tag_at_scan:x%x, "
2148 "evt_tag_current:x%x\n",
2149 phba->fcoe_eventtag_at_fcf_scan,
2150 phba->fcoe_eventtag);
2151 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
2154 * Do not continue FCF discovery and clear FCF_TS_INPROG
2157 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2158 "2833 Stop FCF discovery process due to link "
2159 "state change (x%x)\n", phba->link_state);
2160 spin_lock_irq(&phba->hbalock);
2161 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
2162 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
2163 spin_unlock_irq(&phba->hbalock);
2166 /* Unregister the currently registered FCF if required */
2168 spin_lock_irq(&phba->hbalock);
2169 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
2170 spin_unlock_irq(&phba->hbalock);
2171 lpfc_sli4_unregister_fcf(phba);
2177 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
2178 * @phba: pointer to lpfc hba data structure.
2179 * @fcf_cnt: number of eligible fcf record seen so far.
2181 * This function makes an running random selection decision on FCF record to
2182 * use through a sequence of @fcf_cnt eligible FCF records with equal
2183 * probability. To perform integer manunipulation of random numbers with
2184 * size unit32_t, a 16-bit random number returned from get_random_u16() is
2185 * taken as the random random number generated.
2187 * Returns true when outcome is for the newly read FCF record should be
2188 * chosen; otherwise, return false when outcome is for keeping the previously
2189 * chosen FCF record.
2192 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
2196 /* Get 16-bit uniform random number */
2197 rand_num = get_random_u16();
2199 /* Decision with probability 1/fcf_cnt */
2200 if ((fcf_cnt * rand_num) < 0xFFFF)
2207 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
2208 * @phba: pointer to lpfc hba data structure.
2209 * @mboxq: pointer to mailbox object.
2210 * @next_fcf_index: pointer to holder of next fcf index.
2212 * This routine parses the non-embedded fcf mailbox command by performing the
2213 * necessarily error checking, non-embedded read FCF record mailbox command
2214 * SGE parsing, and endianness swapping.
2216 * Returns the pointer to the new FCF record in the non-embedded mailbox
2217 * command DMA memory if successfully, other NULL.
2219 static struct fcf_record *
2220 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
2221 uint16_t *next_fcf_index)
2224 struct lpfc_mbx_sge sge;
2225 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2226 uint32_t shdr_status, shdr_add_status, if_type;
2227 union lpfc_sli4_cfg_shdr *shdr;
2228 struct fcf_record *new_fcf_record;
2230 /* Get the first SGE entry from the non-embedded DMA memory. This
2231 * routine only uses a single SGE.
2233 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2234 if (unlikely(!mboxq->sge_array)) {
2235 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2236 "2524 Failed to get the non-embedded SGE "
2237 "virtual address\n");
2240 virt_addr = mboxq->sge_array->addr[0];
2242 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
2243 lpfc_sli_pcimem_bcopy(shdr, shdr,
2244 sizeof(union lpfc_sli4_cfg_shdr));
2245 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2246 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2247 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2248 if (shdr_status || shdr_add_status) {
2249 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
2250 if_type == LPFC_SLI_INTF_IF_TYPE_2)
2251 lpfc_printf_log(phba, KERN_ERR,
2253 "2726 READ_FCF_RECORD Indicates empty "
2256 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2257 "2521 READ_FCF_RECORD mailbox failed "
2258 "with status x%x add_status x%x, "
2259 "mbx\n", shdr_status, shdr_add_status);
2263 /* Interpreting the returned information of the FCF record */
2264 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2265 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
2266 sizeof(struct lpfc_mbx_read_fcf_tbl));
2267 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
2268 new_fcf_record = (struct fcf_record *)(virt_addr +
2269 sizeof(struct lpfc_mbx_read_fcf_tbl));
2270 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
2271 offsetof(struct fcf_record, vlan_bitmap));
2272 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
2273 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
2275 return new_fcf_record;
2279 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
2280 * @phba: pointer to lpfc hba data structure.
2281 * @fcf_record: pointer to the fcf record.
2282 * @vlan_id: the lowest vlan identifier associated to this fcf record.
2283 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
2285 * This routine logs the detailed FCF record if the LOG_FIP loggin is
2289 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
2290 struct fcf_record *fcf_record,
2292 uint16_t next_fcf_index)
2294 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2295 "2764 READ_FCF_RECORD:\n"
2296 "\tFCF_Index : x%x\n"
2297 "\tFCF_Avail : x%x\n"
2298 "\tFCF_Valid : x%x\n"
2300 "\tFIP_Priority : x%x\n"
2301 "\tMAC_Provider : x%x\n"
2302 "\tLowest VLANID : x%x\n"
2303 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
2304 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2305 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2306 "\tNext_FCF_Index: x%x\n",
2307 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
2308 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
2309 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
2310 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
2311 fcf_record->fip_priority,
2312 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
2314 bf_get(lpfc_fcf_record_mac_0, fcf_record),
2315 bf_get(lpfc_fcf_record_mac_1, fcf_record),
2316 bf_get(lpfc_fcf_record_mac_2, fcf_record),
2317 bf_get(lpfc_fcf_record_mac_3, fcf_record),
2318 bf_get(lpfc_fcf_record_mac_4, fcf_record),
2319 bf_get(lpfc_fcf_record_mac_5, fcf_record),
2320 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
2321 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
2322 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
2323 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
2324 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
2325 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
2326 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
2327 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
2328 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
2329 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
2330 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
2331 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
2332 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
2333 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
2334 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
2335 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
2340 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
2341 * @phba: pointer to lpfc hba data structure.
2342 * @fcf_rec: pointer to an existing FCF record.
2343 * @new_fcf_record: pointer to a new FCF record.
2344 * @new_vlan_id: vlan id from the new FCF record.
2346 * This function performs matching test of a new FCF record against an existing
2347 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2348 * will not be used as part of the FCF record matching criteria.
2350 * Returns true if all the fields matching, otherwise returns false.
2353 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2354 struct lpfc_fcf_rec *fcf_rec,
2355 struct fcf_record *new_fcf_record,
2356 uint16_t new_vlan_id)
2358 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2359 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2361 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2363 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2365 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2367 if (fcf_rec->priority != new_fcf_record->fip_priority)
2373 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2374 * @vport: Pointer to vport object.
2375 * @fcf_index: index to next fcf.
2377 * This function processing the roundrobin fcf failover to next fcf index.
2378 * When this function is invoked, there will be a current fcf registered
2380 * Return: 0 for continue retrying flogi on currently registered fcf;
2381 * 1 for stop flogi on currently registered fcf;
2383 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2385 struct lpfc_hba *phba = vport->phba;
2388 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2389 spin_lock_irq(&phba->hbalock);
2390 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2391 spin_unlock_irq(&phba->hbalock);
2392 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2393 "2872 Devloss tmo with no eligible "
2394 "FCF, unregister in-use FCF (x%x) "
2395 "and rescan FCF table\n",
2396 phba->fcf.current_rec.fcf_indx);
2397 lpfc_unregister_fcf_rescan(phba);
2398 goto stop_flogi_current_fcf;
2400 /* Mark the end to FLOGI roundrobin failover */
2401 phba->hba_flag &= ~FCF_RR_INPROG;
2402 /* Allow action to new fcf asynchronous event */
2403 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2404 spin_unlock_irq(&phba->hbalock);
2405 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2406 "2865 No FCF available, stop roundrobin FCF "
2407 "failover and change port state:x%x/x%x\n",
2408 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2409 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2411 if (!phba->fcf.fcf_redisc_attempted) {
2412 lpfc_unregister_fcf(phba);
2414 rc = lpfc_sli4_redisc_fcf_table(phba);
2416 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2417 "3195 Rediscover FCF table\n");
2418 phba->fcf.fcf_redisc_attempted = 1;
2419 lpfc_sli4_clear_fcf_rr_bmask(phba);
2421 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2422 "3196 Rediscover FCF table "
2423 "failed. Status:x%x\n", rc);
2426 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2427 "3197 Already rediscover FCF table "
2428 "attempted. No more retry\n");
2430 goto stop_flogi_current_fcf;
2432 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2433 "2794 Try FLOGI roundrobin FCF failover to "
2434 "(x%x)\n", fcf_index);
2435 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2437 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2438 "2761 FLOGI roundrobin FCF failover "
2439 "failed (rc:x%x) to read FCF (x%x)\n",
2440 rc, phba->fcf.current_rec.fcf_indx);
2442 goto stop_flogi_current_fcf;
2446 stop_flogi_current_fcf:
2447 lpfc_can_disctmo(vport);
2452 * lpfc_sli4_fcf_pri_list_del
2453 * @phba: pointer to lpfc hba data structure.
2454 * @fcf_index: the index of the fcf record to delete
2455 * This routine checks the on list flag of the fcf_index to be deleted.
2456 * If it is one the list then it is removed from the list, and the flag
2457 * is cleared. This routine grab the hbalock before removing the fcf
2458 * record from the list.
2460 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2463 struct lpfc_fcf_pri *new_fcf_pri;
2465 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2466 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2467 "3058 deleting idx x%x pri x%x flg x%x\n",
2468 fcf_index, new_fcf_pri->fcf_rec.priority,
2469 new_fcf_pri->fcf_rec.flag);
2470 spin_lock_irq(&phba->hbalock);
2471 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2472 if (phba->fcf.current_rec.priority ==
2473 new_fcf_pri->fcf_rec.priority)
2474 phba->fcf.eligible_fcf_cnt--;
2475 list_del_init(&new_fcf_pri->list);
2476 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2478 spin_unlock_irq(&phba->hbalock);
2482 * lpfc_sli4_set_fcf_flogi_fail
2483 * @phba: pointer to lpfc hba data structure.
2484 * @fcf_index: the index of the fcf record to update
2485 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2486 * flag so the round robin selection for the particular priority level
2487 * will try a different fcf record that does not have this bit set.
2488 * If the fcf record is re-read for any reason this flag is cleared brfore
2489 * adding it to the priority list.
2492 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2494 struct lpfc_fcf_pri *new_fcf_pri;
2495 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2496 spin_lock_irq(&phba->hbalock);
2497 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2498 spin_unlock_irq(&phba->hbalock);
2502 * lpfc_sli4_fcf_pri_list_add
2503 * @phba: pointer to lpfc hba data structure.
2504 * @fcf_index: the index of the fcf record to add
2505 * @new_fcf_record: pointer to a new FCF record.
2506 * This routine checks the priority of the fcf_index to be added.
2507 * If it is a lower priority than the current head of the fcf_pri list
2508 * then it is added to the list in the right order.
2509 * If it is the same priority as the current head of the list then it
2510 * is added to the head of the list and its bit in the rr_bmask is set.
2511 * If the fcf_index to be added is of a higher priority than the current
2512 * head of the list then the rr_bmask is cleared, its bit is set in the
2513 * rr_bmask and it is added to the head of the list.
2515 * 0=success 1=failure
2517 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2519 struct fcf_record *new_fcf_record)
2521 uint16_t current_fcf_pri;
2522 uint16_t last_index;
2523 struct lpfc_fcf_pri *fcf_pri;
2524 struct lpfc_fcf_pri *next_fcf_pri;
2525 struct lpfc_fcf_pri *new_fcf_pri;
2528 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2529 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2530 "3059 adding idx x%x pri x%x flg x%x\n",
2531 fcf_index, new_fcf_record->fip_priority,
2532 new_fcf_pri->fcf_rec.flag);
2533 spin_lock_irq(&phba->hbalock);
2534 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2535 list_del_init(&new_fcf_pri->list);
2536 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2537 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2538 if (list_empty(&phba->fcf.fcf_pri_list)) {
2539 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2540 ret = lpfc_sli4_fcf_rr_index_set(phba,
2541 new_fcf_pri->fcf_rec.fcf_index);
2545 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2546 LPFC_SLI4_FCF_TBL_INDX_MAX);
2547 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2548 ret = 0; /* Empty rr list */
2551 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2552 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2553 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2554 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2555 memset(phba->fcf.fcf_rr_bmask, 0,
2556 sizeof(*phba->fcf.fcf_rr_bmask));
2557 /* fcfs_at_this_priority_level = 1; */
2558 phba->fcf.eligible_fcf_cnt = 1;
2560 /* fcfs_at_this_priority_level++; */
2561 phba->fcf.eligible_fcf_cnt++;
2562 ret = lpfc_sli4_fcf_rr_index_set(phba,
2563 new_fcf_pri->fcf_rec.fcf_index);
2567 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2568 &phba->fcf.fcf_pri_list, list) {
2569 if (new_fcf_pri->fcf_rec.priority <=
2570 fcf_pri->fcf_rec.priority) {
2571 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2572 list_add(&new_fcf_pri->list,
2573 &phba->fcf.fcf_pri_list);
2575 list_add(&new_fcf_pri->list,
2576 &((struct lpfc_fcf_pri *)
2577 fcf_pri->list.prev)->list);
2580 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2581 || new_fcf_pri->fcf_rec.priority <
2582 next_fcf_pri->fcf_rec.priority) {
2583 list_add(&new_fcf_pri->list, &fcf_pri->list);
2587 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2593 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2594 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2595 spin_unlock_irq(&phba->hbalock);
2600 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2601 * @phba: pointer to lpfc hba data structure.
2602 * @mboxq: pointer to mailbox object.
2604 * This function iterates through all the fcf records available in
2605 * HBA and chooses the optimal FCF record for discovery. After finding
2606 * the FCF for discovery it registers the FCF record and kicks start
2608 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2609 * use an FCF record which matches fabric name and mac address of the
2610 * currently used FCF record.
2611 * If the driver supports only one FCF, it will try to use the FCF record
2612 * used by BOOT_BIOS.
2615 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2617 struct fcf_record *new_fcf_record;
2618 uint32_t boot_flag, addr_mode;
2619 uint16_t fcf_index, next_fcf_index;
2620 struct lpfc_fcf_rec *fcf_rec = NULL;
2621 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2622 bool select_new_fcf;
2625 /* If there is pending FCoE event restart FCF table scan */
2626 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2627 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2631 /* Parse the FCF record from the non-embedded mailbox command */
2632 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2634 if (!new_fcf_record) {
2635 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2636 "2765 Mailbox command READ_FCF_RECORD "
2637 "failed to retrieve a FCF record.\n");
2638 /* Let next new FCF event trigger fast failover */
2639 spin_lock_irq(&phba->hbalock);
2640 phba->hba_flag &= ~FCF_TS_INPROG;
2641 spin_unlock_irq(&phba->hbalock);
2642 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2646 /* Check the FCF record against the connection list */
2647 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2648 &addr_mode, &vlan_id);
2650 /* Log the FCF record information if turned on */
2651 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2655 * If the fcf record does not match with connect list entries
2656 * read the next entry; otherwise, this is an eligible FCF
2657 * record for roundrobin FCF failover.
2660 lpfc_sli4_fcf_pri_list_del(phba,
2661 bf_get(lpfc_fcf_record_fcf_index,
2663 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2664 "2781 FCF (x%x) failed connection "
2665 "list check: (x%x/x%x/%x)\n",
2666 bf_get(lpfc_fcf_record_fcf_index,
2668 bf_get(lpfc_fcf_record_fcf_avail,
2670 bf_get(lpfc_fcf_record_fcf_valid,
2672 bf_get(lpfc_fcf_record_fcf_sol,
2674 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2675 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2676 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2677 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2678 phba->fcf.current_rec.fcf_indx) {
2679 lpfc_printf_log(phba, KERN_ERR,
2681 "2862 FCF (x%x) matches property "
2682 "of in-use FCF (x%x)\n",
2683 bf_get(lpfc_fcf_record_fcf_index,
2685 phba->fcf.current_rec.fcf_indx);
2689 * In case the current in-use FCF record becomes
2690 * invalid/unavailable during FCF discovery that
2691 * was not triggered by fast FCF failover process,
2692 * treat it as fast FCF failover.
2694 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2695 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2696 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2697 "2835 Invalid in-use FCF "
2698 "(x%x), enter FCF failover "
2700 phba->fcf.current_rec.fcf_indx);
2701 spin_lock_irq(&phba->hbalock);
2702 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2703 spin_unlock_irq(&phba->hbalock);
2704 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2705 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2706 LPFC_FCOE_FCF_GET_FIRST);
2712 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2713 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2720 * If this is not the first FCF discovery of the HBA, use last
2721 * FCF record for the discovery. The condition that a rescan
2722 * matches the in-use FCF record: fabric name, switch name, mac
2723 * address, and vlan_id.
2725 spin_lock_irq(&phba->hbalock);
2726 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2727 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2728 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2729 new_fcf_record, vlan_id)) {
2730 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2731 phba->fcf.current_rec.fcf_indx) {
2732 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2733 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2734 /* Stop FCF redisc wait timer */
2735 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2737 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2738 /* Fast failover, mark completed */
2739 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2740 spin_unlock_irq(&phba->hbalock);
2741 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2742 "2836 New FCF matches in-use "
2743 "FCF (x%x), port_state:x%x, "
2745 phba->fcf.current_rec.fcf_indx,
2746 phba->pport->port_state,
2747 phba->pport->fc_flag);
2750 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2751 "2863 New FCF (x%x) matches "
2752 "property of in-use FCF (x%x)\n",
2753 bf_get(lpfc_fcf_record_fcf_index,
2755 phba->fcf.current_rec.fcf_indx);
2758 * Read next FCF record from HBA searching for the matching
2759 * with in-use record only if not during the fast failover
2760 * period. In case of fast failover period, it shall try to
2761 * determine whether the FCF record just read should be the
2764 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2765 spin_unlock_irq(&phba->hbalock);
2770 * Update on failover FCF record only if it's in FCF fast-failover
2771 * period; otherwise, update on current FCF record.
2773 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2774 fcf_rec = &phba->fcf.failover_rec;
2776 fcf_rec = &phba->fcf.current_rec;
2778 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2780 * If the driver FCF record does not have boot flag
2781 * set and new hba fcf record has boot flag set, use
2782 * the new hba fcf record.
2784 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2785 /* Choose this FCF record */
2786 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2787 "2837 Update current FCF record "
2788 "(x%x) with new FCF record (x%x)\n",
2790 bf_get(lpfc_fcf_record_fcf_index,
2792 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2793 addr_mode, vlan_id, BOOT_ENABLE);
2794 spin_unlock_irq(&phba->hbalock);
2798 * If the driver FCF record has boot flag set and the
2799 * new hba FCF record does not have boot flag, read
2800 * the next FCF record.
2802 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2803 spin_unlock_irq(&phba->hbalock);
2807 * If the new hba FCF record has lower priority value
2808 * than the driver FCF record, use the new record.
2810 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2811 /* Choose the new FCF record with lower priority */
2812 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2813 "2838 Update current FCF record "
2814 "(x%x) with new FCF record (x%x)\n",
2816 bf_get(lpfc_fcf_record_fcf_index,
2818 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2819 addr_mode, vlan_id, 0);
2820 /* Reset running random FCF selection count */
2821 phba->fcf.eligible_fcf_cnt = 1;
2822 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2823 /* Update running random FCF selection count */
2824 phba->fcf.eligible_fcf_cnt++;
2825 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2826 phba->fcf.eligible_fcf_cnt);
2827 if (select_new_fcf) {
2828 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2829 "2839 Update current FCF record "
2830 "(x%x) with new FCF record (x%x)\n",
2832 bf_get(lpfc_fcf_record_fcf_index,
2834 /* Choose the new FCF by random selection */
2835 __lpfc_update_fcf_record(phba, fcf_rec,
2837 addr_mode, vlan_id, 0);
2840 spin_unlock_irq(&phba->hbalock);
2844 * This is the first suitable FCF record, choose this record for
2845 * initial best-fit FCF.
2848 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2849 "2840 Update initial FCF candidate "
2851 bf_get(lpfc_fcf_record_fcf_index,
2853 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2854 addr_mode, vlan_id, (boot_flag ?
2856 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2857 /* Setup initial running random FCF selection count */
2858 phba->fcf.eligible_fcf_cnt = 1;
2860 spin_unlock_irq(&phba->hbalock);
2864 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2865 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2866 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2868 * Case of FCF fast failover scan
2872 * It has not found any suitable FCF record, cancel
2873 * FCF scan inprogress, and do nothing
2875 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2876 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2877 "2782 No suitable FCF found: "
2879 phba->fcoe_eventtag_at_fcf_scan,
2880 bf_get(lpfc_fcf_record_fcf_index,
2882 spin_lock_irq(&phba->hbalock);
2883 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2884 phba->hba_flag &= ~FCF_TS_INPROG;
2885 spin_unlock_irq(&phba->hbalock);
2886 /* Unregister in-use FCF and rescan */
2887 lpfc_printf_log(phba, KERN_INFO,
2889 "2864 On devloss tmo "
2890 "unreg in-use FCF and "
2891 "rescan FCF table\n");
2892 lpfc_unregister_fcf_rescan(phba);
2896 * Let next new FCF event trigger fast failover
2898 phba->hba_flag &= ~FCF_TS_INPROG;
2899 spin_unlock_irq(&phba->hbalock);
2903 * It has found a suitable FCF record that is not
2904 * the same as in-use FCF record, unregister the
2905 * in-use FCF record, replace the in-use FCF record
2906 * with the new FCF record, mark FCF fast failover
2907 * completed, and then start register the new FCF
2911 /* Unregister the current in-use FCF record */
2912 lpfc_unregister_fcf(phba);
2914 /* Replace in-use record with the new record */
2915 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2916 "2842 Replace in-use FCF (x%x) "
2917 "with failover FCF (x%x)\n",
2918 phba->fcf.current_rec.fcf_indx,
2919 phba->fcf.failover_rec.fcf_indx);
2920 memcpy(&phba->fcf.current_rec,
2921 &phba->fcf.failover_rec,
2922 sizeof(struct lpfc_fcf_rec));
2924 * Mark the fast FCF failover rediscovery completed
2925 * and the start of the first round of the roundrobin
2928 spin_lock_irq(&phba->hbalock);
2929 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2930 spin_unlock_irq(&phba->hbalock);
2931 /* Register to the new FCF record */
2932 lpfc_register_fcf(phba);
2935 * In case of transaction period to fast FCF failover,
2936 * do nothing when search to the end of the FCF table.
2938 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2939 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2942 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2943 phba->fcf.fcf_flag & FCF_IN_USE) {
2945 * In case the current in-use FCF record no
2946 * longer existed during FCF discovery that
2947 * was not triggered by fast FCF failover
2948 * process, treat it as fast FCF failover.
2950 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2951 "2841 In-use FCF record (x%x) "
2952 "not reported, entering fast "
2953 "FCF failover mode scanning.\n",
2954 phba->fcf.current_rec.fcf_indx);
2955 spin_lock_irq(&phba->hbalock);
2956 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2957 spin_unlock_irq(&phba->hbalock);
2958 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2959 LPFC_FCOE_FCF_GET_FIRST);
2962 /* Register to the new FCF record */
2963 lpfc_register_fcf(phba);
2966 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2970 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2971 lpfc_register_fcf(phba);
2977 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2978 * @phba: pointer to lpfc hba data structure.
2979 * @mboxq: pointer to mailbox object.
2981 * This is the callback function for FLOGI failure roundrobin FCF failover
2982 * read FCF record mailbox command from the eligible FCF record bmask for
2983 * performing the failover. If the FCF read back is not valid/available, it
2984 * fails through to retrying FLOGI to the currently registered FCF again.
2985 * Otherwise, if the FCF read back is valid and available, it will set the
2986 * newly read FCF record to the failover FCF record, unregister currently
2987 * registered FCF record, copy the failover FCF record to the current
2988 * FCF record, and then register the current FCF record before proceeding
2989 * to trying FLOGI on the new failover FCF.
2992 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2994 struct fcf_record *new_fcf_record;
2995 uint32_t boot_flag, addr_mode;
2996 uint16_t next_fcf_index, fcf_index;
2997 uint16_t current_fcf_index;
2998 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
3001 /* If link state is not up, stop the roundrobin failover process */
3002 if (phba->link_state < LPFC_LINK_UP) {
3003 spin_lock_irq(&phba->hbalock);
3004 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
3005 phba->hba_flag &= ~FCF_RR_INPROG;
3006 spin_unlock_irq(&phba->hbalock);
3010 /* Parse the FCF record from the non-embedded mailbox command */
3011 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
3013 if (!new_fcf_record) {
3014 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
3015 "2766 Mailbox command READ_FCF_RECORD "
3016 "failed to retrieve a FCF record. "
3017 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
3018 phba->fcf.fcf_flag);
3019 lpfc_unregister_fcf_rescan(phba);
3023 /* Get the needed parameters from FCF record */
3024 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3025 &addr_mode, &vlan_id);
3027 /* Log the FCF record information if turned on */
3028 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3031 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
3033 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3034 "2848 Remove ineligible FCF (x%x) from "
3035 "from roundrobin bmask\n", fcf_index);
3036 /* Clear roundrobin bmask bit for ineligible FCF */
3037 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
3038 /* Perform next round of roundrobin FCF failover */
3039 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
3040 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
3046 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
3047 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3048 "2760 Perform FLOGI roundrobin FCF failover: "
3049 "FCF (x%x) back to FCF (x%x)\n",
3050 phba->fcf.current_rec.fcf_indx, fcf_index);
3051 /* Wait 500 ms before retrying FLOGI to current FCF */
3053 lpfc_issue_init_vfi(phba->pport);
3057 /* Upload new FCF record to the failover FCF record */
3058 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3059 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
3060 phba->fcf.failover_rec.fcf_indx, fcf_index);
3061 spin_lock_irq(&phba->hbalock);
3062 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
3063 new_fcf_record, addr_mode, vlan_id,
3064 (boot_flag ? BOOT_ENABLE : 0));
3065 spin_unlock_irq(&phba->hbalock);
3067 current_fcf_index = phba->fcf.current_rec.fcf_indx;
3069 /* Unregister the current in-use FCF record */
3070 lpfc_unregister_fcf(phba);
3072 /* Replace in-use record with the new record */
3073 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
3074 sizeof(struct lpfc_fcf_rec));
3076 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3077 "2783 Perform FLOGI roundrobin FCF failover: FCF "
3078 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
3081 lpfc_register_fcf(phba);
3083 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3087 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
3088 * @phba: pointer to lpfc hba data structure.
3089 * @mboxq: pointer to mailbox object.
3091 * This is the callback function of read FCF record mailbox command for
3092 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
3093 * failover when a new FCF event happened. If the FCF read back is
3094 * valid/available and it passes the connection list check, it updates
3095 * the bmask for the eligible FCF record for roundrobin failover.
3098 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3100 struct fcf_record *new_fcf_record;
3101 uint32_t boot_flag, addr_mode;
3102 uint16_t fcf_index, next_fcf_index;
3103 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
3106 /* If link state is not up, no need to proceed */
3107 if (phba->link_state < LPFC_LINK_UP)
3110 /* If FCF discovery period is over, no need to proceed */
3111 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
3114 /* Parse the FCF record from the non-embedded mailbox command */
3115 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
3117 if (!new_fcf_record) {
3118 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3119 "2767 Mailbox command READ_FCF_RECORD "
3120 "failed to retrieve a FCF record.\n");
3124 /* Check the connection list for eligibility */
3125 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3126 &addr_mode, &vlan_id);
3128 /* Log the FCF record information if turned on */
3129 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3135 /* Update the eligible FCF record index bmask */
3136 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
3138 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
3141 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3145 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
3146 * @phba: pointer to lpfc hba data structure.
3147 * @mboxq: pointer to mailbox data structure.
3149 * This function handles completion of init vfi mailbox command.
3152 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3154 struct lpfc_vport *vport = mboxq->vport;
3157 * VFI not supported on interface type 0, just do the flogi
3158 * Also continue if the VFI is in use - just use the same one.
3160 if (mboxq->u.mb.mbxStatus &&
3161 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3162 LPFC_SLI_INTF_IF_TYPE_0) &&
3163 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3164 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3165 "2891 Init VFI mailbox failed 0x%x\n",
3166 mboxq->u.mb.mbxStatus);
3167 mempool_free(mboxq, phba->mbox_mem_pool);
3168 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3172 lpfc_initial_flogi(vport);
3173 mempool_free(mboxq, phba->mbox_mem_pool);
3178 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
3179 * @vport: pointer to lpfc_vport data structure.
3181 * This function issue a init_vfi mailbox command to initialize the VFI and
3182 * VPI for the physical port.
3185 lpfc_issue_init_vfi(struct lpfc_vport *vport)
3187 LPFC_MBOXQ_t *mboxq;
3189 struct lpfc_hba *phba = vport->phba;
3191 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3193 lpfc_printf_vlog(vport, KERN_ERR,
3194 LOG_TRACE_EVENT, "2892 Failed to allocate "
3195 "init_vfi mailbox\n");
3198 lpfc_init_vfi(mboxq, vport);
3199 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
3200 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
3201 if (rc == MBX_NOT_FINISHED) {
3202 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3203 "2893 Failed to issue init_vfi mailbox\n");
3204 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3209 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
3210 * @phba: pointer to lpfc hba data structure.
3211 * @mboxq: pointer to mailbox data structure.
3213 * This function handles completion of init vpi mailbox command.
3216 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3218 struct lpfc_vport *vport = mboxq->vport;
3219 struct lpfc_nodelist *ndlp;
3220 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3222 if (mboxq->u.mb.mbxStatus) {
3223 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3224 "2609 Init VPI mailbox failed 0x%x\n",
3225 mboxq->u.mb.mbxStatus);
3226 mempool_free(mboxq, phba->mbox_mem_pool);
3227 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3230 spin_lock_irq(shost->host_lock);
3231 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3232 spin_unlock_irq(shost->host_lock);
3234 /* If this port is physical port or FDISC is done, do reg_vpi */
3235 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
3236 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3238 lpfc_printf_vlog(vport, KERN_ERR,
3240 "2731 Cannot find fabric "
3241 "controller node\n");
3243 lpfc_register_new_vport(phba, vport, ndlp);
3244 mempool_free(mboxq, phba->mbox_mem_pool);
3248 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3249 lpfc_initial_fdisc(vport);
3251 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
3252 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3253 "2606 No NPIV Fabric support\n");
3255 mempool_free(mboxq, phba->mbox_mem_pool);
3260 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
3261 * @vport: pointer to lpfc_vport data structure.
3263 * This function issue a init_vpi mailbox command to initialize
3264 * VPI for the vport.
3267 lpfc_issue_init_vpi(struct lpfc_vport *vport)
3269 LPFC_MBOXQ_t *mboxq;
3272 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
3273 vpi = lpfc_alloc_vpi(vport->phba);
3275 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3276 "3303 Failed to obtain vport vpi\n");
3277 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3283 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
3285 lpfc_printf_vlog(vport, KERN_ERR,
3286 LOG_TRACE_EVENT, "2607 Failed to allocate "
3287 "init_vpi mailbox\n");
3290 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
3291 mboxq->vport = vport;
3292 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
3293 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
3294 if (rc == MBX_NOT_FINISHED) {
3295 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3296 "2608 Failed to issue init_vpi mailbox\n");
3297 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3302 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
3303 * @phba: pointer to lpfc hba data structure.
3305 * This function loops through the list of vports on the @phba and issues an
3306 * FDISC if possible.
3309 lpfc_start_fdiscs(struct lpfc_hba *phba)
3311 struct lpfc_vport **vports;
3314 vports = lpfc_create_vport_work_array(phba);
3315 if (vports != NULL) {
3316 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3317 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
3319 /* There are no vpi for this vport */
3320 if (vports[i]->vpi > phba->max_vpi) {
3321 lpfc_vport_set_state(vports[i],
3325 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3326 lpfc_vport_set_state(vports[i],
3330 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
3331 lpfc_issue_init_vpi(vports[i]);
3334 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3335 lpfc_initial_fdisc(vports[i]);
3337 lpfc_vport_set_state(vports[i],
3338 FC_VPORT_NO_FABRIC_SUPP);
3339 lpfc_printf_vlog(vports[i], KERN_ERR,
3342 "Fabric support\n");
3346 lpfc_destroy_vport_work_array(phba, vports);
3350 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3352 struct lpfc_vport *vport = mboxq->vport;
3353 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3356 * VFI not supported for interface type 0, so ignore any mailbox
3357 * error (except VFI in use) and continue with the discovery.
3359 if (mboxq->u.mb.mbxStatus &&
3360 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3361 LPFC_SLI_INTF_IF_TYPE_0) &&
3362 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3363 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3364 "2018 REG_VFI mbxStatus error x%x "
3366 mboxq->u.mb.mbxStatus, vport->port_state);
3367 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3368 /* FLOGI failed, use loop map to make discovery list */
3369 lpfc_disc_list_loopmap(vport);
3370 /* Start discovery */
3371 lpfc_disc_start(vport);
3374 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3378 /* If the VFI is already registered, there is nothing else to do
3379 * Unless this was a VFI update and we are in PT2PT mode, then
3380 * we should drop through to set the port state to ready.
3382 if (vport->fc_flag & FC_VFI_REGISTERED)
3383 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3384 vport->fc_flag & FC_PT2PT))
3387 /* The VPI is implicitly registered when the VFI is registered */
3388 spin_lock_irq(shost->host_lock);
3389 vport->vpi_state |= LPFC_VPI_REGISTERED;
3390 vport->fc_flag |= FC_VFI_REGISTERED;
3391 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3392 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3393 spin_unlock_irq(shost->host_lock);
3395 /* In case SLI4 FC loopback test, we are ready */
3396 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3397 (phba->link_flag & LS_LOOPBACK_MODE)) {
3398 phba->link_state = LPFC_HBA_READY;
3402 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3403 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3404 "alpacnt:%d LinkState:%x topology:%x\n",
3405 vport->port_state, vport->fc_flag, vport->fc_myDID,
3406 vport->phba->alpa_map[0],
3407 phba->link_state, phba->fc_topology);
3409 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3411 * For private loop or for NPort pt2pt,
3412 * just start discovery and we are done.
3414 if ((vport->fc_flag & FC_PT2PT) ||
3415 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3416 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3418 /* Use loop map to make discovery list */
3419 lpfc_disc_list_loopmap(vport);
3420 /* Start discovery */
3421 if (vport->fc_flag & FC_PT2PT)
3422 vport->port_state = LPFC_VPORT_READY;
3424 lpfc_disc_start(vport);
3426 lpfc_start_fdiscs(phba);
3427 lpfc_do_scr_ns_plogi(phba, vport);
3432 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
3436 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3438 MAILBOX_t *mb = &pmb->u.mb;
3439 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3440 struct lpfc_vport *vport = pmb->vport;
3441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3442 struct serv_parm *sp = &vport->fc_sparam;
3445 /* Check for error */
3446 if (mb->mbxStatus) {
3447 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3448 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3449 "0319 READ_SPARAM mbxStatus error x%x "
3451 mb->mbxStatus, vport->port_state);
3452 lpfc_linkdown(phba);
3456 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3457 sizeof (struct serv_parm));
3459 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3460 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3461 ed_tov = (ed_tov + 999999) / 1000000;
3463 phba->fc_edtov = ed_tov;
3464 phba->fc_ratov = (2 * ed_tov) / 1000;
3465 if (phba->fc_ratov < FF_DEF_RATOV) {
3466 /* RA_TOV should be atleast 10sec for initial flogi */
3467 phba->fc_ratov = FF_DEF_RATOV;
3470 lpfc_update_vport_wwn(vport);
3471 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3472 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3473 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3474 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3477 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3479 /* Check if sending the FLOGI is being deferred to after we get
3480 * up to date CSPs from MBX_READ_SPARAM.
3482 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3483 lpfc_initial_flogi(vport);
3484 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3489 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3490 lpfc_issue_clear_la(phba, vport);
3494 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3496 struct lpfc_vport *vport = phba->pport;
3497 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3498 struct Scsi_Host *shost;
3501 struct fcf_record *fcf_record;
3502 uint32_t fc_flags = 0;
3503 unsigned long iflags;
3505 spin_lock_irqsave(&phba->hbalock, iflags);
3506 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3508 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3509 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3510 case LPFC_LINK_SPEED_1GHZ:
3511 case LPFC_LINK_SPEED_2GHZ:
3512 case LPFC_LINK_SPEED_4GHZ:
3513 case LPFC_LINK_SPEED_8GHZ:
3514 case LPFC_LINK_SPEED_10GHZ:
3515 case LPFC_LINK_SPEED_16GHZ:
3516 case LPFC_LINK_SPEED_32GHZ:
3517 case LPFC_LINK_SPEED_64GHZ:
3518 case LPFC_LINK_SPEED_128GHZ:
3519 case LPFC_LINK_SPEED_256GHZ:
3522 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3527 if (phba->fc_topology &&
3528 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3529 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3530 "3314 Toplogy changed was 0x%x is 0x%x\n",
3532 bf_get(lpfc_mbx_read_top_topology, la));
3533 phba->fc_topology_changed = 1;
3536 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3537 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
3539 shost = lpfc_shost_from_vport(vport);
3540 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3541 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3543 /* if npiv is enabled and this adapter supports npiv log
3544 * a message that npiv is not supported in this topology
3546 if (phba->cfg_enable_npiv && phba->max_vpi)
3547 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3548 "1309 Link Up Event npiv not supported in loop "
3550 /* Get Loop Map information */
3551 if (bf_get(lpfc_mbx_read_top_il, la))
3552 fc_flags |= FC_LBIT;
3554 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3555 i = la->lilpBde64.tus.f.bdeSize;
3558 phba->alpa_map[0] = 0;
3560 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3571 numalpa = phba->alpa_map[0];
3573 while (j < numalpa) {
3574 memset(un.pamap, 0, 16);
3575 for (k = 1; j < numalpa; k++) {
3577 phba->alpa_map[j + 1];
3582 /* Link Up Event ALPA map */
3583 lpfc_printf_log(phba,
3586 "1304 Link Up Event "
3587 "ALPA map Data: x%x "
3589 un.pa.wd1, un.pa.wd2,
3590 un.pa.wd3, un.pa.wd4);
3595 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3596 if (phba->max_vpi && phba->cfg_enable_npiv &&
3597 (phba->sli_rev >= LPFC_SLI_REV3))
3598 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3600 vport->fc_myDID = phba->fc_pref_DID;
3601 fc_flags |= FC_LBIT;
3603 spin_unlock_irqrestore(&phba->hbalock, iflags);
3606 spin_lock_irqsave(shost->host_lock, iflags);
3607 vport->fc_flag |= fc_flags;
3608 spin_unlock_irqrestore(shost->host_lock, iflags);
3614 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3618 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3620 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3623 sparam_mbox->vport = vport;
3624 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3625 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3626 if (rc == MBX_NOT_FINISHED) {
3627 lpfc_mbox_rsrc_cleanup(phba, sparam_mbox, MBOX_THD_UNLOCKED);
3631 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3632 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3635 vport->port_state = LPFC_LOCAL_CFG_LINK;
3636 lpfc_config_link(phba, cfglink_mbox);
3637 cfglink_mbox->vport = vport;
3638 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3639 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3640 if (rc == MBX_NOT_FINISHED) {
3641 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3645 vport->port_state = LPFC_VPORT_UNKNOWN;
3647 * Add the driver's default FCF record at FCF index 0 now. This
3648 * is phase 1 implementation that support FCF index 0 and driver
3651 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3652 fcf_record = kzalloc(sizeof(struct fcf_record),
3654 if (unlikely(!fcf_record)) {
3655 lpfc_printf_log(phba, KERN_ERR,
3657 "2554 Could not allocate memory for "
3663 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3664 LPFC_FCOE_FCF_DEF_INDEX);
3665 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3667 lpfc_printf_log(phba, KERN_ERR,
3669 "2013 Could not manually add FCF "
3670 "record 0, status %d\n", rc);
3678 * The driver is expected to do FIP/FCF. Call the port
3679 * and get the FCF Table.
3681 spin_lock_irqsave(&phba->hbalock, iflags);
3682 if (phba->hba_flag & FCF_TS_INPROG) {
3683 spin_unlock_irqrestore(&phba->hbalock, iflags);
3686 /* This is the initial FCF discovery scan */
3687 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3688 spin_unlock_irqrestore(&phba->hbalock, iflags);
3689 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3690 "2778 Start FCF table scan at linkup\n");
3691 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3692 LPFC_FCOE_FCF_GET_FIRST);
3694 spin_lock_irqsave(&phba->hbalock, iflags);
3695 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3696 spin_unlock_irqrestore(&phba->hbalock, iflags);
3699 /* Reset FCF roundrobin bmask for new discovery */
3700 lpfc_sli4_clear_fcf_rr_bmask(phba);
3703 /* Prepare for LINK up registrations */
3704 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3705 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3706 init_utsname()->nodename);
3709 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3710 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3711 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3712 vport->port_state, sparam_mbox, cfglink_mbox);
3713 lpfc_issue_clear_la(phba, vport);
3718 lpfc_enable_la(struct lpfc_hba *phba)
3721 struct lpfc_sli *psli = &phba->sli;
3722 spin_lock_irq(&phba->hbalock);
3723 psli->sli_flag |= LPFC_PROCESS_LA;
3724 if (phba->sli_rev <= LPFC_SLI_REV3) {
3725 control = readl(phba->HCregaddr);
3726 control |= HC_LAINT_ENA;
3727 writel(control, phba->HCregaddr);
3728 readl(phba->HCregaddr); /* flush */
3730 spin_unlock_irq(&phba->hbalock);
3734 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3736 lpfc_linkdown(phba);
3737 lpfc_enable_la(phba);
3738 lpfc_unregister_unused_fcf(phba);
3739 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3744 * This routine handles processing a READ_TOPOLOGY mailbox
3745 * command upon completion. It is setup in the LPFC_MBOXQ
3746 * as the completion routine when the command is
3747 * handed off to the SLI layer. SLI4 only.
3750 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3752 struct lpfc_vport *vport = pmb->vport;
3753 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3754 struct lpfc_mbx_read_top *la;
3755 struct lpfc_sli_ring *pring;
3756 MAILBOX_t *mb = &pmb->u.mb;
3757 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3759 unsigned long iflags;
3761 /* Unblock ELS traffic */
3762 pring = lpfc_phba_elsring(phba);
3764 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3766 /* Check for error */
3767 if (mb->mbxStatus) {
3768 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3769 "1307 READ_LA mbox error x%x state x%x\n",
3770 mb->mbxStatus, vport->port_state);
3771 lpfc_mbx_issue_link_down(phba);
3772 phba->link_state = LPFC_HBA_ERROR;
3773 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3776 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3777 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3779 memcpy(&phba->alpa_map[0], mp->virt, 128);
3781 spin_lock_irqsave(shost->host_lock, iflags);
3782 if (bf_get(lpfc_mbx_read_top_pb, la))
3783 vport->fc_flag |= FC_BYPASSED_MODE;
3785 vport->fc_flag &= ~FC_BYPASSED_MODE;
3786 spin_unlock_irqrestore(shost->host_lock, iflags);
3788 if (phba->fc_eventTag <= la->eventTag) {
3789 phba->fc_stat.LinkMultiEvent++;
3790 if (attn_type == LPFC_ATT_LINK_UP)
3791 if (phba->fc_eventTag != 0)
3792 lpfc_linkdown(phba);
3795 phba->fc_eventTag = la->eventTag;
3796 phba->link_events++;
3797 if (attn_type == LPFC_ATT_LINK_UP) {
3798 phba->fc_stat.LinkUp++;
3799 if (phba->link_flag & LS_LOOPBACK_MODE) {
3800 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3801 "1306 Link Up Event in loop back mode "
3802 "x%x received Data: x%x x%x x%x x%x\n",
3803 la->eventTag, phba->fc_eventTag,
3804 bf_get(lpfc_mbx_read_top_alpa_granted,
3806 bf_get(lpfc_mbx_read_top_link_spd, la),
3809 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3810 "1303 Link Up Event x%x received "
3811 "Data: x%x x%x x%x x%x x%x\n",
3812 la->eventTag, phba->fc_eventTag,
3813 bf_get(lpfc_mbx_read_top_alpa_granted,
3815 bf_get(lpfc_mbx_read_top_link_spd, la),
3817 bf_get(lpfc_mbx_read_top_fa, la));
3819 lpfc_mbx_process_link_up(phba, la);
3821 if (phba->cmf_active_mode != LPFC_CFG_OFF)
3822 lpfc_cmf_signal_init(phba);
3824 if (phba->lmt & LMT_64Gb)
3825 lpfc_read_lds_params(phba);
3827 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3828 attn_type == LPFC_ATT_UNEXP_WWPN) {
3829 phba->fc_stat.LinkDown++;
3830 if (phba->link_flag & LS_LOOPBACK_MODE)
3831 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3832 "1308 Link Down Event in loop back mode "
3834 "Data: x%x x%x x%x\n",
3835 la->eventTag, phba->fc_eventTag,
3836 phba->pport->port_state, vport->fc_flag);
3837 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3838 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3839 "1313 Link Down Unexpected FA WWPN Event x%x "
3840 "received Data: x%x x%x x%x x%x\n",
3841 la->eventTag, phba->fc_eventTag,
3842 phba->pport->port_state, vport->fc_flag,
3843 bf_get(lpfc_mbx_read_top_fa, la));
3845 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3846 "1305 Link Down Event x%x received "
3847 "Data: x%x x%x x%x x%x\n",
3848 la->eventTag, phba->fc_eventTag,
3849 phba->pport->port_state, vport->fc_flag,
3850 bf_get(lpfc_mbx_read_top_fa, la));
3851 lpfc_mbx_issue_link_down(phba);
3854 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3855 bf_get(lpfc_mbx_read_top_fa, la))
3856 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3858 bf_get(lpfc_mbx_read_top_fa, la));
3860 lpfc_mbx_cmpl_read_topology_free_mbuf:
3861 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3865 * This routine handles processing a REG_LOGIN mailbox
3866 * command upon completion. It is setup in the LPFC_MBOXQ
3867 * as the completion routine when the command is
3868 * handed off to the SLI layer.
3871 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3873 struct lpfc_vport *vport = pmb->vport;
3874 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3875 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3877 /* The driver calls the state machine with the pmb pointer
3878 * but wants to make sure a stale ctx_buf isn't acted on.
3879 * The ctx_buf is restored later and cleaned up.
3881 pmb->ctx_buf = NULL;
3882 pmb->ctx_ndlp = NULL;
3884 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
3885 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3886 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3887 kref_read(&ndlp->kref),
3889 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3890 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3892 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3893 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3894 /* We rcvd a rscn after issuing this
3895 * mbox reg login, we may have cycled
3896 * back through the state and be
3897 * back at reg login state so this
3898 * mbox needs to be ignored becase
3899 * there is another reg login in
3902 spin_lock_irq(&ndlp->lock);
3903 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3904 spin_unlock_irq(&ndlp->lock);
3907 * We cannot leave the RPI registered because
3908 * if we go thru discovery again for this ndlp
3909 * a subsequent REG_RPI will fail.
3911 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3912 lpfc_unreg_rpi(vport, ndlp);
3915 /* Call state machine */
3916 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3918 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3920 /* decrement the node reference count held for this callback
3929 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3931 MAILBOX_t *mb = &pmb->u.mb;
3932 struct lpfc_vport *vport = pmb->vport;
3933 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3935 switch (mb->mbxStatus) {
3938 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3939 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3942 /* If VPI is busy, reset the HBA */
3944 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3945 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3946 vport->vpi, mb->mbxStatus);
3947 if (!(phba->pport->load_flag & FC_UNLOADING))
3948 lpfc_workq_post_event(phba, NULL, NULL,
3949 LPFC_EVT_RESET_HBA);
3951 spin_lock_irq(shost->host_lock);
3952 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3953 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3954 spin_unlock_irq(shost->host_lock);
3955 mempool_free(pmb, phba->mbox_mem_pool);
3956 lpfc_cleanup_vports_rrqs(vport, NULL);
3958 * This shost reference might have been taken at the beginning of
3959 * lpfc_vport_delete()
3961 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3962 scsi_host_put(shost);
3966 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3968 struct lpfc_hba *phba = vport->phba;
3972 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3976 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3977 mbox->vport = vport;
3978 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3979 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3980 if (rc == MBX_NOT_FINISHED) {
3981 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3982 "1800 Could not issue unreg_vpi\n");
3983 mempool_free(mbox, phba->mbox_mem_pool);
3990 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3992 struct lpfc_vport *vport = pmb->vport;
3993 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3994 MAILBOX_t *mb = &pmb->u.mb;
3996 switch (mb->mbxStatus) {
4000 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4001 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
4003 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4004 spin_lock_irq(shost->host_lock);
4005 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4006 spin_unlock_irq(shost->host_lock);
4007 vport->fc_myDID = 0;
4009 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4010 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4011 if (phba->nvmet_support)
4012 lpfc_nvmet_update_targetport(phba);
4014 lpfc_nvme_update_localport(vport);
4019 spin_lock_irq(shost->host_lock);
4020 vport->vpi_state |= LPFC_VPI_REGISTERED;
4021 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4022 spin_unlock_irq(shost->host_lock);
4023 vport->num_disc_nodes = 0;
4024 /* go thru NPR list and issue ELS PLOGIs */
4025 if (vport->fc_npr_cnt)
4026 lpfc_els_disc_plogi(vport);
4028 if (!vport->num_disc_nodes) {
4029 spin_lock_irq(shost->host_lock);
4030 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4031 spin_unlock_irq(shost->host_lock);
4032 lpfc_can_disctmo(vport);
4034 vport->port_state = LPFC_VPORT_READY;
4037 mempool_free(pmb, phba->mbox_mem_pool);
4042 * lpfc_create_static_vport - Read HBA config region to create static vports.
4043 * @phba: pointer to lpfc hba data structure.
4045 * This routine issue a DUMP mailbox command for config region 22 to get
4046 * the list of static vports to be created. The function create vports
4047 * based on the information returned from the HBA.
4050 lpfc_create_static_vport(struct lpfc_hba *phba)
4052 LPFC_MBOXQ_t *pmb = NULL;
4054 struct static_vport_info *vport_info;
4055 int mbx_wait_rc = 0, i;
4056 struct fc_vport_identifiers vport_id;
4057 struct fc_vport *new_fc_vport;
4058 struct Scsi_Host *shost;
4059 struct lpfc_vport *vport;
4060 uint16_t offset = 0;
4061 uint8_t *vport_buff;
4062 struct lpfc_dmabuf *mp;
4063 uint32_t byte_count = 0;
4065 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4067 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4068 "0542 lpfc_create_static_vport failed to"
4069 " allocate mailbox memory\n");
4072 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
4075 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
4077 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4078 "0543 lpfc_create_static_vport failed to"
4079 " allocate vport_info\n");
4080 mempool_free(pmb, phba->mbox_mem_pool);
4084 vport_buff = (uint8_t *) vport_info;
4086 /* While loop iteration forces a free dma buffer from
4087 * the previous loop because the mbox is reused and
4088 * the dump routine is a single-use construct.
4091 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4092 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4094 pmb->ctx_buf = NULL;
4096 if (lpfc_dump_static_vport(phba, pmb, offset))
4099 pmb->vport = phba->pport;
4100 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
4103 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
4104 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4105 "0544 lpfc_create_static_vport failed to"
4106 " issue dump mailbox command ret 0x%x "
4108 mbx_wait_rc, mb->mbxStatus);
4112 if (phba->sli_rev == LPFC_SLI_REV4) {
4113 byte_count = pmb->u.mqe.un.mb_words[5];
4114 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4115 if (byte_count > sizeof(struct static_vport_info) -
4117 byte_count = sizeof(struct static_vport_info)
4119 memcpy(vport_buff + offset, mp->virt, byte_count);
4120 offset += byte_count;
4122 if (mb->un.varDmp.word_cnt >
4123 sizeof(struct static_vport_info) - offset)
4124 mb->un.varDmp.word_cnt =
4125 sizeof(struct static_vport_info)
4127 byte_count = mb->un.varDmp.word_cnt;
4128 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
4129 vport_buff + offset,
4132 offset += byte_count;
4135 } while (byte_count &&
4136 offset < sizeof(struct static_vport_info));
4139 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
4140 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
4141 != VPORT_INFO_REV)) {
4142 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4143 "0545 lpfc_create_static_vport bad"
4144 " information header 0x%x 0x%x\n",
4145 le32_to_cpu(vport_info->signature),
4146 le32_to_cpu(vport_info->rev) &
4147 VPORT_INFO_REV_MASK);
4152 shost = lpfc_shost_from_vport(phba->pport);
4154 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
4155 memset(&vport_id, 0, sizeof(vport_id));
4156 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
4157 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
4158 if (!vport_id.port_name || !vport_id.node_name)
4161 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
4162 vport_id.vport_type = FC_PORTTYPE_NPIV;
4163 vport_id.disable = false;
4164 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
4166 if (!new_fc_vport) {
4167 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4168 "0546 lpfc_create_static_vport failed to"
4173 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
4174 vport->vport_flag |= STATIC_VPORT;
4179 if (mbx_wait_rc != MBX_TIMEOUT)
4180 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4184 * This routine handles processing a Fabric REG_LOGIN mailbox
4185 * command upon completion. It is setup in the LPFC_MBOXQ
4186 * as the completion routine when the command is
4187 * handed off to the SLI layer.
4190 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4192 struct lpfc_vport *vport = pmb->vport;
4193 MAILBOX_t *mb = &pmb->u.mb;
4194 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4195 struct Scsi_Host *shost;
4197 pmb->ctx_ndlp = NULL;
4199 if (mb->mbxStatus) {
4200 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4201 "0258 Register Fabric login error: 0x%x\n",
4203 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4204 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4205 /* FLOGI failed, use loop map to make discovery list */
4206 lpfc_disc_list_loopmap(vport);
4208 /* Start discovery */
4209 lpfc_disc_start(vport);
4210 /* Decrement the reference count to ndlp after the
4211 * reference to the ndlp are done.
4217 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4218 /* Decrement the reference count to ndlp after the reference
4219 * to the ndlp are done.
4225 if (phba->sli_rev < LPFC_SLI_REV4)
4226 ndlp->nlp_rpi = mb->un.varWords[0];
4227 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4228 ndlp->nlp_type |= NLP_FABRIC;
4229 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4231 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
4232 /* when physical port receive logo donot start
4233 * vport discovery */
4234 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
4235 lpfc_start_fdiscs(phba);
4237 shost = lpfc_shost_from_vport(vport);
4238 spin_lock_irq(shost->host_lock);
4239 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
4240 spin_unlock_irq(shost->host_lock);
4242 lpfc_do_scr_ns_plogi(phba, vport);
4245 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4247 /* Drop the reference count from the mbox at the end after
4248 * all the current reference to the ndlp have been done.
4255 * This routine will issue a GID_FT for each FC4 Type supported
4256 * by the driver. ALL GID_FTs must complete before discovery is started.
4259 lpfc_issue_gidft(struct lpfc_vport *vport)
4261 /* Good status, issue CT Request to NameServer */
4262 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4263 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
4264 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
4265 /* Cannot issue NameServer FCP Query, so finish up
4268 lpfc_printf_vlog(vport, KERN_ERR,
4270 "0604 %s FC TYPE %x %s\n",
4271 "Failed to issue GID_FT to ",
4273 "Finishing discovery.");
4279 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4280 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4281 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4282 /* Cannot issue NameServer NVME Query, so finish up
4285 lpfc_printf_vlog(vport, KERN_ERR,
4287 "0605 %s FC_TYPE %x %s %d\n",
4288 "Failed to issue GID_FT to ",
4290 "Finishing discovery: gidftinp ",
4292 if (vport->gidft_inp == 0)
4297 return vport->gidft_inp;
4301 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4302 * @vport: The virtual port for which this call is being executed.
4304 * This routine will issue a GID_PT to get a list of all N_Ports
4307 * 0 - Failure to issue a GID_PT
4311 lpfc_issue_gidpt(struct lpfc_vport *vport)
4313 /* Good status, issue CT Request to NameServer */
4314 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4315 /* Cannot issue NameServer FCP Query, so finish up
4318 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4319 "0606 %s Port TYPE %x %s\n",
4320 "Failed to issue GID_PT to ",
4322 "Finishing discovery.");
4330 * This routine handles processing a NameServer REG_LOGIN mailbox
4331 * command upon completion. It is setup in the LPFC_MBOXQ
4332 * as the completion routine when the command is
4333 * handed off to the SLI layer.
4336 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4338 MAILBOX_t *mb = &pmb->u.mb;
4339 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4340 struct lpfc_vport *vport = pmb->vport;
4343 pmb->ctx_ndlp = NULL;
4344 vport->gidft_inp = 0;
4346 if (mb->mbxStatus) {
4347 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4348 "0260 Register NameServer error: 0x%x\n",
4352 /* decrement the node reference count held for this
4353 * callback function.
4356 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4358 /* If the node is not registered with the scsi or nvme
4359 * transport, remove the fabric node. The failed reg_login
4360 * is terminal and forces the removal of the last node
4363 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4364 spin_lock_irq(&ndlp->lock);
4365 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4366 spin_unlock_irq(&ndlp->lock);
4370 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4372 * RegLogin failed, use loop map to make discovery
4375 lpfc_disc_list_loopmap(vport);
4377 /* Start discovery */
4378 lpfc_disc_start(vport);
4381 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4385 if (phba->sli_rev < LPFC_SLI_REV4)
4386 ndlp->nlp_rpi = mb->un.varWords[0];
4387 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4388 ndlp->nlp_type |= NLP_FABRIC;
4389 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4390 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4391 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4392 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4393 kref_read(&ndlp->kref),
4396 if (vport->port_state < LPFC_VPORT_READY) {
4397 /* Link up discovery requires Fabric registration. */
4398 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4399 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4400 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4401 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4403 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4404 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4405 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4407 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4408 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4409 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4412 /* Issue SCR just before NameServer GID_FT Query */
4413 lpfc_issue_els_scr(vport, 0);
4415 /* Link was bounced or a Fabric LOGO occurred. Start EDC
4416 * with initial FW values provided the congestion mode is
4417 * not off. Note that signals may or may not be supported
4418 * by the adapter but FPIN is provided by default for 1
4419 * or both missing signals support.
4421 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
4422 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
4423 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
4424 rc = lpfc_issue_els_edc(vport, 0);
4425 lpfc_printf_log(phba, KERN_INFO,
4426 LOG_INIT | LOG_ELS | LOG_DISCOVERY,
4427 "4220 Issue EDC status x%x Data x%x\n",
4428 rc, phba->cgn_init_reg_signal);
4429 } else if (phba->lmt & LMT_64Gb) {
4430 /* may send link fault capability descriptor */
4431 lpfc_issue_els_edc(vport, 0);
4433 lpfc_issue_els_rdf(vport, 0);
4437 vport->fc_ns_retry = 0;
4438 if (lpfc_issue_gidft(vport) == 0)
4442 * At this point in time we may need to wait for multiple
4443 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4445 * decrement the node reference count held for this
4446 * callback function.
4449 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4454 * This routine handles processing a Fabric Controller REG_LOGIN mailbox
4455 * command upon completion. It is setup in the LPFC_MBOXQ
4456 * as the completion routine when the command is handed off to the SLI layer.
4459 lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4461 struct lpfc_vport *vport = pmb->vport;
4462 MAILBOX_t *mb = &pmb->u.mb;
4463 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4465 pmb->ctx_ndlp = NULL;
4466 if (mb->mbxStatus) {
4467 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4468 "0933 %s: Register FC login error: 0x%x\n",
4469 __func__, mb->mbxStatus);
4473 lpfc_check_nlp_post_devloss(vport, ndlp);
4475 if (phba->sli_rev < LPFC_SLI_REV4)
4476 ndlp->nlp_rpi = mb->un.varWords[0];
4478 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4479 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4480 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4483 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4484 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4485 ndlp->nlp_type |= NLP_FABRIC;
4486 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4489 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4491 /* Drop the reference count from the mbox at the end after
4492 * all the current reference to the ndlp have been done.
4498 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4500 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4501 struct fc_rport *rport;
4502 struct lpfc_rport_data *rdata;
4503 struct fc_rport_identifiers rport_ids;
4504 struct lpfc_hba *phba = vport->phba;
4505 unsigned long flags;
4507 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4510 /* Remote port has reappeared. Re-register w/ FC transport */
4511 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4512 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4513 rport_ids.port_id = ndlp->nlp_DID;
4514 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4517 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4518 "rport add: did:x%x flg:x%x type x%x",
4519 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4521 /* Don't add the remote port if unloading. */
4522 if (vport->load_flag & FC_UNLOADING)
4525 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4527 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4528 "Warning: fc_remote_port_add failed\n");
4532 /* Successful port add. Complete initializing node data */
4533 rport->maxframe_size = ndlp->nlp_maxframe;
4534 rport->supported_classes = ndlp->nlp_class_sup;
4535 rdata = rport->dd_data;
4536 rdata->pnode = lpfc_nlp_get(ndlp);
4537 if (!rdata->pnode) {
4538 dev_warn(&phba->pcidev->dev,
4539 "Warning - node ref failed. Unreg rport\n");
4540 fc_remote_port_delete(rport);
4545 spin_lock_irqsave(&ndlp->lock, flags);
4546 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4547 spin_unlock_irqrestore(&ndlp->lock, flags);
4549 if (ndlp->nlp_type & NLP_FCP_TARGET)
4550 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4551 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4552 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4553 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4554 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4555 if (ndlp->nlp_type & NLP_NVME_TARGET)
4556 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4557 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4558 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4560 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4561 fc_remote_port_rolechg(rport, rport_ids.roles);
4563 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4564 "3183 %s rport x%px DID x%x, role x%x refcnt %d\n",
4565 __func__, rport, rport->port_id, rport->roles,
4566 kref_read(&ndlp->kref));
4568 if ((rport->scsi_target_id != -1) &&
4569 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4570 ndlp->nlp_sid = rport->scsi_target_id;
4577 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4579 struct fc_rport *rport = ndlp->rport;
4580 struct lpfc_vport *vport = ndlp->vport;
4582 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4585 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4586 "rport delete: did:x%x flg:x%x type x%x",
4587 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4589 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4590 "3184 rport unregister x%06x, rport x%px "
4591 "xptflg x%x refcnt %d\n",
4592 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags,
4593 kref_read(&ndlp->kref));
4595 fc_remote_port_delete(rport);
4600 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4603 unsigned long iflags;
4605 spin_lock_irqsave(shost->host_lock, iflags);
4607 case NLP_STE_UNUSED_NODE:
4608 vport->fc_unused_cnt += count;
4610 case NLP_STE_PLOGI_ISSUE:
4611 vport->fc_plogi_cnt += count;
4613 case NLP_STE_ADISC_ISSUE:
4614 vport->fc_adisc_cnt += count;
4616 case NLP_STE_REG_LOGIN_ISSUE:
4617 vport->fc_reglogin_cnt += count;
4619 case NLP_STE_PRLI_ISSUE:
4620 vport->fc_prli_cnt += count;
4622 case NLP_STE_UNMAPPED_NODE:
4623 vport->fc_unmap_cnt += count;
4625 case NLP_STE_MAPPED_NODE:
4626 vport->fc_map_cnt += count;
4628 case NLP_STE_NPR_NODE:
4629 if (vport->fc_npr_cnt == 0 && count == -1)
4630 vport->fc_npr_cnt = 0;
4632 vport->fc_npr_cnt += count;
4635 spin_unlock_irqrestore(shost->host_lock, iflags);
4638 /* Register a node with backend if not already done */
4640 lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4642 unsigned long iflags;
4644 lpfc_check_nlp_post_devloss(vport, ndlp);
4646 spin_lock_irqsave(&ndlp->lock, iflags);
4647 if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) {
4648 /* Already registered with backend, trigger rescan */
4649 spin_unlock_irqrestore(&ndlp->lock, iflags);
4651 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD &&
4652 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) {
4653 lpfc_nvme_rescan_port(vport, ndlp);
4658 ndlp->fc4_xpt_flags |= NLP_XPT_REGD;
4659 spin_unlock_irqrestore(&ndlp->lock, iflags);
4661 if (lpfc_valid_xpt_node(ndlp)) {
4662 vport->phba->nport_event_cnt++;
4664 * Tell the fc transport about the port, if we haven't
4665 * already. If we have, and it's a scsi entity, be
4667 lpfc_register_remote_port(vport, ndlp);
4670 /* We are done if we do not have any NVME remote node */
4671 if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME))
4674 /* Notify the NVME transport of this new rport. */
4675 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4676 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4677 if (vport->phba->nvmet_support == 0) {
4678 /* Register this rport with the transport.
4679 * Only NVME Target Rports are registered with
4682 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4683 vport->phba->nport_event_cnt++;
4684 lpfc_nvme_register_port(vport, ndlp);
4687 /* Just take an NDLP ref count since the
4688 * target does not register rports.
4695 /* Unregister a node with backend if not already done */
4697 lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4699 unsigned long iflags;
4701 spin_lock_irqsave(&ndlp->lock, iflags);
4702 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) {
4703 spin_unlock_irqrestore(&ndlp->lock, iflags);
4704 lpfc_printf_vlog(vport, KERN_INFO,
4705 LOG_ELS | LOG_NODE | LOG_DISCOVERY,
4706 "0999 %s Not regd: ndlp x%px rport x%px DID "
4707 "x%x FLG x%x XPT x%x\n",
4708 __func__, ndlp, ndlp->rport, ndlp->nlp_DID,
4709 ndlp->nlp_flag, ndlp->fc4_xpt_flags);
4713 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
4714 spin_unlock_irqrestore(&ndlp->lock, iflags);
4717 ndlp->fc4_xpt_flags & SCSI_XPT_REGD) {
4718 vport->phba->nport_event_cnt++;
4719 lpfc_unregister_remote_port(ndlp);
4720 } else if (!ndlp->rport) {
4721 lpfc_printf_vlog(vport, KERN_INFO,
4722 LOG_ELS | LOG_NODE | LOG_DISCOVERY,
4723 "1999 %s NDLP in devloss x%px DID x%x FLG x%x"
4724 " XPT x%x refcnt %u\n",
4725 __func__, ndlp, ndlp->nlp_DID, ndlp->nlp_flag,
4726 ndlp->fc4_xpt_flags,
4727 kref_read(&ndlp->kref));
4730 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) {
4731 vport->phba->nport_event_cnt++;
4732 if (vport->phba->nvmet_support == 0) {
4733 /* Start devloss if target. */
4734 if (ndlp->nlp_type & NLP_NVME_TARGET)
4735 lpfc_nvme_unregister_port(vport, ndlp);
4737 /* NVMET has no upcall. */
4745 * Adisc state change handling
4748 lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4751 switch (new_state) {
4753 * Any state to ADISC_ISSUE
4754 * Do nothing, adisc cmpl handling will trigger state changes
4756 case NLP_STE_ADISC_ISSUE:
4760 * ADISC_ISSUE to mapped states
4761 * Trigger a registration with backend, it will be nop if
4762 * already registered
4764 case NLP_STE_UNMAPPED_NODE:
4765 ndlp->nlp_type |= NLP_FC_NODE;
4767 case NLP_STE_MAPPED_NODE:
4768 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4769 lpfc_nlp_reg_node(vport, ndlp);
4773 * ADISC_ISSUE to non-mapped states
4774 * We are moving from ADISC_ISSUE to a non-mapped state because
4775 * ADISC failed, we would have skipped unregistering with
4776 * backend, attempt it now
4778 case NLP_STE_NPR_NODE:
4779 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4782 lpfc_nlp_unreg_node(vport, ndlp);
4789 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4790 int old_state, int new_state)
4792 /* Trap ADISC changes here */
4793 if (new_state == NLP_STE_ADISC_ISSUE ||
4794 old_state == NLP_STE_ADISC_ISSUE) {
4795 lpfc_handle_adisc_state(vport, ndlp, new_state);
4799 if (new_state == NLP_STE_UNMAPPED_NODE) {
4800 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4801 ndlp->nlp_type |= NLP_FC_NODE;
4803 if (new_state == NLP_STE_MAPPED_NODE)
4804 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4805 if (new_state == NLP_STE_NPR_NODE)
4806 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4808 /* Reg/Unreg for FCP and NVME Transport interface */
4809 if ((old_state == NLP_STE_MAPPED_NODE ||
4810 old_state == NLP_STE_UNMAPPED_NODE)) {
4811 /* For nodes marked for ADISC, Handle unreg in ADISC cmpl
4812 * if linkup. In linkdown do unreg_node
4814 if (!(ndlp->nlp_flag & NLP_NPR_ADISC) ||
4815 !lpfc_is_link_up(vport->phba))
4816 lpfc_nlp_unreg_node(vport, ndlp);
4819 if (new_state == NLP_STE_MAPPED_NODE ||
4820 new_state == NLP_STE_UNMAPPED_NODE)
4821 lpfc_nlp_reg_node(vport, ndlp);
4824 * If the node just added to Mapped list was an FCP target,
4825 * but the remote port registration failed or assigned a target
4826 * id outside the presentable range - move the node to the
4829 if ((new_state == NLP_STE_MAPPED_NODE) &&
4830 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4832 ndlp->rport->scsi_target_id == -1 ||
4833 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4834 spin_lock_irq(&ndlp->lock);
4835 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4836 spin_unlock_irq(&ndlp->lock);
4837 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4842 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4844 static char *states[] = {
4845 [NLP_STE_UNUSED_NODE] = "UNUSED",
4846 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4847 [NLP_STE_ADISC_ISSUE] = "ADISC",
4848 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4849 [NLP_STE_PRLI_ISSUE] = "PRLI",
4850 [NLP_STE_LOGO_ISSUE] = "LOGO",
4851 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4852 [NLP_STE_MAPPED_NODE] = "MAPPED",
4853 [NLP_STE_NPR_NODE] = "NPR",
4856 if (state < NLP_STE_MAX_STATE && states[state])
4857 strscpy(buffer, states[state], size);
4859 snprintf(buffer, size, "unknown (%d)", state);
4864 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4867 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4868 int old_state = ndlp->nlp_state;
4869 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
4870 char name1[16], name2[16];
4872 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4873 "0904 NPort state transition x%06x, %s -> %s\n",
4875 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4876 lpfc_nlp_state_name(name2, sizeof(name2), state));
4878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4879 "node statechg did:x%x old:%d ste:%d",
4880 ndlp->nlp_DID, old_state, state);
4882 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4883 state != NLP_STE_UNUSED_NODE) {
4884 ndlp->nlp_flag &= ~NLP_DROPPED;
4888 if (old_state == NLP_STE_NPR_NODE &&
4889 state != NLP_STE_NPR_NODE)
4890 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4891 if (old_state == NLP_STE_UNMAPPED_NODE) {
4892 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4893 ndlp->nlp_type &= ~NLP_FC_NODE;
4896 if (list_empty(&ndlp->nlp_listp)) {
4897 spin_lock_irq(shost->host_lock);
4898 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4899 spin_unlock_irq(shost->host_lock);
4900 } else if (old_state)
4901 lpfc_nlp_counters(vport, old_state, -1);
4903 ndlp->nlp_state = state;
4904 lpfc_nlp_counters(vport, state, 1);
4905 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4909 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4913 if (list_empty(&ndlp->nlp_listp)) {
4914 spin_lock_irq(shost->host_lock);
4915 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4916 spin_unlock_irq(shost->host_lock);
4921 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4923 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4925 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4926 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4927 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4928 spin_lock_irq(shost->host_lock);
4929 list_del_init(&ndlp->nlp_listp);
4930 spin_unlock_irq(shost->host_lock);
4931 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4932 NLP_STE_UNUSED_NODE);
4936 * lpfc_initialize_node - Initialize all fields of node object
4937 * @vport: Pointer to Virtual Port object.
4938 * @ndlp: Pointer to FC node object.
4939 * @did: FC_ID of the node.
4941 * This function is always called when node object need to be initialized.
4942 * It initializes all the fields of the node object. Although the reference
4943 * to phba from @ndlp can be obtained indirectly through it's reference to
4944 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4945 * to the life-span of the @ndlp might go beyond the existence of @vport as
4946 * the final release of ndlp is determined by its reference count. And, the
4947 * operation on @ndlp needs the reference to phba.
4950 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4953 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4954 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4955 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4956 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4958 ndlp->nlp_DID = did;
4959 ndlp->vport = vport;
4960 ndlp->phba = vport->phba;
4961 ndlp->nlp_sid = NLP_NO_SID;
4962 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4963 kref_init(&ndlp->kref);
4964 atomic_set(&ndlp->cmd_pending, 0);
4965 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4966 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4970 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4973 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4974 * be used when lpfc wants to remove the "last" lpfc_nlp_put() to
4975 * release the ndlp from the vport when conditions are correct.
4977 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4979 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4980 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4981 lpfc_cleanup_vports_rrqs(vport, ndlp);
4982 lpfc_unreg_rpi(vport, ndlp);
4985 /* NLP_DROPPED means another thread already removed the initial
4986 * reference from lpfc_nlp_init. If set, don't drop it again and
4987 * introduce an imbalance.
4989 spin_lock_irq(&ndlp->lock);
4990 if (!(ndlp->nlp_flag & NLP_DROPPED)) {
4991 ndlp->nlp_flag |= NLP_DROPPED;
4992 spin_unlock_irq(&ndlp->lock);
4996 spin_unlock_irq(&ndlp->lock);
5000 * Start / ReStart rescue timer for Discovery / RSCN handling
5003 lpfc_set_disctmo(struct lpfc_vport *vport)
5005 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5006 struct lpfc_hba *phba = vport->phba;
5009 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
5010 /* For FAN, timeout should be greater than edtov */
5011 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
5013 /* Normal discovery timeout should be > than ELS/CT timeout
5014 * FC spec states we need 3 * ratov for CT requests
5016 tmo = ((phba->fc_ratov * 3) + 3);
5020 if (!timer_pending(&vport->fc_disctmo)) {
5021 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5022 "set disc timer: tmo:x%x state:x%x flg:x%x",
5023 tmo, vport->port_state, vport->fc_flag);
5026 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
5027 spin_lock_irq(shost->host_lock);
5028 vport->fc_flag |= FC_DISC_TMO;
5029 spin_unlock_irq(shost->host_lock);
5031 /* Start Discovery Timer state <hba_state> */
5032 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5033 "0247 Start Discovery Timer state x%x "
5034 "Data: x%x x%lx x%x x%x\n",
5035 vport->port_state, tmo,
5036 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
5037 vport->fc_adisc_cnt);
5043 * Cancel rescue timer for Discovery / RSCN handling
5046 lpfc_can_disctmo(struct lpfc_vport *vport)
5048 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5049 unsigned long iflags;
5051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5052 "can disc timer: state:x%x rtry:x%x flg:x%x",
5053 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5055 /* Turn off discovery timer if its running */
5056 if (vport->fc_flag & FC_DISC_TMO ||
5057 timer_pending(&vport->fc_disctmo)) {
5058 spin_lock_irqsave(shost->host_lock, iflags);
5059 vport->fc_flag &= ~FC_DISC_TMO;
5060 spin_unlock_irqrestore(shost->host_lock, iflags);
5061 del_timer_sync(&vport->fc_disctmo);
5062 spin_lock_irqsave(&vport->work_port_lock, iflags);
5063 vport->work_port_events &= ~WORKER_DISC_TMO;
5064 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
5067 /* Cancel Discovery Timer state <hba_state> */
5068 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5069 "0248 Cancel Discovery Timer state x%x "
5070 "Data: x%x x%x x%x\n",
5071 vport->port_state, vport->fc_flag,
5072 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
5077 * Check specified ring for outstanding IOCB on the SLI queue
5078 * Return true if iocb matches the specified nport
5081 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
5082 struct lpfc_sli_ring *pring,
5083 struct lpfc_iocbq *iocb,
5084 struct lpfc_nodelist *ndlp)
5086 struct lpfc_vport *vport = ndlp->vport;
5091 if (iocb->vport != vport)
5094 ulp_command = get_job_cmnd(phba, iocb);
5095 ulp_context = get_job_ulpcontext(phba, iocb);
5096 remote_id = get_job_els_rsp64_did(phba, iocb);
5098 if (pring->ringno == LPFC_ELS_RING) {
5099 switch (ulp_command) {
5100 case CMD_GEN_REQUEST64_CR:
5101 if (iocb->ndlp == ndlp)
5104 case CMD_ELS_REQUEST64_CR:
5105 if (remote_id == ndlp->nlp_DID)
5108 case CMD_XMIT_ELS_RSP64_CX:
5109 if (iocb->ndlp == ndlp)
5112 } else if (pring->ringno == LPFC_FCP_RING) {
5113 /* Skip match check if waiting to relogin to FCP target */
5114 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5115 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
5118 if (ulp_context == ndlp->nlp_rpi)
5125 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
5126 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
5127 struct list_head *dequeue_list)
5129 struct lpfc_iocbq *iocb, *next_iocb;
5131 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5132 /* Check to see if iocb matches the nport */
5133 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
5134 /* match, dequeue */
5135 list_move_tail(&iocb->list, dequeue_list);
5140 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
5141 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5143 struct lpfc_sli *psli = &phba->sli;
5146 spin_lock_irq(&phba->hbalock);
5147 for (i = 0; i < psli->num_rings; i++)
5148 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
5150 spin_unlock_irq(&phba->hbalock);
5154 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
5155 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5157 struct lpfc_sli_ring *pring;
5158 struct lpfc_queue *qp = NULL;
5160 spin_lock_irq(&phba->hbalock);
5161 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
5165 spin_lock(&pring->ring_lock);
5166 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
5167 spin_unlock(&pring->ring_lock);
5169 spin_unlock_irq(&phba->hbalock);
5173 * Free resources / clean up outstanding I/Os
5174 * associated with nlp_rpi in the LPFC_NODELIST entry.
5177 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5179 LIST_HEAD(completions);
5181 lpfc_fabric_abort_nport(ndlp);
5184 * Everything that matches on txcmplq will be returned
5185 * by firmware with a no rpi error.
5187 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5188 if (phba->sli_rev != LPFC_SLI_REV4)
5189 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
5191 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
5194 /* Cancel all the IOCBs from the completions list */
5195 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5202 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
5203 * @phba: Pointer to HBA context object.
5204 * @pmb: Pointer to mailbox object.
5206 * This function will issue an ELS LOGO command after completing
5210 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5212 struct lpfc_vport *vport = pmb->vport;
5213 struct lpfc_nodelist *ndlp;
5215 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
5218 lpfc_issue_els_logo(vport, ndlp, 0);
5220 /* Check to see if there are any deferred events to process */
5221 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
5222 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
5223 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5224 "1434 UNREG cmpl deferred logo x%x "
5225 "on NPort x%x Data: x%x x%px\n",
5226 ndlp->nlp_rpi, ndlp->nlp_DID,
5227 ndlp->nlp_defer_did, ndlp);
5229 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5230 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5231 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5233 /* NLP_RELEASE_RPI is only set for SLI4 ports. */
5234 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5235 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
5236 spin_lock_irq(&ndlp->lock);
5237 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5238 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5239 spin_unlock_irq(&ndlp->lock);
5241 spin_lock_irq(&ndlp->lock);
5242 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5243 spin_unlock_irq(&ndlp->lock);
5246 /* The node has an outstanding reference for the unreg. Now
5247 * that the LOGO action and cleanup are finished, release
5251 mempool_free(pmb, phba->mbox_mem_pool);
5255 * Sets the mailbox completion handler to be used for the
5256 * unreg_rpi command. The handler varies based on the state of
5257 * the port and what will be happening to the rpi next.
5260 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
5261 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
5263 unsigned long iflags;
5265 /* Driver always gets a reference on the mailbox job
5266 * in support of async jobs.
5268 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5269 if (!mbox->ctx_ndlp)
5272 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
5273 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
5275 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
5276 (!(vport->load_flag & FC_UNLOADING)) &&
5277 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
5278 LPFC_SLI_INTF_IF_TYPE_2) &&
5279 (kref_read(&ndlp->kref) > 0)) {
5280 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
5282 if (vport->load_flag & FC_UNLOADING) {
5283 if (phba->sli_rev == LPFC_SLI_REV4) {
5284 spin_lock_irqsave(&ndlp->lock, iflags);
5285 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5286 spin_unlock_irqrestore(&ndlp->lock, iflags);
5289 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5294 * Free rpi associated with LPFC_NODELIST entry.
5295 * This routine is called from lpfc_freenode(), when we are removing
5296 * a LPFC_NODELIST entry. It is also called if the driver initiates a
5297 * LOGO that completes successfully, and we are waiting to PLOGI back
5298 * to the remote NPort. In addition, it is called after we receive
5299 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
5300 * we are waiting to PLOGI back to the remote NPort.
5303 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5305 struct lpfc_hba *phba = vport->phba;
5307 int rc, acc_plogi = 1;
5310 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5311 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
5312 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
5313 lpfc_printf_vlog(vport, KERN_INFO,
5314 LOG_NODE | LOG_DISCOVERY,
5315 "3366 RPI x%x needs to be "
5316 "unregistered nlp_flag x%x "
5318 ndlp->nlp_rpi, ndlp->nlp_flag,
5321 /* If there is already an UNREG in progress for this ndlp,
5322 * no need to queue up another one.
5324 if (ndlp->nlp_flag & NLP_UNREG_INP) {
5325 lpfc_printf_vlog(vport, KERN_INFO,
5326 LOG_NODE | LOG_DISCOVERY,
5327 "1436 unreg_rpi SKIP UNREG x%x on "
5328 "NPort x%x deferred x%x flg x%x "
5330 ndlp->nlp_rpi, ndlp->nlp_DID,
5331 ndlp->nlp_defer_did,
5332 ndlp->nlp_flag, ndlp);
5336 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5338 /* SLI4 ports require the physical rpi value. */
5339 rpi = ndlp->nlp_rpi;
5340 if (phba->sli_rev == LPFC_SLI_REV4)
5341 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
5343 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
5344 mbox->vport = vport;
5345 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
5346 if (!mbox->ctx_ndlp) {
5347 mempool_free(mbox, phba->mbox_mem_pool);
5351 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
5353 * accept PLOGIs after unreg_rpi_cmpl
5356 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
5358 (!(vport->fc_flag & FC_OFFLINE_MODE)))
5359 ndlp->nlp_flag |= NLP_UNREG_INP;
5361 lpfc_printf_vlog(vport, KERN_INFO,
5362 LOG_NODE | LOG_DISCOVERY,
5363 "1433 unreg_rpi UNREG x%x on "
5364 "NPort x%x deferred flg x%x "
5366 ndlp->nlp_rpi, ndlp->nlp_DID,
5367 ndlp->nlp_flag, ndlp);
5369 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5370 if (rc == MBX_NOT_FINISHED) {
5371 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5372 mempool_free(mbox, phba->mbox_mem_pool);
5377 lpfc_printf_vlog(vport, KERN_INFO,
5378 LOG_NODE | LOG_DISCOVERY,
5379 "1444 Failed to allocate mempool "
5380 "unreg_rpi UNREG x%x, "
5381 "DID x%x, flag x%x, "
5383 ndlp->nlp_rpi, ndlp->nlp_DID,
5384 ndlp->nlp_flag, ndlp);
5386 /* Because mempool_alloc failed, we
5387 * will issue a LOGO here and keep the rpi alive if
5390 if (!(vport->load_flag & FC_UNLOADING)) {
5391 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5392 lpfc_issue_els_logo(vport, ndlp, 0);
5393 ndlp->nlp_prev_state = ndlp->nlp_state;
5394 lpfc_nlp_set_state(vport, ndlp,
5400 lpfc_no_rpi(phba, ndlp);
5402 if (phba->sli_rev != LPFC_SLI_REV4)
5404 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
5405 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5407 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5410 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5415 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5416 * @phba: pointer to lpfc hba data structure.
5418 * This routine is invoked to unregister all the currently registered RPIs
5422 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5424 struct lpfc_vport **vports;
5425 struct lpfc_nodelist *ndlp;
5426 struct Scsi_Host *shost;
5429 vports = lpfc_create_vport_work_array(phba);
5431 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5432 "2884 Vport array allocation failed \n");
5435 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5436 shost = lpfc_shost_from_vport(vports[i]);
5437 spin_lock_irq(shost->host_lock);
5438 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5439 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5440 /* The mempool_alloc might sleep */
5441 spin_unlock_irq(shost->host_lock);
5442 lpfc_unreg_rpi(vports[i], ndlp);
5443 spin_lock_irq(shost->host_lock);
5446 spin_unlock_irq(shost->host_lock);
5448 lpfc_destroy_vport_work_array(phba, vports);
5452 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5454 struct lpfc_hba *phba = vport->phba;
5458 if (phba->sli_rev == LPFC_SLI_REV4) {
5459 lpfc_sli4_unreg_all_rpis(vport);
5463 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5465 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5467 mbox->vport = vport;
5468 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5469 mbox->ctx_ndlp = NULL;
5470 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5471 if (rc != MBX_TIMEOUT)
5472 mempool_free(mbox, phba->mbox_mem_pool);
5474 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5475 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5476 "1836 Could not issue "
5477 "unreg_login(all_rpis) status %d\n",
5483 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5485 struct lpfc_hba *phba = vport->phba;
5489 /* Unreg DID is an SLI3 operation. */
5490 if (phba->sli_rev > LPFC_SLI_REV3)
5493 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5495 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5497 mbox->vport = vport;
5498 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5499 mbox->ctx_ndlp = NULL;
5500 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5501 if (rc != MBX_TIMEOUT)
5502 mempool_free(mbox, phba->mbox_mem_pool);
5504 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5505 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5506 "1815 Could not issue "
5507 "unreg_did (default rpis) status %d\n",
5513 * Free resources associated with LPFC_NODELIST entry
5514 * so it can be freed.
5517 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5519 struct lpfc_hba *phba = vport->phba;
5520 LPFC_MBOXQ_t *mb, *nextmb;
5522 /* Cleanup node for NPort <nlp_DID> */
5523 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5524 "0900 Cleanup node for NPort x%x "
5525 "Data: x%x x%x x%x\n",
5526 ndlp->nlp_DID, ndlp->nlp_flag,
5527 ndlp->nlp_state, ndlp->nlp_rpi);
5528 lpfc_dequeue_node(vport, ndlp);
5530 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5532 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5533 if ((mb = phba->sli.mbox_active)) {
5534 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5535 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5536 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5537 mb->ctx_ndlp = NULL;
5538 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5542 spin_lock_irq(&phba->hbalock);
5543 /* Cleanup REG_LOGIN completions which are not yet processed */
5544 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5545 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5546 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5547 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5550 mb->ctx_ndlp = NULL;
5551 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5554 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5555 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5556 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5557 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5558 list_del(&mb->list);
5559 lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_LOCKED);
5561 /* Don't invoke lpfc_nlp_put. The driver is in
5562 * lpfc_nlp_release context.
5566 spin_unlock_irq(&phba->hbalock);
5568 lpfc_els_abort(phba, ndlp);
5570 spin_lock_irq(&ndlp->lock);
5571 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5572 spin_unlock_irq(&ndlp->lock);
5574 ndlp->nlp_last_elscmd = 0;
5575 del_timer_sync(&ndlp->nlp_delayfunc);
5577 list_del_init(&ndlp->els_retry_evt.evt_listp);
5578 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5579 list_del_init(&ndlp->recovery_evt.evt_listp);
5580 lpfc_cleanup_vports_rrqs(vport, ndlp);
5582 if (phba->sli_rev == LPFC_SLI_REV4)
5583 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5589 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5592 D_ID mydid, ndlpdid, matchdid;
5594 if (did == Bcast_DID)
5597 /* First check for Direct match */
5598 if (ndlp->nlp_DID == did)
5601 /* Next check for area/domain identically equals 0 match */
5602 mydid.un.word = vport->fc_myDID;
5603 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5607 matchdid.un.word = did;
5608 ndlpdid.un.word = ndlp->nlp_DID;
5609 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5610 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5611 (mydid.un.b.area == matchdid.un.b.area)) {
5612 /* This code is supposed to match the ID
5613 * for a private loop device that is
5614 * connect to fl_port. But we need to
5615 * check that the port did not just go
5616 * from pt2pt to fabric or we could end
5617 * up matching ndlp->nlp_DID 000001 to
5618 * fabric DID 0x20101
5620 if ((ndlpdid.un.b.domain == 0) &&
5621 (ndlpdid.un.b.area == 0)) {
5622 if (ndlpdid.un.b.id &&
5623 vport->phba->fc_topology ==
5630 matchdid.un.word = ndlp->nlp_DID;
5631 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5632 (mydid.un.b.area == ndlpdid.un.b.area)) {
5633 if ((matchdid.un.b.domain == 0) &&
5634 (matchdid.un.b.area == 0)) {
5635 if (matchdid.un.b.id)
5643 /* Search for a nodelist entry */
5644 static struct lpfc_nodelist *
5645 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5647 struct lpfc_nodelist *ndlp;
5650 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5651 if (lpfc_matchdid(vport, ndlp, did)) {
5652 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5653 ((uint32_t)ndlp->nlp_xri << 16) |
5654 ((uint32_t)ndlp->nlp_type << 8)
5656 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5657 "0929 FIND node DID "
5658 "Data: x%px x%x x%x x%x x%x x%px\n",
5659 ndlp, ndlp->nlp_DID,
5660 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5661 ndlp->active_rrqs_xri_bitmap);
5666 /* FIND node did <did> NOT FOUND */
5667 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5668 "0932 FIND node did x%x NOT FOUND.\n", did);
5672 struct lpfc_nodelist *
5673 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5675 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5676 struct lpfc_nodelist *ndlp;
5677 unsigned long iflags;
5679 spin_lock_irqsave(shost->host_lock, iflags);
5680 ndlp = __lpfc_findnode_did(vport, did);
5681 spin_unlock_irqrestore(shost->host_lock, iflags);
5685 struct lpfc_nodelist *
5686 lpfc_findnode_mapped(struct lpfc_vport *vport)
5688 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5689 struct lpfc_nodelist *ndlp;
5691 unsigned long iflags;
5693 spin_lock_irqsave(shost->host_lock, iflags);
5695 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5696 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5697 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5698 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5699 ((uint32_t)ndlp->nlp_xri << 16) |
5700 ((uint32_t)ndlp->nlp_type << 8) |
5701 ((uint32_t)ndlp->nlp_rpi & 0xff));
5702 spin_unlock_irqrestore(shost->host_lock, iflags);
5703 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5704 "2025 FIND node DID "
5705 "Data: x%px x%x x%x x%x x%px\n",
5706 ndlp, ndlp->nlp_DID,
5707 ndlp->nlp_flag, data1,
5708 ndlp->active_rrqs_xri_bitmap);
5712 spin_unlock_irqrestore(shost->host_lock, iflags);
5714 /* FIND node did <did> NOT FOUND */
5715 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5716 "2026 FIND mapped did NOT FOUND.\n");
5720 struct lpfc_nodelist *
5721 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5723 struct lpfc_nodelist *ndlp;
5725 ndlp = lpfc_findnode_did(vport, did);
5727 if (vport->phba->nvmet_support)
5729 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5730 lpfc_rscn_payload_check(vport, did) == 0)
5732 ndlp = lpfc_nlp_init(vport, did);
5735 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5737 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5738 "6453 Setup New Node 2B_DISC x%x "
5739 "Data:x%x x%x x%x\n",
5740 ndlp->nlp_DID, ndlp->nlp_flag,
5741 ndlp->nlp_state, vport->fc_flag);
5743 spin_lock_irq(&ndlp->lock);
5744 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5745 spin_unlock_irq(&ndlp->lock);
5749 /* The NVME Target does not want to actively manage an rport.
5750 * The goal is to allow the target to reset its state and clear
5751 * pending IO in preparation for the initiator to recover.
5753 if ((vport->fc_flag & FC_RSCN_MODE) &&
5754 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5755 if (lpfc_rscn_payload_check(vport, did)) {
5757 /* Since this node is marked for discovery,
5758 * delay timeout is not needed.
5760 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5762 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5763 "6455 Setup RSCN Node 2B_DISC x%x "
5764 "Data:x%x x%x x%x\n",
5765 ndlp->nlp_DID, ndlp->nlp_flag,
5766 ndlp->nlp_state, vport->fc_flag);
5768 /* NVME Target mode waits until rport is known to be
5769 * impacted by the RSCN before it transitions. No
5770 * active management - just go to NPR provided the
5771 * node had a valid login.
5773 if (vport->phba->nvmet_support)
5776 /* If we've already received a PLOGI from this NPort
5777 * we don't need to try to discover it again.
5779 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5781 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5784 if (ndlp->nlp_state > NLP_STE_UNUSED_NODE &&
5785 ndlp->nlp_state < NLP_STE_PRLI_ISSUE) {
5786 lpfc_disc_state_machine(vport, ndlp, NULL,
5787 NLP_EVT_DEVICE_RECOVERY);
5790 spin_lock_irq(&ndlp->lock);
5791 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5792 spin_unlock_irq(&ndlp->lock);
5794 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5795 "6456 Skip Setup RSCN Node x%x "
5796 "Data:x%x x%x x%x\n",
5797 ndlp->nlp_DID, ndlp->nlp_flag,
5798 ndlp->nlp_state, vport->fc_flag);
5802 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5803 "6457 Setup Active Node 2B_DISC x%x "
5804 "Data:x%x x%x x%x\n",
5805 ndlp->nlp_DID, ndlp->nlp_flag,
5806 ndlp->nlp_state, vport->fc_flag);
5808 /* If the initiator received a PLOGI from this NPort or if the
5809 * initiator is already in the process of discovery on it,
5810 * there's no need to try to discover it again.
5812 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5813 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5814 (!vport->phba->nvmet_support &&
5815 ndlp->nlp_flag & NLP_RCV_PLOGI))
5818 if (vport->phba->nvmet_support)
5821 /* Moving to NPR state clears unsolicited flags and
5822 * allows for rediscovery
5824 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5826 spin_lock_irq(&ndlp->lock);
5827 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5828 spin_unlock_irq(&ndlp->lock);
5833 /* Build a list of nodes to discover based on the loopmap */
5835 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5837 struct lpfc_hba *phba = vport->phba;
5839 uint32_t alpa, index;
5841 if (!lpfc_is_link_up(phba))
5844 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5847 /* Check for loop map present or not */
5848 if (phba->alpa_map[0]) {
5849 for (j = 1; j <= phba->alpa_map[0]; j++) {
5850 alpa = phba->alpa_map[j];
5851 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5853 lpfc_setup_disc_node(vport, alpa);
5856 /* No alpamap, so try all alpa's */
5857 for (j = 0; j < FC_MAXLOOP; j++) {
5858 /* If cfg_scan_down is set, start from highest
5859 * ALPA (0xef) to lowest (0x1).
5861 if (vport->cfg_scan_down)
5864 index = FC_MAXLOOP - j - 1;
5865 alpa = lpfcAlpaArray[index];
5866 if ((vport->fc_myDID & 0xff) == alpa)
5868 lpfc_setup_disc_node(vport, alpa);
5876 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5879 struct lpfc_sli *psli = &phba->sli;
5880 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5881 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5885 * if it's not a physical port or if we already send
5886 * clear_la then don't send it.
5888 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5889 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5890 (phba->sli_rev == LPFC_SLI_REV4))
5893 /* Link up discovery */
5894 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5895 phba->link_state = LPFC_CLEAR_LA;
5896 lpfc_clear_la(phba, mbox);
5897 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5898 mbox->vport = vport;
5899 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5900 if (rc == MBX_NOT_FINISHED) {
5901 mempool_free(mbox, phba->mbox_mem_pool);
5902 lpfc_disc_flush_list(vport);
5903 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5904 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5905 phba->link_state = LPFC_HBA_ERROR;
5910 /* Reg_vpi to tell firmware to resume normal operations */
5912 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5914 LPFC_MBOXQ_t *regvpimbox;
5916 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5918 lpfc_reg_vpi(vport, regvpimbox);
5919 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5920 regvpimbox->vport = vport;
5921 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5922 == MBX_NOT_FINISHED) {
5923 mempool_free(regvpimbox, phba->mbox_mem_pool);
5928 /* Start Link up / RSCN discovery on NPR nodes */
5930 lpfc_disc_start(struct lpfc_vport *vport)
5932 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5933 struct lpfc_hba *phba = vport->phba;
5935 uint32_t clear_la_pending;
5937 if (!lpfc_is_link_up(phba)) {
5938 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5939 "3315 Link is not up %x\n",
5944 if (phba->link_state == LPFC_CLEAR_LA)
5945 clear_la_pending = 1;
5947 clear_la_pending = 0;
5949 if (vport->port_state < LPFC_VPORT_READY)
5950 vport->port_state = LPFC_DISC_AUTH;
5952 lpfc_set_disctmo(vport);
5954 vport->fc_prevDID = vport->fc_myDID;
5955 vport->num_disc_nodes = 0;
5957 /* Start Discovery state <hba_state> */
5958 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5959 "0202 Start Discovery port state x%x "
5960 "flg x%x Data: x%x x%x x%x\n",
5961 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5962 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5964 /* First do ADISCs - if any */
5965 num_sent = lpfc_els_disc_adisc(vport);
5970 /* Register the VPI for SLI3, NPIV only. */
5971 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5972 !(vport->fc_flag & FC_PT2PT) &&
5973 !(vport->fc_flag & FC_RSCN_MODE) &&
5974 (phba->sli_rev < LPFC_SLI_REV4)) {
5975 lpfc_issue_clear_la(phba, vport);
5976 lpfc_issue_reg_vpi(phba, vport);
5981 * For SLI2, we need to set port_state to READY and continue
5984 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5985 /* If we get here, there is nothing to ADISC */
5986 lpfc_issue_clear_la(phba, vport);
5988 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5989 vport->num_disc_nodes = 0;
5990 /* go thru NPR nodes and issue ELS PLOGIs */
5991 if (vport->fc_npr_cnt)
5992 lpfc_els_disc_plogi(vport);
5994 if (!vport->num_disc_nodes) {
5995 spin_lock_irq(shost->host_lock);
5996 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5997 spin_unlock_irq(shost->host_lock);
5998 lpfc_can_disctmo(vport);
6001 vport->port_state = LPFC_VPORT_READY;
6003 /* Next do PLOGIs - if any */
6004 num_sent = lpfc_els_disc_plogi(vport);
6009 if (vport->fc_flag & FC_RSCN_MODE) {
6010 /* Check to see if more RSCNs came in while we
6011 * were processing this one.
6013 if ((vport->fc_rscn_id_cnt == 0) &&
6014 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
6015 spin_lock_irq(shost->host_lock);
6016 vport->fc_flag &= ~FC_RSCN_MODE;
6017 spin_unlock_irq(shost->host_lock);
6018 lpfc_can_disctmo(vport);
6020 lpfc_els_handle_rscn(vport);
6027 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
6028 * ring the match the sppecified nodelist.
6031 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
6033 LIST_HEAD(completions);
6034 struct lpfc_iocbq *iocb, *next_iocb;
6035 struct lpfc_sli_ring *pring;
6038 pring = lpfc_phba_elsring(phba);
6039 if (unlikely(!pring))
6042 /* Error matching iocb on txq or txcmplq
6043 * First check the txq.
6045 spin_lock_irq(&phba->hbalock);
6046 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6047 if (iocb->ndlp != ndlp)
6050 ulp_command = get_job_cmnd(phba, iocb);
6052 if (ulp_command == CMD_ELS_REQUEST64_CR ||
6053 ulp_command == CMD_XMIT_ELS_RSP64_CX) {
6055 list_move_tail(&iocb->list, &completions);
6059 /* Next check the txcmplq */
6060 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
6061 if (iocb->ndlp != ndlp)
6064 ulp_command = get_job_cmnd(phba, iocb);
6066 if (ulp_command == CMD_ELS_REQUEST64_CR ||
6067 ulp_command == CMD_XMIT_ELS_RSP64_CX) {
6068 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
6071 spin_unlock_irq(&phba->hbalock);
6073 /* Make sure HBA is alive */
6074 lpfc_issue_hb_tmo(phba);
6076 /* Cancel all the IOCBs from the completions list */
6077 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6082 lpfc_disc_flush_list(struct lpfc_vport *vport)
6084 struct lpfc_nodelist *ndlp, *next_ndlp;
6085 struct lpfc_hba *phba = vport->phba;
6087 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
6088 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6090 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
6091 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
6092 lpfc_free_tx(phba, ndlp);
6099 * lpfc_notify_xport_npr - notifies xport of node disappearance
6100 * @vport: Pointer to Virtual Port object.
6102 * Transitions all ndlps to NPR state. When lpfc_nlp_set_state
6103 * calls lpfc_nlp_state_cleanup, the ndlp->rport is unregistered
6104 * and transport notified that the node is gone.
6109 lpfc_notify_xport_npr(struct lpfc_vport *vport)
6111 struct lpfc_nodelist *ndlp, *next_ndlp;
6113 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6115 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6119 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
6121 lpfc_els_flush_rscn(vport);
6122 lpfc_els_flush_cmd(vport);
6123 lpfc_disc_flush_list(vport);
6124 if (pci_channel_offline(vport->phba->pcidev))
6125 lpfc_notify_xport_npr(vport);
6128 /*****************************************************************************/
6130 * NAME: lpfc_disc_timeout
6132 * FUNCTION: Fibre Channel driver discovery timeout routine.
6134 * EXECUTION ENVIRONMENT: interrupt only
6142 /*****************************************************************************/
6144 lpfc_disc_timeout(struct timer_list *t)
6146 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
6147 struct lpfc_hba *phba = vport->phba;
6148 uint32_t tmo_posted;
6149 unsigned long flags = 0;
6151 if (unlikely(!phba))
6154 spin_lock_irqsave(&vport->work_port_lock, flags);
6155 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
6157 vport->work_port_events |= WORKER_DISC_TMO;
6158 spin_unlock_irqrestore(&vport->work_port_lock, flags);
6161 lpfc_worker_wake_up(phba);
6166 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
6168 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6169 struct lpfc_hba *phba = vport->phba;
6170 struct lpfc_sli *psli = &phba->sli;
6171 struct lpfc_nodelist *ndlp, *next_ndlp;
6172 LPFC_MBOXQ_t *initlinkmbox;
6173 int rc, clrlaerr = 0;
6175 if (!(vport->fc_flag & FC_DISC_TMO))
6178 spin_lock_irq(shost->host_lock);
6179 vport->fc_flag &= ~FC_DISC_TMO;
6180 spin_unlock_irq(shost->host_lock);
6182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6183 "disc timeout: state:x%x rtry:x%x flg:x%x",
6184 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
6186 switch (vport->port_state) {
6188 case LPFC_LOCAL_CFG_LINK:
6190 * port_state is identically LPFC_LOCAL_CFG_LINK while
6191 * waiting for FAN timeout
6193 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
6194 "0221 FAN timeout\n");
6196 /* Start discovery by sending FLOGI, clean up old rpis */
6197 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6199 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
6201 if (ndlp->nlp_type & NLP_FABRIC) {
6202 /* Clean up the ndlp on Fabric connections */
6203 lpfc_drop_node(vport, ndlp);
6205 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
6206 /* Fail outstanding IO now since device
6207 * is marked for PLOGI.
6209 lpfc_unreg_rpi(vport, ndlp);
6212 if (vport->port_state != LPFC_FLOGI) {
6213 if (phba->sli_rev <= LPFC_SLI_REV3)
6214 lpfc_initial_flogi(vport);
6216 lpfc_issue_init_vfi(vport);
6223 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
6224 /* Initial FLOGI timeout */
6225 lpfc_printf_vlog(vport, KERN_ERR,
6227 "0222 Initial %s timeout\n",
6228 vport->vpi ? "FDISC" : "FLOGI");
6230 /* Assume no Fabric and go on with discovery.
6231 * Check for outstanding ELS FLOGI to abort.
6234 /* FLOGI failed, so just use loop map to make discovery list */
6235 lpfc_disc_list_loopmap(vport);
6237 /* Start discovery */
6238 lpfc_disc_start(vport);
6241 case LPFC_FABRIC_CFG_LINK:
6242 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
6244 lpfc_printf_vlog(vport, KERN_ERR,
6246 "0223 Timeout while waiting for "
6247 "NameServer login\n");
6248 /* Next look for NameServer ndlp */
6249 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6251 lpfc_els_abort(phba, ndlp);
6253 /* ReStart discovery */
6257 /* Check for wait for NameServer Rsp timeout */
6258 lpfc_printf_vlog(vport, KERN_ERR,
6260 "0224 NameServer Query timeout "
6262 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6264 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
6265 /* Try it one more time */
6266 vport->fc_ns_retry++;
6267 vport->gidft_inp = 0;
6268 rc = lpfc_issue_gidft(vport);
6272 vport->fc_ns_retry = 0;
6276 * Discovery is over.
6277 * set port_state to PORT_READY if SLI2.
6278 * cmpl_reg_vpi will set port_state to READY for SLI3.
6280 if (phba->sli_rev < LPFC_SLI_REV4) {
6281 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6282 lpfc_issue_reg_vpi(phba, vport);
6284 lpfc_issue_clear_la(phba, vport);
6285 vport->port_state = LPFC_VPORT_READY;
6289 /* Setup and issue mailbox INITIALIZE LINK command */
6290 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6291 if (!initlinkmbox) {
6292 lpfc_printf_vlog(vport, KERN_ERR,
6294 "0206 Device Discovery "
6295 "completion error\n");
6296 phba->link_state = LPFC_HBA_ERROR;
6300 lpfc_linkdown(phba);
6301 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
6302 phba->cfg_link_speed);
6303 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6304 initlinkmbox->vport = vport;
6305 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6306 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
6307 lpfc_set_loopback_flag(phba);
6308 if (rc == MBX_NOT_FINISHED)
6309 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6313 case LPFC_DISC_AUTH:
6314 /* Node Authentication timeout */
6315 lpfc_printf_vlog(vport, KERN_ERR,
6317 "0227 Node Authentication timeout\n");
6318 lpfc_disc_flush_list(vport);
6321 * set port_state to PORT_READY if SLI2.
6322 * cmpl_reg_vpi will set port_state to READY for SLI3.
6324 if (phba->sli_rev < LPFC_SLI_REV4) {
6325 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6326 lpfc_issue_reg_vpi(phba, vport);
6327 else { /* NPIV Not enabled */
6328 lpfc_issue_clear_la(phba, vport);
6329 vport->port_state = LPFC_VPORT_READY;
6334 case LPFC_VPORT_READY:
6335 if (vport->fc_flag & FC_RSCN_MODE) {
6336 lpfc_printf_vlog(vport, KERN_ERR,
6338 "0231 RSCN timeout Data: x%x "
6340 vport->fc_ns_retry, LPFC_MAX_NS_RETRY,
6341 vport->port_state, vport->gidft_inp);
6343 /* Cleanup any outstanding ELS commands */
6344 lpfc_els_flush_cmd(vport);
6346 lpfc_els_flush_rscn(vport);
6347 lpfc_disc_flush_list(vport);
6352 lpfc_printf_vlog(vport, KERN_ERR,
6354 "0273 Unexpected discovery timeout, "
6355 "vport State x%x\n", vport->port_state);
6359 switch (phba->link_state) {
6361 /* CLEAR LA timeout */
6362 lpfc_printf_vlog(vport, KERN_ERR,
6364 "0228 CLEAR LA timeout\n");
6369 lpfc_issue_clear_la(phba, vport);
6371 case LPFC_LINK_UNKNOWN:
6372 case LPFC_WARM_START:
6373 case LPFC_INIT_START:
6374 case LPFC_INIT_MBX_CMDS:
6375 case LPFC_LINK_DOWN:
6376 case LPFC_HBA_ERROR:
6377 lpfc_printf_vlog(vport, KERN_ERR,
6379 "0230 Unexpected timeout, hba link "
6380 "state x%x\n", phba->link_state);
6384 case LPFC_HBA_READY:
6389 lpfc_disc_flush_list(vport);
6390 if (phba->sli_rev != LPFC_SLI_REV4) {
6391 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6392 ~LPFC_STOP_IOCB_EVENT;
6393 psli->sli3_ring[LPFC_FCP_RING].flag &=
6394 ~LPFC_STOP_IOCB_EVENT;
6396 vport->port_state = LPFC_VPORT_READY;
6402 * This routine handles processing a NameServer REG_LOGIN mailbox
6403 * command upon completion. It is setup in the LPFC_MBOXQ
6404 * as the completion routine when the command is
6405 * handed off to the SLI layer.
6408 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6410 MAILBOX_t *mb = &pmb->u.mb;
6411 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6412 struct lpfc_vport *vport = pmb->vport;
6414 pmb->ctx_ndlp = NULL;
6416 if (phba->sli_rev < LPFC_SLI_REV4)
6417 ndlp->nlp_rpi = mb->un.varWords[0];
6418 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6419 ndlp->nlp_type |= NLP_FABRIC;
6420 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6421 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6422 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
6423 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6424 kref_read(&ndlp->kref),
6427 * Start issuing Fabric-Device Management Interface (FDMI) command to
6428 * 0xfffffa (FDMI well known port).
6429 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6430 * DPRT -> RPRT (vports)
6432 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6433 phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */
6434 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6436 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6440 /* decrement the node reference count held for this callback
6444 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
6449 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6451 uint16_t *rpi = param;
6453 return ndlp->nlp_rpi == *rpi;
6457 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6459 return memcmp(&ndlp->nlp_portname, param,
6460 sizeof(ndlp->nlp_portname)) == 0;
6463 static struct lpfc_nodelist *
6464 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6466 struct lpfc_nodelist *ndlp;
6468 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6469 if (filter(ndlp, param)) {
6470 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6471 "3185 FIND node filter %ps DID "
6472 "ndlp x%px did x%x flg x%x st x%x "
6473 "xri x%x type x%x rpi x%x\n",
6474 filter, ndlp, ndlp->nlp_DID,
6475 ndlp->nlp_flag, ndlp->nlp_state,
6476 ndlp->nlp_xri, ndlp->nlp_type,
6481 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6482 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6487 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6488 * returns the node list element pointer else return NULL.
6490 struct lpfc_nodelist *
6491 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6493 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6497 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6498 * returns the node element list pointer else return NULL.
6500 struct lpfc_nodelist *
6501 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6504 struct lpfc_nodelist *ndlp;
6506 spin_lock_irq(shost->host_lock);
6507 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6508 spin_unlock_irq(shost->host_lock);
6513 * This routine looks up the ndlp lists for the given RPI. If the rpi
6514 * is found, the routine returns the node element list pointer else
6517 struct lpfc_nodelist *
6518 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6521 struct lpfc_nodelist *ndlp;
6522 unsigned long flags;
6524 spin_lock_irqsave(shost->host_lock, flags);
6525 ndlp = __lpfc_findnode_rpi(vport, rpi);
6526 spin_unlock_irqrestore(shost->host_lock, flags);
6531 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6532 * @phba: pointer to lpfc hba data structure.
6533 * @vpi: the physical host virtual N_Port identifier.
6535 * This routine finds a vport on a HBA (referred by @phba) through a
6536 * @vpi. The function walks the HBA's vport list and returns the address
6537 * of the vport with the matching @vpi.
6540 * NULL - No vport with the matching @vpi found
6541 * Otherwise - Address to the vport with the matching @vpi.
6544 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6546 struct lpfc_vport *vport;
6547 unsigned long flags;
6550 /* The physical ports are always vpi 0 - translate is unnecessary. */
6553 * Translate the physical vpi to the logical vpi. The
6554 * vport stores the logical vpi.
6556 for (i = 0; i <= phba->max_vpi; i++) {
6557 if (vpi == phba->vpi_ids[i])
6561 if (i > phba->max_vpi) {
6562 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6563 "2936 Could not find Vport mapped "
6564 "to vpi %d\n", vpi);
6569 spin_lock_irqsave(&phba->port_list_lock, flags);
6570 list_for_each_entry(vport, &phba->port_list, listentry) {
6571 if (vport->vpi == i) {
6572 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6576 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6580 struct lpfc_nodelist *
6581 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6583 struct lpfc_nodelist *ndlp;
6584 int rpi = LPFC_RPI_ALLOC_ERROR;
6586 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6587 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6588 if (rpi == LPFC_RPI_ALLOC_ERROR)
6592 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6594 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6595 lpfc_sli4_free_rpi(vport->phba, rpi);
6599 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6601 spin_lock_init(&ndlp->lock);
6603 lpfc_initialize_node(vport, ndlp, did);
6604 INIT_LIST_HEAD(&ndlp->nlp_listp);
6605 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6606 ndlp->nlp_rpi = rpi;
6607 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6608 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6609 "flg:x%x refcnt:%d\n",
6610 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6611 ndlp->nlp_flag, kref_read(&ndlp->kref));
6613 ndlp->active_rrqs_xri_bitmap =
6614 mempool_alloc(vport->phba->active_rrq_pool,
6616 if (ndlp->active_rrqs_xri_bitmap)
6617 memset(ndlp->active_rrqs_xri_bitmap, 0,
6618 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6624 "node init: did:x%x",
6625 ndlp->nlp_DID, 0, 0);
6630 /* This routine releases all resources associated with a specifc NPort's ndlp
6631 * and mempool_free's the nodelist.
6634 lpfc_nlp_release(struct kref *kref)
6636 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6638 struct lpfc_vport *vport = ndlp->vport;
6640 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6641 "node release: did:x%x flg:x%x type:x%x",
6642 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6644 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6645 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
6646 __func__, ndlp, ndlp->nlp_DID,
6647 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6649 /* remove ndlp from action. */
6650 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6651 lpfc_cleanup_node(vport, ndlp);
6653 /* Not all ELS transactions have registered the RPI with the port.
6654 * In these cases the rpi usage is temporary and the node is
6655 * released when the WQE is completed. Catch this case to free the
6656 * RPI to the pool. Because this node is in the release path, a lock
6657 * is unnecessary. All references are gone and the node has been
6660 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6661 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6662 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6663 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6664 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6668 /* The node is not freed back to memory, it is released to a pool so
6669 * the node fields need to be cleaned up.
6672 ndlp->nlp_state = NLP_STE_FREED_NODE;
6674 ndlp->fc4_xpt_flags = 0;
6676 /* free ndlp memory for final ndlp release */
6677 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6678 mempool_free(ndlp->active_rrqs_xri_bitmap,
6679 ndlp->phba->active_rrq_pool);
6680 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6683 /* This routine bumps the reference count for a ndlp structure to ensure
6684 * that one discovery thread won't free a ndlp while another discovery thread
6687 struct lpfc_nodelist *
6688 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6690 unsigned long flags;
6693 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6694 "node get: did:x%x flg:x%x refcnt:x%x",
6695 ndlp->nlp_DID, ndlp->nlp_flag,
6696 kref_read(&ndlp->kref));
6698 /* The check of ndlp usage to prevent incrementing the
6699 * ndlp reference count that is in the process of being
6702 spin_lock_irqsave(&ndlp->lock, flags);
6703 if (!kref_get_unless_zero(&ndlp->kref)) {
6704 spin_unlock_irqrestore(&ndlp->lock, flags);
6705 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6706 "0276 %s: ndlp:x%px refcnt:%d\n",
6707 __func__, (void *)ndlp, kref_read(&ndlp->kref));
6710 spin_unlock_irqrestore(&ndlp->lock, flags);
6712 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
6718 /* This routine decrements the reference count for a ndlp structure. If the
6719 * count goes to 0, this indicates the associated nodelist should be freed.
6722 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6725 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6726 "node put: did:x%x flg:x%x refcnt:x%x",
6727 ndlp->nlp_DID, ndlp->nlp_flag,
6728 kref_read(&ndlp->kref));
6730 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
6733 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
6737 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6738 * @phba: Pointer to hba context object.
6740 * This function iterate through all FC nodes associated
6741 * will all vports to check if there is any node with
6742 * fc_rports associated with it. If there is an fc_rport
6743 * associated with the node, then the node is either in
6744 * discovered state or its devloss_timer is pending.
6747 lpfc_fcf_inuse(struct lpfc_hba *phba)
6749 struct lpfc_vport **vports;
6751 struct lpfc_nodelist *ndlp;
6752 struct Scsi_Host *shost;
6754 vports = lpfc_create_vport_work_array(phba);
6756 /* If driver cannot allocate memory, indicate fcf is in use */
6760 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6761 shost = lpfc_shost_from_vport(vports[i]);
6762 spin_lock_irq(shost->host_lock);
6764 * IF the CVL_RCVD bit is not set then we have sent the
6766 * If dev_loss fires while we are waiting we do not want to
6769 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6770 spin_unlock_irq(shost->host_lock);
6774 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6776 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6778 spin_unlock_irq(shost->host_lock);
6780 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6782 lpfc_printf_log(phba, KERN_INFO,
6783 LOG_NODE | LOG_DISCOVERY,
6784 "2624 RPI %x DID %x flag %x "
6785 "still logged in\n",
6786 ndlp->nlp_rpi, ndlp->nlp_DID,
6790 spin_unlock_irq(shost->host_lock);
6793 lpfc_destroy_vport_work_array(phba, vports);
6798 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6799 * @phba: Pointer to hba context object.
6800 * @mboxq: Pointer to mailbox object.
6802 * This function frees memory associated with the mailbox command.
6805 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6807 struct lpfc_vport *vport = mboxq->vport;
6808 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6810 if (mboxq->u.mb.mbxStatus) {
6811 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6812 "2555 UNREG_VFI mbxStatus error x%x "
6814 mboxq->u.mb.mbxStatus, vport->port_state);
6816 spin_lock_irq(shost->host_lock);
6817 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6818 spin_unlock_irq(shost->host_lock);
6819 mempool_free(mboxq, phba->mbox_mem_pool);
6824 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6825 * @phba: Pointer to hba context object.
6826 * @mboxq: Pointer to mailbox object.
6828 * This function frees memory associated with the mailbox command.
6831 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6833 struct lpfc_vport *vport = mboxq->vport;
6835 if (mboxq->u.mb.mbxStatus) {
6836 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6837 "2550 UNREG_FCFI mbxStatus error x%x "
6839 mboxq->u.mb.mbxStatus, vport->port_state);
6841 mempool_free(mboxq, phba->mbox_mem_pool);
6846 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6847 * @phba: Pointer to hba context object.
6849 * This function prepare the HBA for unregistering the currently registered
6850 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6854 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6856 struct lpfc_vport **vports;
6857 struct lpfc_nodelist *ndlp;
6858 struct Scsi_Host *shost;
6861 /* Unregister RPIs */
6862 if (lpfc_fcf_inuse(phba))
6863 lpfc_unreg_hba_rpis(phba);
6865 /* At this point, all discovery is aborted */
6866 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6868 /* Unregister VPIs */
6869 vports = lpfc_create_vport_work_array(phba);
6870 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6871 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6872 /* Stop FLOGI/FDISC retries */
6873 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6875 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6876 lpfc_cleanup_pending_mbox(vports[i]);
6877 if (phba->sli_rev == LPFC_SLI_REV4)
6878 lpfc_sli4_unreg_all_rpis(vports[i]);
6879 lpfc_mbx_unreg_vpi(vports[i]);
6880 shost = lpfc_shost_from_vport(vports[i]);
6881 spin_lock_irq(shost->host_lock);
6882 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6883 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6884 spin_unlock_irq(shost->host_lock);
6886 lpfc_destroy_vport_work_array(phba, vports);
6887 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6888 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6890 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6891 lpfc_cleanup_pending_mbox(phba->pport);
6892 if (phba->sli_rev == LPFC_SLI_REV4)
6893 lpfc_sli4_unreg_all_rpis(phba->pport);
6894 lpfc_mbx_unreg_vpi(phba->pport);
6895 shost = lpfc_shost_from_vport(phba->pport);
6896 spin_lock_irq(shost->host_lock);
6897 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6898 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6899 spin_unlock_irq(shost->host_lock);
6902 /* Cleanup any outstanding ELS commands */
6903 lpfc_els_flush_all_cmd(phba);
6905 /* Unregister the physical port VFI */
6906 rc = lpfc_issue_unreg_vfi(phba->pport);
6911 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6912 * @phba: Pointer to hba context object.
6914 * This function issues synchronous unregister FCF mailbox command to HBA to
6915 * unregister the currently registered FCF record. The driver does not reset
6916 * the driver FCF usage state flags.
6918 * Return 0 if successfully issued, none-zero otherwise.
6921 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6926 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6928 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6929 "2551 UNREG_FCFI mbox allocation failed"
6930 "HBA state x%x\n", phba->pport->port_state);
6933 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6934 mbox->vport = phba->pport;
6935 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6936 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6938 if (rc == MBX_NOT_FINISHED) {
6939 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6940 "2552 Unregister FCFI command failed rc x%x "
6942 rc, phba->pport->port_state);
6949 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6950 * @phba: Pointer to hba context object.
6952 * This function unregisters the currently reigstered FCF. This function
6953 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6956 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6960 /* Preparation for unregistering fcf */
6961 rc = lpfc_unregister_fcf_prep(phba);
6963 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6964 "2748 Failed to prepare for unregistering "
6965 "HBA's FCF record: rc=%d\n", rc);
6969 /* Now, unregister FCF record and reset HBA FCF state */
6970 rc = lpfc_sli4_unregister_fcf(phba);
6973 /* Reset HBA FCF states after successful unregister FCF */
6974 spin_lock_irq(&phba->hbalock);
6975 phba->fcf.fcf_flag = 0;
6976 spin_unlock_irq(&phba->hbalock);
6977 phba->fcf.current_rec.flag = 0;
6980 * If driver is not unloading, check if there is any other
6981 * FCF record that can be used for discovery.
6983 if ((phba->pport->load_flag & FC_UNLOADING) ||
6984 (phba->link_state < LPFC_LINK_UP))
6987 /* This is considered as the initial FCF discovery scan */
6988 spin_lock_irq(&phba->hbalock);
6989 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6990 spin_unlock_irq(&phba->hbalock);
6992 /* Reset FCF roundrobin bmask for new discovery */
6993 lpfc_sli4_clear_fcf_rr_bmask(phba);
6995 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6998 spin_lock_irq(&phba->hbalock);
6999 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
7000 spin_unlock_irq(&phba->hbalock);
7001 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7002 "2553 lpfc_unregister_unused_fcf failed "
7003 "to read FCF record HBA state x%x\n",
7004 phba->pport->port_state);
7009 * lpfc_unregister_fcf - Unregister the currently registered fcf record
7010 * @phba: Pointer to hba context object.
7012 * This function just unregisters the currently reigstered FCF. It does not
7013 * try to find another FCF for discovery.
7016 lpfc_unregister_fcf(struct lpfc_hba *phba)
7020 /* Preparation for unregistering fcf */
7021 rc = lpfc_unregister_fcf_prep(phba);
7023 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7024 "2749 Failed to prepare for unregistering "
7025 "HBA's FCF record: rc=%d\n", rc);
7029 /* Now, unregister FCF record and reset HBA FCF state */
7030 rc = lpfc_sli4_unregister_fcf(phba);
7033 /* Set proper HBA FCF states after successful unregister FCF */
7034 spin_lock_irq(&phba->hbalock);
7035 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
7036 spin_unlock_irq(&phba->hbalock);
7040 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
7041 * @phba: Pointer to hba context object.
7043 * This function check if there are any connected remote port for the FCF and
7044 * if all the devices are disconnected, this function unregister FCFI.
7045 * This function also tries to use another FCF for discovery.
7048 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
7051 * If HBA is not running in FIP mode, if HBA does not support
7052 * FCoE, if FCF discovery is ongoing, or if FCF has not been
7053 * registered, do nothing.
7055 spin_lock_irq(&phba->hbalock);
7056 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
7057 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
7058 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
7059 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
7060 (phba->pport->port_state == LPFC_FLOGI)) {
7061 spin_unlock_irq(&phba->hbalock);
7064 spin_unlock_irq(&phba->hbalock);
7066 if (lpfc_fcf_inuse(phba))
7069 lpfc_unregister_fcf_rescan(phba);
7073 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
7074 * @phba: Pointer to hba context object.
7075 * @buff: Buffer containing the FCF connection table as in the config
7077 * This function create driver data structure for the FCF connection
7078 * record table read from config region 23.
7081 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
7084 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
7085 struct lpfc_fcf_conn_hdr *conn_hdr;
7086 struct lpfc_fcf_conn_rec *conn_rec;
7087 uint32_t record_count;
7090 /* Free the current connect table */
7091 list_for_each_entry_safe(conn_entry, next_conn_entry,
7092 &phba->fcf_conn_rec_list, list) {
7093 list_del_init(&conn_entry->list);
7097 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
7098 record_count = conn_hdr->length * sizeof(uint32_t)/
7099 sizeof(struct lpfc_fcf_conn_rec);
7101 conn_rec = (struct lpfc_fcf_conn_rec *)
7102 (buff + sizeof(struct lpfc_fcf_conn_hdr));
7104 for (i = 0; i < record_count; i++) {
7105 if (!(conn_rec[i].flags & FCFCNCT_VALID))
7107 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
7110 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7111 "2566 Failed to allocate connection"
7116 memcpy(&conn_entry->conn_rec, &conn_rec[i],
7117 sizeof(struct lpfc_fcf_conn_rec));
7118 list_add_tail(&conn_entry->list,
7119 &phba->fcf_conn_rec_list);
7122 if (!list_empty(&phba->fcf_conn_rec_list)) {
7124 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
7126 conn_rec = &conn_entry->conn_rec;
7127 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7128 "3345 FCF connection list rec[%02d]: "
7129 "flags:x%04x, vtag:x%04x, "
7130 "fabric_name:x%02x:%02x:%02x:%02x:"
7131 "%02x:%02x:%02x:%02x, "
7132 "switch_name:x%02x:%02x:%02x:%02x:"
7133 "%02x:%02x:%02x:%02x\n", i++,
7134 conn_rec->flags, conn_rec->vlan_tag,
7135 conn_rec->fabric_name[0],
7136 conn_rec->fabric_name[1],
7137 conn_rec->fabric_name[2],
7138 conn_rec->fabric_name[3],
7139 conn_rec->fabric_name[4],
7140 conn_rec->fabric_name[5],
7141 conn_rec->fabric_name[6],
7142 conn_rec->fabric_name[7],
7143 conn_rec->switch_name[0],
7144 conn_rec->switch_name[1],
7145 conn_rec->switch_name[2],
7146 conn_rec->switch_name[3],
7147 conn_rec->switch_name[4],
7148 conn_rec->switch_name[5],
7149 conn_rec->switch_name[6],
7150 conn_rec->switch_name[7]);
7156 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
7157 * @phba: Pointer to hba context object.
7158 * @buff: Buffer containing the FCoE parameter data structure.
7160 * This function update driver data structure with config
7161 * parameters read from config region 23.
7164 lpfc_read_fcoe_param(struct lpfc_hba *phba,
7167 struct lpfc_fip_param_hdr *fcoe_param_hdr;
7168 struct lpfc_fcoe_params *fcoe_param;
7170 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
7172 fcoe_param = (struct lpfc_fcoe_params *)
7173 (buff + sizeof(struct lpfc_fip_param_hdr));
7175 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
7176 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
7179 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
7180 phba->valid_vlan = 1;
7181 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
7185 phba->fc_map[0] = fcoe_param->fc_map[0];
7186 phba->fc_map[1] = fcoe_param->fc_map[1];
7187 phba->fc_map[2] = fcoe_param->fc_map[2];
7192 * lpfc_get_rec_conf23 - Get a record type in config region data.
7193 * @buff: Buffer containing config region 23 data.
7194 * @size: Size of the data buffer.
7195 * @rec_type: Record type to be searched.
7197 * This function searches config region data to find the beginning
7198 * of the record specified by record_type. If record found, this
7199 * function return pointer to the record else return NULL.
7202 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
7204 uint32_t offset = 0, rec_length;
7206 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
7207 (size < sizeof(uint32_t)))
7210 rec_length = buff[offset + 1];
7213 * One TLV record has one word header and number of data words
7214 * specified in the rec_length field of the record header.
7216 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
7218 if (buff[offset] == rec_type)
7219 return &buff[offset];
7221 if (buff[offset] == LPFC_REGION23_LAST_REC)
7224 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
7225 rec_length = buff[offset + 1];
7231 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
7232 * @phba: Pointer to lpfc_hba data structure.
7233 * @buff: Buffer containing config region 23 data.
7234 * @size: Size of the data buffer.
7236 * This function parses the FCoE config parameters in config region 23 and
7237 * populate driver data structure with the parameters.
7240 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
7244 uint32_t offset = 0;
7248 * If data size is less than 2 words signature and version cannot be
7251 if (size < 2*sizeof(uint32_t))
7254 /* Check the region signature first */
7255 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
7256 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7257 "2567 Config region 23 has bad signature\n");
7263 /* Check the data structure version */
7264 if (buff[offset] != LPFC_REGION23_VERSION) {
7265 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7266 "2568 Config region 23 has bad version\n");
7271 /* Read FCoE param record */
7272 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7273 size - offset, FCOE_PARAM_TYPE);
7275 lpfc_read_fcoe_param(phba, rec_ptr);
7277 /* Read FCF connection table */
7278 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7279 size - offset, FCOE_CONN_TBL_TYPE);
7281 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
7286 * lpfc_error_lost_link - IO failure from link event or FW reset check.
7288 * @vport: Pointer to lpfc_vport data structure.
7289 * @ulp_status: IO completion status.
7290 * @ulp_word4: Reason code for the ulp_status.
7292 * This function evaluates the ulp_status and ulp_word4 values
7293 * for specific error values that indicate an internal link fault
7294 * or fw reset event for the completing IO. Callers require this
7295 * common data to decide next steps on the IO.
7298 * false - No link or reset error occurred.
7299 * true - A link or reset error occurred.
7302 lpfc_error_lost_link(struct lpfc_vport *vport, u32 ulp_status, u32 ulp_word4)
7304 /* Mask off the extra port data to get just the reason code. */
7305 u32 rsn_code = IOERR_PARAM_MASK & ulp_word4;
7307 if (ulp_status == IOSTAT_LOCAL_REJECT &&
7308 (rsn_code == IOERR_SLI_ABORTED ||
7309 rsn_code == IOERR_LINK_DOWN ||
7310 rsn_code == IOERR_SLI_DOWN)) {
7311 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI | LOG_ELS,
7312 "0408 Report link error true: <x%x:x%x>\n",
7313 ulp_status, ulp_word4);