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 %d 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 * The teardown process cleans up the node via lpfc_drop_node.
180 if (vport->load_flag & FC_UNLOADING) {
181 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
184 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
185 /* clear the NLP_XPT_REGD if the node is not registered
188 if (ndlp->fc4_xpt_flags == NLP_XPT_REGD)
189 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
191 /* Remove the node reference from remote_port_add now.
192 * The driver will not call remote_port_delete.
198 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
201 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
202 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
203 "6789 rport name %llx != node port name %llx",
205 wwn_to_u64(ndlp->nlp_portname.u.wwn));
207 evtp = &ndlp->dev_loss_evt;
209 if (!list_empty(&evtp->evt_listp)) {
210 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
211 "6790 rport name %llx dev_loss_evt pending\n",
216 spin_lock_irqsave(&ndlp->lock, iflags);
217 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
219 /* If there is a PLOGI in progress, and we are in a
220 * NLP_NPR_2B_DISC state, don't turn off the flag.
222 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
223 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
226 * The backend does not expect any more calls associated with this
227 * rport. Remove the association between rport and ndlp.
229 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
230 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
232 spin_unlock_irqrestore(&ndlp->lock, iflags);
234 if (phba->worker_thread) {
235 /* We need to hold the node by incrementing the reference
236 * count until this queued work is done
238 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
240 spin_lock_irqsave(&phba->hbalock, iflags);
241 if (evtp->evt_arg1) {
242 evtp->evt = LPFC_EVT_DEV_LOSS;
243 list_add_tail(&evtp->evt_listp, &phba->work_list);
244 lpfc_worker_wake_up(phba);
246 spin_unlock_irqrestore(&phba->hbalock, iflags);
248 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
249 "3188 worker thread is stopped %s x%06x, "
250 " rport x%px flg x%x load_flag x%x refcnt "
251 "%d\n", __func__, ndlp->nlp_DID,
252 ndlp->rport, ndlp->nlp_flag,
253 vport->load_flag, kref_read(&ndlp->kref));
254 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD)) {
255 spin_lock_irqsave(&ndlp->lock, iflags);
256 /* Node is in dev loss. No further transaction. */
257 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
258 spin_unlock_irqrestore(&ndlp->lock, iflags);
259 lpfc_disc_state_machine(vport, ndlp, NULL,
269 * lpfc_check_inactive_vmid_one - VMID inactivity checker for a vport
270 * @vport: Pointer to vport context object.
272 * This function checks for idle VMID entries related to a particular vport. If
273 * found unused/idle, free them accordingly.
275 static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport)
278 u32 difftime = 0, r, bucket;
281 struct lpfc_vmid *vmp;
283 write_lock(&vport->vmid_lock);
285 if (!vport->cur_vmid_cnt)
288 /* iterate through the table */
289 hash_for_each(vport->hash_table, bucket, vmp, hnode) {
291 if (vmp->flag & LPFC_VMID_REGISTERED) {
292 /* check if the particular VMID is in use */
293 /* for all available per cpu variable */
294 for_each_possible_cpu(cpu) {
295 /* if last access time is less than timeout */
296 lta = per_cpu_ptr(vmp->last_io_time, cpu);
299 difftime = (jiffies) - (*lta);
300 if ((vport->vmid_inactivity_timeout *
301 JIFFIES_PER_HR) > difftime) {
307 /* if none of the cpus have been used by the vm, */
308 /* remove the entry if already registered */
310 /* mark the entry for deregistration */
311 vmp->flag = LPFC_VMID_DE_REGISTER;
312 write_unlock(&vport->vmid_lock);
313 if (vport->vmid_priority_tagging)
314 r = lpfc_vmid_uvem(vport, vmp, false);
316 r = lpfc_vmid_cmd(vport,
320 /* decrement number of active vms and mark */
321 /* entry in slot as free */
322 write_lock(&vport->vmid_lock);
324 struct lpfc_vmid *ht = vmp;
326 vport->cur_vmid_cnt--;
327 ht->flag = LPFC_VMID_SLOT_FREE;
328 free_percpu(ht->last_io_time);
329 ht->last_io_time = NULL;
330 hash_del(&ht->hnode);
336 write_unlock(&vport->vmid_lock);
340 * lpfc_check_inactive_vmid - VMID inactivity checker
341 * @phba: Pointer to hba context object.
343 * This function is called from the worker thread to determine if an entry in
344 * the VMID table can be released since there was no I/O activity seen from that
345 * particular VM for the specified time. When this happens, the entry in the
346 * table is released and also the resources on the switch cleared.
349 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba)
351 struct lpfc_vport *vport;
352 struct lpfc_vport **vports;
355 vports = lpfc_create_vport_work_array(phba);
359 for (i = 0; i <= phba->max_vports; i++) {
360 if ((!vports[i]) && (i == 0))
367 lpfc_check_inactive_vmid_one(vport);
369 lpfc_destroy_vport_work_array(phba, vports);
373 * lpfc_check_nlp_post_devloss - Check to restore ndlp refcnt after devloss
374 * @vport: Pointer to vport object.
375 * @ndlp: Pointer to remote node object.
377 * If NLP_IN_RECOV_POST_DEV_LOSS flag was set due to outstanding recovery of
378 * node during dev_loss_tmo processing, then this function restores the nlp_put
379 * kref decrement from lpfc_dev_loss_tmo_handler.
382 lpfc_check_nlp_post_devloss(struct lpfc_vport *vport,
383 struct lpfc_nodelist *ndlp)
385 unsigned long iflags;
387 spin_lock_irqsave(&ndlp->lock, iflags);
388 if (ndlp->save_flags & NLP_IN_RECOV_POST_DEV_LOSS) {
389 ndlp->save_flags &= ~NLP_IN_RECOV_POST_DEV_LOSS;
390 spin_unlock_irqrestore(&ndlp->lock, iflags);
392 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_NODE,
393 "8438 Devloss timeout reversed on DID x%x "
394 "refcnt %d ndlp %p flag x%x "
395 "port_state = x%x\n",
396 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp,
397 ndlp->nlp_flag, vport->port_state);
398 spin_lock_irqsave(&ndlp->lock, iflags);
400 spin_unlock_irqrestore(&ndlp->lock, iflags);
404 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
405 * @ndlp: Pointer to remote node object.
407 * This function is called from the worker thread when devloss timeout timer
408 * expires. For SLI4 host, this routine shall return 1 when at lease one
409 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
410 * routine shall return 0 when there is no remote node is still in use of FCF
411 * when devloss timeout happened to this @ndlp.
414 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
416 struct lpfc_vport *vport;
417 struct lpfc_hba *phba;
421 bool recovering = false;
422 struct fc_vport *fc_vport = NULL;
423 unsigned long iflags;
426 name = (uint8_t *)&ndlp->nlp_portname;
429 if (phba->sli_rev == LPFC_SLI_REV4)
430 fcf_inuse = lpfc_fcf_inuse(phba);
432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
433 "rport devlosstmo:did:x%x type:x%x id:x%x",
434 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
436 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
437 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
438 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
439 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
441 /* If the driver is recovering the rport, ignore devloss. */
442 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
443 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
444 "0284 Devloss timeout Ignored on "
445 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
447 *name, *(name+1), *(name+2), *(name+3),
448 *(name+4), *(name+5), *(name+6), *(name+7),
451 spin_lock_irqsave(&ndlp->lock, iflags);
452 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
453 spin_unlock_irqrestore(&ndlp->lock, iflags);
457 /* Fabric nodes are done. */
458 if (ndlp->nlp_type & NLP_FABRIC) {
459 spin_lock_irqsave(&ndlp->lock, iflags);
461 /* In massive vport configuration settings or when the FLOGI
462 * completes with a sequence timeout, it's possible
463 * dev_loss_tmo fired during node recovery. The driver has to
464 * account for this race to allow for recovery and keep
465 * the reference counting correct.
467 switch (ndlp->nlp_DID) {
469 fc_vport = vport->fc_vport;
472 if (fc_vport->vport_state ==
473 FC_VPORT_INITIALIZING)
476 /* Physical port path. */
477 if (phba->hba_flag & HBA_FLOGI_OUTSTANDING)
481 case Fabric_Cntl_DID:
482 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
488 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
489 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE)
493 spin_unlock_irqrestore(&ndlp->lock, iflags);
495 /* Mark an NLP_IN_RECOV_POST_DEV_LOSS flag to know if reversing
496 * the following lpfc_nlp_put is necessary after fabric node is
500 lpfc_printf_vlog(vport, KERN_INFO,
501 LOG_DISCOVERY | LOG_NODE,
502 "8436 Devloss timeout marked on "
503 "DID x%x refcnt %d ndlp %p "
504 "flag x%x port_state = x%x\n",
505 ndlp->nlp_DID, kref_read(&ndlp->kref),
506 ndlp, ndlp->nlp_flag,
508 spin_lock_irqsave(&ndlp->lock, iflags);
509 ndlp->save_flags |= NLP_IN_RECOV_POST_DEV_LOSS;
510 spin_unlock_irqrestore(&ndlp->lock, iflags);
511 } else if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
512 /* Fabric node fully recovered before this dev_loss_tmo
513 * queue work is processed. Thus, ignore the
514 * dev_loss_tmo event.
516 lpfc_printf_vlog(vport, KERN_INFO,
517 LOG_DISCOVERY | LOG_NODE,
518 "8437 Devloss timeout ignored on "
519 "DID x%x refcnt %d ndlp %p "
520 "flag x%x port_state = x%x\n",
521 ndlp->nlp_DID, kref_read(&ndlp->kref),
522 ndlp, ndlp->nlp_flag,
527 spin_lock_irqsave(&ndlp->lock, iflags);
528 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
529 spin_unlock_irqrestore(&ndlp->lock, iflags);
534 if (ndlp->nlp_sid != NLP_NO_SID) {
536 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
540 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
541 "0203 Devloss timeout on "
542 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
543 "NPort x%06x Data: x%x x%x x%x refcnt %d\n",
544 *name, *(name+1), *(name+2), *(name+3),
545 *(name+4), *(name+5), *(name+6), *(name+7),
546 ndlp->nlp_DID, ndlp->nlp_flag,
547 ndlp->nlp_state, ndlp->nlp_rpi,
548 kref_read(&ndlp->kref));
550 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
551 "0204 Devloss timeout on "
552 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
553 "NPort x%06x Data: x%x x%x x%x\n",
554 *name, *(name+1), *(name+2), *(name+3),
555 *(name+4), *(name+5), *(name+6), *(name+7),
556 ndlp->nlp_DID, ndlp->nlp_flag,
557 ndlp->nlp_state, ndlp->nlp_rpi);
560 /* If we are devloss, but we are in the process of rediscovering the
561 * ndlp, don't issue a NLP_EVT_DEVICE_RM event.
563 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
564 ndlp->nlp_state <= NLP_STE_PRLI_ISSUE) {
568 spin_lock_irqsave(&ndlp->lock, iflags);
569 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
570 spin_unlock_irqrestore(&ndlp->lock, iflags);
571 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
572 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
577 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba)
579 struct lpfc_vport *vport;
580 struct lpfc_vport **vports;
583 vports = lpfc_create_vport_work_array(phba);
587 for (i = 0; i <= phba->max_vports; i++) {
588 if ((!vports[i]) && (i == 0))
595 if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) {
596 if (!lpfc_issue_els_qfpa(vport))
597 vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA;
600 lpfc_destroy_vport_work_array(phba, vports);
604 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
605 * @phba: Pointer to hba context object.
606 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
607 * @nlp_did: remote node identifer with devloss timeout.
609 * This function is called from the worker thread after invoking devloss
610 * timeout handler and releasing the reference count for the ndlp with
611 * which the devloss timeout was handled for SLI4 host. For the devloss
612 * timeout of the last remote node which had been in use of FCF, when this
613 * routine is invoked, it shall be guaranteed that none of the remote are
614 * in-use of FCF. When devloss timeout to the last remote using the FCF,
615 * if the FIP engine is neither in FCF table scan process nor roundrobin
616 * failover process, the in-use FCF shall be unregistered. If the FIP
617 * engine is in FCF discovery process, the devloss timeout state shall
618 * be set for either the FCF table scan process or roundrobin failover
619 * process to unregister the in-use FCF.
622 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
625 /* If devloss timeout happened to a remote node when FCF had no
626 * longer been in-use, do nothing.
631 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
632 spin_lock_irq(&phba->hbalock);
633 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
634 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
635 spin_unlock_irq(&phba->hbalock);
638 phba->hba_flag |= HBA_DEVLOSS_TMO;
639 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
640 "2847 Last remote node (x%x) using "
641 "FCF devloss tmo\n", nlp_did);
643 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
644 spin_unlock_irq(&phba->hbalock);
645 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
646 "2868 Devloss tmo to FCF rediscovery "
650 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
651 spin_unlock_irq(&phba->hbalock);
652 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
653 "2869 Devloss tmo to idle FIP engine, "
654 "unreg in-use FCF and rescan.\n");
655 /* Unregister in-use FCF and rescan */
656 lpfc_unregister_fcf_rescan(phba);
659 spin_unlock_irq(&phba->hbalock);
660 if (phba->hba_flag & FCF_TS_INPROG)
661 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
662 "2870 FCF table scan in progress\n");
663 if (phba->hba_flag & FCF_RR_INPROG)
664 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
665 "2871 FLOGI roundrobin FCF failover "
668 lpfc_unregister_unused_fcf(phba);
672 * lpfc_alloc_fast_evt - Allocates data structure for posting event
673 * @phba: Pointer to hba context object.
675 * This function is called from the functions which need to post
676 * events from interrupt context. This function allocates data
677 * structure required for posting event. It also keeps track of
678 * number of events pending and prevent event storm when there are
681 struct lpfc_fast_path_event *
682 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
683 struct lpfc_fast_path_event *ret;
685 /* If there are lot of fast event do not exhaust memory due to this */
686 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
689 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
692 atomic_inc(&phba->fast_event_count);
693 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
694 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
700 * lpfc_free_fast_evt - Frees event data structure
701 * @phba: Pointer to hba context object.
702 * @evt: Event object which need to be freed.
704 * This function frees the data structure required for posting
708 lpfc_free_fast_evt(struct lpfc_hba *phba,
709 struct lpfc_fast_path_event *evt) {
711 atomic_dec(&phba->fast_event_count);
716 * lpfc_send_fastpath_evt - Posts events generated from fast path
717 * @phba: Pointer to hba context object.
718 * @evtp: Event data structure.
720 * This function is called from worker thread, when the interrupt
721 * context need to post an event. This function posts the event
722 * to fc transport netlink interface.
725 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
726 struct lpfc_work_evt *evtp)
728 unsigned long evt_category, evt_sub_category;
729 struct lpfc_fast_path_event *fast_evt_data;
731 uint32_t evt_data_size;
732 struct Scsi_Host *shost;
734 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
737 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
738 evt_sub_category = (unsigned long) fast_evt_data->un.
739 fabric_evt.subcategory;
740 shost = lpfc_shost_from_vport(fast_evt_data->vport);
741 if (evt_category == FC_REG_FABRIC_EVENT) {
742 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
743 evt_data = (char *) &fast_evt_data->un.read_check_error;
744 evt_data_size = sizeof(fast_evt_data->un.
746 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
747 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
748 evt_data = (char *) &fast_evt_data->un.fabric_evt;
749 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
751 lpfc_free_fast_evt(phba, fast_evt_data);
754 } else if (evt_category == FC_REG_SCSI_EVENT) {
755 switch (evt_sub_category) {
756 case LPFC_EVENT_QFULL:
757 case LPFC_EVENT_DEVBSY:
758 evt_data = (char *) &fast_evt_data->un.scsi_evt;
759 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
761 case LPFC_EVENT_CHECK_COND:
762 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
763 evt_data_size = sizeof(fast_evt_data->un.
766 case LPFC_EVENT_VARQUEDEPTH:
767 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
768 evt_data_size = sizeof(fast_evt_data->un.
772 lpfc_free_fast_evt(phba, fast_evt_data);
776 lpfc_free_fast_evt(phba, fast_evt_data);
780 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
781 fc_host_post_vendor_event(shost,
782 fc_get_event_number(),
787 lpfc_free_fast_evt(phba, fast_evt_data);
792 lpfc_work_list_done(struct lpfc_hba *phba)
794 struct lpfc_work_evt *evtp = NULL;
795 struct lpfc_nodelist *ndlp;
801 spin_lock_irq(&phba->hbalock);
802 while (!list_empty(&phba->work_list)) {
803 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
805 spin_unlock_irq(&phba->hbalock);
806 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
809 case LPFC_EVT_ELS_RETRY:
810 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
812 lpfc_els_retry_delay_handler(ndlp);
813 free_evt = 0; /* evt is part of ndlp */
815 /* decrement the node reference count held
816 * for this queued work
820 case LPFC_EVT_DEV_LOSS:
821 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
822 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
824 /* decrement the node reference count held for
827 nlp_did = ndlp->nlp_DID;
829 if (phba->sli_rev == LPFC_SLI_REV4)
830 lpfc_sli4_post_dev_loss_tmo_handler(phba,
834 case LPFC_EVT_RECOVER_PORT:
835 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
837 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
840 /* decrement the node reference count held for
845 case LPFC_EVT_ONLINE:
846 if (phba->link_state < LPFC_LINK_DOWN)
847 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
849 *(int *) (evtp->evt_arg1) = 0;
850 complete((struct completion *)(evtp->evt_arg2));
852 case LPFC_EVT_OFFLINE_PREP:
853 if (phba->link_state >= LPFC_LINK_DOWN)
854 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
855 *(int *)(evtp->evt_arg1) = 0;
856 complete((struct completion *)(evtp->evt_arg2));
858 case LPFC_EVT_OFFLINE:
860 lpfc_sli_brdrestart(phba);
861 *(int *)(evtp->evt_arg1) =
862 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
863 lpfc_unblock_mgmt_io(phba);
864 complete((struct completion *)(evtp->evt_arg2));
866 case LPFC_EVT_WARM_START:
868 lpfc_reset_barrier(phba);
869 lpfc_sli_brdreset(phba);
870 lpfc_hba_down_post(phba);
871 *(int *)(evtp->evt_arg1) =
872 lpfc_sli_brdready(phba, HS_MBRDY);
873 lpfc_unblock_mgmt_io(phba);
874 complete((struct completion *)(evtp->evt_arg2));
878 *(int *)(evtp->evt_arg1)
879 = (phba->pport->stopped)
880 ? 0 : lpfc_sli_brdkill(phba);
881 lpfc_unblock_mgmt_io(phba);
882 complete((struct completion *)(evtp->evt_arg2));
884 case LPFC_EVT_FASTPATH_MGMT_EVT:
885 lpfc_send_fastpath_evt(phba, evtp);
888 case LPFC_EVT_RESET_HBA:
889 if (!(phba->pport->load_flag & FC_UNLOADING))
890 lpfc_reset_hba(phba);
895 spin_lock_irq(&phba->hbalock);
897 spin_unlock_irq(&phba->hbalock);
902 lpfc_work_done(struct lpfc_hba *phba)
904 struct lpfc_sli_ring *pring;
905 uint32_t ha_copy, status, control, work_port_events;
906 struct lpfc_vport **vports;
907 struct lpfc_vport *vport;
911 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
912 spin_lock_irq(&phba->hbalock);
913 ha_copy = phba->work_ha;
915 spin_unlock_irq(&phba->hbalock);
919 /* First, try to post the next mailbox command to SLI4 device */
920 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC && !hba_pci_err)
921 lpfc_sli4_post_async_mbox(phba);
923 if (ha_copy & HA_ERATT) {
924 /* Handle the error attention event */
925 lpfc_handle_eratt(phba);
927 if (phba->fw_dump_cmpl) {
928 complete(phba->fw_dump_cmpl);
929 phba->fw_dump_cmpl = NULL;
933 if (ha_copy & HA_MBATT)
934 lpfc_sli_handle_mb_event(phba);
936 if (ha_copy & HA_LATT)
937 lpfc_handle_latt(phba);
939 /* Handle VMID Events */
940 if (lpfc_is_vmid_enabled(phba) && !hba_pci_err) {
941 if (phba->pport->work_port_events &
942 WORKER_CHECK_VMID_ISSUE_QFPA) {
943 lpfc_check_vmid_qfpa_issue(phba);
944 phba->pport->work_port_events &=
945 ~WORKER_CHECK_VMID_ISSUE_QFPA;
947 if (phba->pport->work_port_events &
948 WORKER_CHECK_INACTIVE_VMID) {
949 lpfc_check_inactive_vmid(phba);
950 phba->pport->work_port_events &=
951 ~WORKER_CHECK_INACTIVE_VMID;
955 /* Process SLI4 events */
956 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
957 if (phba->hba_flag & HBA_RRQ_ACTIVE)
958 lpfc_handle_rrq_active(phba);
959 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
960 lpfc_sli4_els_xri_abort_event_proc(phba);
961 if (phba->hba_flag & ASYNC_EVENT)
962 lpfc_sli4_async_event_proc(phba);
963 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
964 spin_lock_irq(&phba->hbalock);
965 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
966 spin_unlock_irq(&phba->hbalock);
967 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
969 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
970 lpfc_sli4_fcf_redisc_event_proc(phba);
973 vports = lpfc_create_vport_work_array(phba);
975 for (i = 0; i <= phba->max_vports; i++) {
977 * We could have no vports in array if unloading, so if
978 * this happens then just use the pport
980 if (vports[i] == NULL && i == 0)
986 spin_lock_irq(&vport->work_port_lock);
987 work_port_events = vport->work_port_events;
988 vport->work_port_events &= ~work_port_events;
989 spin_unlock_irq(&vport->work_port_lock);
992 if (work_port_events & WORKER_DISC_TMO)
993 lpfc_disc_timeout_handler(vport);
994 if (work_port_events & WORKER_ELS_TMO)
995 lpfc_els_timeout_handler(vport);
996 if (work_port_events & WORKER_HB_TMO)
997 lpfc_hb_timeout_handler(phba);
998 if (work_port_events & WORKER_MBOX_TMO)
999 lpfc_mbox_timeout_handler(phba);
1000 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
1001 lpfc_unblock_fabric_iocbs(phba);
1002 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
1003 lpfc_ramp_down_queue_handler(phba);
1004 if (work_port_events & WORKER_DELAYED_DISC_TMO)
1005 lpfc_delayed_disc_timeout_handler(vport);
1007 lpfc_destroy_vport_work_array(phba, vports);
1009 pring = lpfc_phba_elsring(phba);
1010 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
1011 status >>= (4*LPFC_ELS_RING);
1012 if (pring && (status & HA_RXMASK ||
1013 pring->flag & LPFC_DEFERRED_RING_EVENT ||
1014 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
1015 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
1016 pring->flag |= LPFC_DEFERRED_RING_EVENT;
1017 /* Preserve legacy behavior. */
1018 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
1019 set_bit(LPFC_DATA_READY, &phba->data_flags);
1021 /* Driver could have abort request completed in queue
1022 * when link goes down. Allow for this transition.
1024 if (phba->link_state >= LPFC_LINK_DOWN ||
1025 phba->link_flag & LS_MDS_LOOPBACK) {
1026 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
1027 lpfc_sli_handle_slow_ring_event(phba, pring,
1032 if (phba->sli_rev == LPFC_SLI_REV4)
1033 lpfc_drain_txq(phba);
1035 * Turn on Ring interrupts
1037 if (phba->sli_rev <= LPFC_SLI_REV3) {
1038 spin_lock_irq(&phba->hbalock);
1039 control = readl(phba->HCregaddr);
1040 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
1041 lpfc_debugfs_slow_ring_trc(phba,
1042 "WRK Enable ring: cntl:x%x hacopy:x%x",
1043 control, ha_copy, 0);
1045 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
1046 writel(control, phba->HCregaddr);
1047 readl(phba->HCregaddr); /* flush */
1049 lpfc_debugfs_slow_ring_trc(phba,
1050 "WRK Ring ok: cntl:x%x hacopy:x%x",
1051 control, ha_copy, 0);
1053 spin_unlock_irq(&phba->hbalock);
1056 lpfc_work_list_done(phba);
1060 lpfc_do_work(void *p)
1062 struct lpfc_hba *phba = p;
1065 set_user_nice(current, MIN_NICE);
1066 current->flags |= PF_NOFREEZE;
1067 phba->data_flags = 0;
1069 while (!kthread_should_stop()) {
1070 /* wait and check worker queue activities */
1071 rc = wait_event_interruptible(phba->work_waitq,
1072 (test_and_clear_bit(LPFC_DATA_READY,
1074 || kthread_should_stop()));
1075 /* Signal wakeup shall terminate the worker thread */
1077 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1078 "0433 Wakeup on signal: rc=x%x\n", rc);
1082 /* Attend pending lpfc data processing */
1083 lpfc_work_done(phba);
1085 phba->worker_thread = NULL;
1086 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1087 "0432 Worker thread stopped.\n");
1092 * This is only called to handle FC worker events. Since this a rare
1093 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
1094 * embedding it in the IOCB.
1097 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
1100 struct lpfc_work_evt *evtp;
1101 unsigned long flags;
1104 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
1105 * be queued to worker thread for processing
1107 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
1111 evtp->evt_arg1 = arg1;
1112 evtp->evt_arg2 = arg2;
1115 spin_lock_irqsave(&phba->hbalock, flags);
1116 list_add_tail(&evtp->evt_listp, &phba->work_list);
1117 spin_unlock_irqrestore(&phba->hbalock, flags);
1119 lpfc_worker_wake_up(phba);
1125 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
1127 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1128 struct lpfc_hba *phba = vport->phba;
1129 struct lpfc_nodelist *ndlp, *next_ndlp;
1131 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1132 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
1133 ((vport->port_type == LPFC_NPIV_PORT) &&
1134 ((ndlp->nlp_DID == NameServer_DID) ||
1135 (ndlp->nlp_DID == FDMI_DID) ||
1136 (ndlp->nlp_DID == Fabric_Cntl_DID))))
1137 lpfc_unreg_rpi(vport, ndlp);
1139 /* Leave Fabric nodes alone on link down */
1140 if ((phba->sli_rev < LPFC_SLI_REV4) &&
1141 (!remove && ndlp->nlp_type & NLP_FABRIC))
1144 /* Notify transport of connectivity loss to trigger cleanup. */
1145 if (phba->nvmet_support &&
1146 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
1147 lpfc_nvmet_invalidate_host(phba, ndlp);
1149 lpfc_disc_state_machine(vport, ndlp, NULL,
1152 : NLP_EVT_DEVICE_RECOVERY);
1154 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
1155 if (phba->sli_rev == LPFC_SLI_REV4)
1156 lpfc_sli4_unreg_all_rpis(vport);
1157 lpfc_mbx_unreg_vpi(vport);
1158 spin_lock_irq(shost->host_lock);
1159 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1160 spin_unlock_irq(shost->host_lock);
1165 lpfc_port_link_failure(struct lpfc_vport *vport)
1167 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
1169 /* Cleanup any outstanding received buffers */
1170 lpfc_cleanup_rcv_buffers(vport);
1172 /* Cleanup any outstanding RSCN activity */
1173 lpfc_els_flush_rscn(vport);
1175 /* Cleanup any outstanding ELS commands */
1176 lpfc_els_flush_cmd(vport);
1178 lpfc_cleanup_rpis(vport, 0);
1180 /* Turn off discovery timer if its running */
1181 lpfc_can_disctmo(vport);
1185 lpfc_linkdown_port(struct lpfc_vport *vport)
1187 struct lpfc_hba *phba = vport->phba;
1188 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1190 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1191 fc_host_post_event(shost, fc_get_event_number(),
1192 FCH_EVT_LINKDOWN, 0);
1194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1195 "Link Down: state:x%x rtry:x%x flg:x%x",
1196 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1198 lpfc_port_link_failure(vport);
1200 /* Stop delayed Nport discovery */
1201 spin_lock_irq(shost->host_lock);
1202 vport->fc_flag &= ~FC_DISC_DELAYED;
1203 spin_unlock_irq(shost->host_lock);
1204 del_timer_sync(&vport->delayed_disc_tmo);
1206 if (phba->sli_rev == LPFC_SLI_REV4 &&
1207 vport->port_type == LPFC_PHYSICAL_PORT &&
1208 phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG) {
1209 /* Assume success on link up */
1210 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
1215 lpfc_linkdown(struct lpfc_hba *phba)
1217 struct lpfc_vport *vport = phba->pport;
1218 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1219 struct lpfc_vport **vports;
1224 if (phba->link_state == LPFC_LINK_DOWN)
1227 /* Block all SCSI stack I/Os */
1228 lpfc_scsi_dev_block(phba);
1229 offline = pci_channel_offline(phba->pcidev);
1231 phba->defer_flogi_acc_flag = false;
1233 /* Clear external loopback plug detected flag */
1234 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
1236 spin_lock_irq(&phba->hbalock);
1237 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1238 spin_unlock_irq(&phba->hbalock);
1239 if (phba->link_state > LPFC_LINK_DOWN) {
1240 phba->link_state = LPFC_LINK_DOWN;
1241 if (phba->sli4_hba.conf_trunk) {
1242 phba->trunk_link.link0.state = 0;
1243 phba->trunk_link.link1.state = 0;
1244 phba->trunk_link.link2.state = 0;
1245 phba->trunk_link.link3.state = 0;
1246 phba->trunk_link.phy_lnk_speed =
1247 LPFC_LINK_SPEED_UNKNOWN;
1248 phba->sli4_hba.link_state.logical_speed =
1249 LPFC_LINK_SPEED_UNKNOWN;
1251 spin_lock_irq(shost->host_lock);
1252 phba->pport->fc_flag &= ~FC_LBIT;
1253 spin_unlock_irq(shost->host_lock);
1255 vports = lpfc_create_vport_work_array(phba);
1256 if (vports != NULL) {
1257 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1258 /* Issue a LINK DOWN event to all nodes */
1259 lpfc_linkdown_port(vports[i]);
1261 vports[i]->fc_myDID = 0;
1263 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1264 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1265 if (phba->nvmet_support)
1266 lpfc_nvmet_update_targetport(phba);
1268 lpfc_nvme_update_localport(vports[i]);
1272 lpfc_destroy_vport_work_array(phba, vports);
1274 /* Clean up any SLI3 firmware default rpi's */
1275 if (phba->sli_rev > LPFC_SLI_REV3 || offline)
1276 goto skip_unreg_did;
1278 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1280 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
1282 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1283 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1284 == MBX_NOT_FINISHED) {
1285 mempool_free(mb, phba->mbox_mem_pool);
1290 /* Setup myDID for link up if we are in pt2pt mode */
1291 if (phba->pport->fc_flag & FC_PT2PT) {
1292 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1294 lpfc_config_link(phba, mb);
1295 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1297 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1298 == MBX_NOT_FINISHED) {
1299 mempool_free(mb, phba->mbox_mem_pool);
1302 spin_lock_irq(shost->host_lock);
1303 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
1304 phba->pport->rcv_flogi_cnt = 0;
1305 spin_unlock_irq(shost->host_lock);
1311 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
1313 struct lpfc_nodelist *ndlp;
1315 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1316 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
1318 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1320 if (ndlp->nlp_type & NLP_FABRIC) {
1321 /* On Linkup its safe to clean up the ndlp
1322 * from Fabric connections.
1324 if (ndlp->nlp_DID != Fabric_DID)
1325 lpfc_unreg_rpi(vport, ndlp);
1326 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1327 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
1328 /* Fail outstanding IO now since device is
1331 lpfc_unreg_rpi(vport, ndlp);
1337 lpfc_linkup_port(struct lpfc_vport *vport)
1339 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1340 struct lpfc_hba *phba = vport->phba;
1342 if ((vport->load_flag & FC_UNLOADING) != 0)
1345 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1346 "Link Up: top:x%x speed:x%x flg:x%x",
1347 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1349 /* If NPIV is not enabled, only bring the physical port up */
1350 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1351 (vport != phba->pport))
1354 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1355 fc_host_post_event(shost, fc_get_event_number(),
1358 spin_lock_irq(shost->host_lock);
1359 if (phba->defer_flogi_acc_flag)
1360 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_RSCN_MODE |
1361 FC_NLP_MORE | FC_RSCN_DISCOVERY);
1363 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI |
1364 FC_ABORT_DISCOVERY | FC_RSCN_MODE |
1365 FC_NLP_MORE | FC_RSCN_DISCOVERY);
1366 vport->fc_flag |= FC_NDISC_ACTIVE;
1367 vport->fc_ns_retry = 0;
1368 spin_unlock_irq(shost->host_lock);
1369 lpfc_setup_fdmi_mask(vport);
1371 lpfc_linkup_cleanup_nodes(vport);
1375 lpfc_linkup(struct lpfc_hba *phba)
1377 struct lpfc_vport **vports;
1379 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1381 phba->link_state = LPFC_LINK_UP;
1383 /* Unblock fabric iocbs if they are blocked */
1384 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1385 del_timer_sync(&phba->fabric_block_timer);
1387 vports = lpfc_create_vport_work_array(phba);
1389 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1390 lpfc_linkup_port(vports[i]);
1391 lpfc_destroy_vport_work_array(phba, vports);
1393 /* Clear the pport flogi counter in case the link down was
1394 * absorbed without an ACQE. No lock here - in worker thread
1395 * and discovery is synchronized.
1397 spin_lock_irq(shost->host_lock);
1398 phba->pport->rcv_flogi_cnt = 0;
1399 spin_unlock_irq(shost->host_lock);
1401 /* reinitialize initial HBA flag */
1402 phba->hba_flag &= ~(HBA_FLOGI_ISSUED | HBA_RHBA_CMPL);
1408 * This routine handles processing a CLEAR_LA mailbox
1409 * command upon completion. It is setup in the LPFC_MBOXQ
1410 * as the completion routine when the command is
1411 * handed off to the SLI layer. SLI3 only.
1414 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1416 struct lpfc_vport *vport = pmb->vport;
1417 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1418 struct lpfc_sli *psli = &phba->sli;
1419 MAILBOX_t *mb = &pmb->u.mb;
1422 /* Since we don't do discovery right now, turn these off here */
1423 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1424 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1426 /* Check for error */
1427 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1428 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1429 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1430 "0320 CLEAR_LA mbxStatus error x%x hba "
1432 mb->mbxStatus, vport->port_state);
1433 phba->link_state = LPFC_HBA_ERROR;
1437 if (vport->port_type == LPFC_PHYSICAL_PORT)
1438 phba->link_state = LPFC_HBA_READY;
1440 spin_lock_irq(&phba->hbalock);
1441 psli->sli_flag |= LPFC_PROCESS_LA;
1442 control = readl(phba->HCregaddr);
1443 control |= HC_LAINT_ENA;
1444 writel(control, phba->HCregaddr);
1445 readl(phba->HCregaddr); /* flush */
1446 spin_unlock_irq(&phba->hbalock);
1447 mempool_free(pmb, phba->mbox_mem_pool);
1451 /* Device Discovery completes */
1452 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1453 "0225 Device Discovery completes\n");
1454 mempool_free(pmb, phba->mbox_mem_pool);
1456 spin_lock_irq(shost->host_lock);
1457 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1458 spin_unlock_irq(shost->host_lock);
1460 lpfc_can_disctmo(vport);
1462 /* turn on Link Attention interrupts */
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);
1476 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1478 struct lpfc_vport *vport = pmb->vport;
1479 LPFC_MBOXQ_t *sparam_mb;
1480 u16 status = pmb->u.mb.mbxStatus;
1483 mempool_free(pmb, phba->mbox_mem_pool);
1488 /* don't perform discovery for SLI4 loopback diagnostic test */
1489 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1490 !(phba->hba_flag & HBA_FCOE_MODE) &&
1491 (phba->link_flag & LS_LOOPBACK_MODE))
1494 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1495 vport->fc_flag & FC_PUBLIC_LOOP &&
1496 !(vport->fc_flag & FC_LBIT)) {
1497 /* Need to wait for FAN - use discovery timer
1498 * for timeout. port_state is identically
1499 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1501 lpfc_set_disctmo(vport);
1505 /* Start discovery by sending a FLOGI. port_state is identically
1506 * LPFC_FLOGI while waiting for FLOGI cmpl.
1508 if (vport->port_state != LPFC_FLOGI) {
1509 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1510 * bb-credit recovery is in place.
1512 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1513 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1514 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1519 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1521 mempool_free(sparam_mb, phba->mbox_mem_pool);
1524 sparam_mb->vport = vport;
1525 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1526 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1527 if (rc == MBX_NOT_FINISHED) {
1528 lpfc_mbox_rsrc_cleanup(phba, sparam_mb,
1533 phba->hba_flag |= HBA_DEFER_FLOGI;
1535 lpfc_initial_flogi(vport);
1538 if (vport->fc_flag & FC_PT2PT)
1539 lpfc_disc_start(vport);
1544 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1545 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1546 status, vport->port_state);
1549 lpfc_linkdown(phba);
1551 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1552 "0200 CONFIG_LINK bad hba state x%x\n",
1555 lpfc_issue_clear_la(phba, vport);
1560 * lpfc_sli4_clear_fcf_rr_bmask
1561 * @phba: pointer to the struct lpfc_hba for this port.
1562 * This fucnction resets the round robin bit mask and clears the
1563 * fcf priority list. The list deletions are done while holding the
1564 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1565 * from the lpfc_fcf_pri record.
1568 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1570 struct lpfc_fcf_pri *fcf_pri;
1571 struct lpfc_fcf_pri *next_fcf_pri;
1572 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1573 spin_lock_irq(&phba->hbalock);
1574 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1575 &phba->fcf.fcf_pri_list, list) {
1576 list_del_init(&fcf_pri->list);
1577 fcf_pri->fcf_rec.flag = 0;
1579 spin_unlock_irq(&phba->hbalock);
1582 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1584 struct lpfc_vport *vport = mboxq->vport;
1586 if (mboxq->u.mb.mbxStatus) {
1587 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1588 "2017 REG_FCFI mbxStatus error x%x "
1589 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1594 /* Start FCoE discovery by sending a FLOGI. */
1595 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1596 /* Set the FCFI registered flag */
1597 spin_lock_irq(&phba->hbalock);
1598 phba->fcf.fcf_flag |= FCF_REGISTERED;
1599 spin_unlock_irq(&phba->hbalock);
1601 /* If there is a pending FCoE event, restart FCF table scan. */
1602 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1603 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1606 /* Mark successful completion of FCF table scan */
1607 spin_lock_irq(&phba->hbalock);
1608 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1609 phba->hba_flag &= ~FCF_TS_INPROG;
1610 if (vport->port_state != LPFC_FLOGI) {
1611 phba->hba_flag |= FCF_RR_INPROG;
1612 spin_unlock_irq(&phba->hbalock);
1613 lpfc_issue_init_vfi(vport);
1616 spin_unlock_irq(&phba->hbalock);
1620 spin_lock_irq(&phba->hbalock);
1621 phba->hba_flag &= ~FCF_RR_INPROG;
1622 spin_unlock_irq(&phba->hbalock);
1624 mempool_free(mboxq, phba->mbox_mem_pool);
1628 * lpfc_fab_name_match - Check if the fcf fabric name match.
1629 * @fab_name: pointer to fabric name.
1630 * @new_fcf_record: pointer to fcf record.
1632 * This routine compare the fcf record's fabric name with provided
1633 * fabric name. If the fabric name are identical this function
1634 * returns 1 else return 0.
1637 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1639 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1641 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1643 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1645 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1647 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1649 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1651 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1653 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1659 * lpfc_sw_name_match - Check if the fcf switch name match.
1660 * @sw_name: pointer to switch name.
1661 * @new_fcf_record: pointer to fcf record.
1663 * This routine compare the fcf record's switch name with provided
1664 * switch name. If the switch name are identical this function
1665 * returns 1 else return 0.
1668 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1670 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1672 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1674 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1676 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1678 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1680 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1682 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1684 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1690 * lpfc_mac_addr_match - Check if the fcf mac address match.
1691 * @mac_addr: pointer to mac address.
1692 * @new_fcf_record: pointer to fcf record.
1694 * This routine compare the fcf record's mac address with HBA's
1695 * FCF mac address. If the mac addresses are identical this function
1696 * returns 1 else return 0.
1699 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1701 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1703 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1705 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1707 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1709 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1711 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1717 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1719 return (curr_vlan_id == new_vlan_id);
1723 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1724 * @phba: pointer to lpfc hba data structure.
1725 * @fcf_index: Index for the lpfc_fcf_record.
1726 * @new_fcf_record: pointer to hba fcf record.
1728 * This routine updates the driver FCF priority record from the new HBA FCF
1729 * record. The hbalock is asserted held in the code path calling this
1733 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1734 struct fcf_record *new_fcf_record
1737 struct lpfc_fcf_pri *fcf_pri;
1739 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1740 fcf_pri->fcf_rec.fcf_index = fcf_index;
1741 /* FCF record priority */
1742 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1747 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1748 * @fcf_rec: pointer to driver fcf record.
1749 * @new_fcf_record: pointer to fcf record.
1751 * This routine copies the FCF information from the FCF
1752 * record to lpfc_hba data structure.
1755 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1756 struct fcf_record *new_fcf_record)
1759 fcf_rec->fabric_name[0] =
1760 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1761 fcf_rec->fabric_name[1] =
1762 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1763 fcf_rec->fabric_name[2] =
1764 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1765 fcf_rec->fabric_name[3] =
1766 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1767 fcf_rec->fabric_name[4] =
1768 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1769 fcf_rec->fabric_name[5] =
1770 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1771 fcf_rec->fabric_name[6] =
1772 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1773 fcf_rec->fabric_name[7] =
1774 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1776 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1777 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1778 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1779 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1780 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1781 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1782 /* FCF record index */
1783 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1784 /* FCF record priority */
1785 fcf_rec->priority = new_fcf_record->fip_priority;
1787 fcf_rec->switch_name[0] =
1788 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1789 fcf_rec->switch_name[1] =
1790 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1791 fcf_rec->switch_name[2] =
1792 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1793 fcf_rec->switch_name[3] =
1794 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1795 fcf_rec->switch_name[4] =
1796 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1797 fcf_rec->switch_name[5] =
1798 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1799 fcf_rec->switch_name[6] =
1800 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1801 fcf_rec->switch_name[7] =
1802 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1806 * __lpfc_update_fcf_record - Update driver fcf record
1807 * @phba: pointer to lpfc hba data structure.
1808 * @fcf_rec: pointer to driver fcf record.
1809 * @new_fcf_record: pointer to hba fcf record.
1810 * @addr_mode: address mode to be set to the driver fcf record.
1811 * @vlan_id: vlan tag to be set to the driver fcf record.
1812 * @flag: flag bits to be set to the driver fcf record.
1814 * This routine updates the driver FCF record from the new HBA FCF record
1815 * together with the address mode, vlan_id, and other informations. This
1816 * routine is called with the hbalock held.
1819 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1820 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1821 uint16_t vlan_id, uint32_t flag)
1823 lockdep_assert_held(&phba->hbalock);
1825 /* Copy the fields from the HBA's FCF record */
1826 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1827 /* Update other fields of driver FCF record */
1828 fcf_rec->addr_mode = addr_mode;
1829 fcf_rec->vlan_id = vlan_id;
1830 fcf_rec->flag |= (flag | RECORD_VALID);
1831 __lpfc_update_fcf_record_pri(phba,
1832 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1837 * lpfc_register_fcf - Register the FCF with hba.
1838 * @phba: pointer to lpfc hba data structure.
1840 * This routine issues a register fcfi mailbox command to register
1844 lpfc_register_fcf(struct lpfc_hba *phba)
1846 LPFC_MBOXQ_t *fcf_mbxq;
1849 spin_lock_irq(&phba->hbalock);
1850 /* If the FCF is not available do nothing. */
1851 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1852 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1853 spin_unlock_irq(&phba->hbalock);
1857 /* The FCF is already registered, start discovery */
1858 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1859 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1860 phba->hba_flag &= ~FCF_TS_INPROG;
1861 if (phba->pport->port_state != LPFC_FLOGI &&
1862 phba->pport->fc_flag & FC_FABRIC) {
1863 phba->hba_flag |= FCF_RR_INPROG;
1864 spin_unlock_irq(&phba->hbalock);
1865 lpfc_initial_flogi(phba->pport);
1868 spin_unlock_irq(&phba->hbalock);
1871 spin_unlock_irq(&phba->hbalock);
1873 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1875 spin_lock_irq(&phba->hbalock);
1876 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1877 spin_unlock_irq(&phba->hbalock);
1881 lpfc_reg_fcfi(phba, fcf_mbxq);
1882 fcf_mbxq->vport = phba->pport;
1883 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1884 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1885 if (rc == MBX_NOT_FINISHED) {
1886 spin_lock_irq(&phba->hbalock);
1887 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1888 spin_unlock_irq(&phba->hbalock);
1889 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1896 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1897 * @phba: pointer to lpfc hba data structure.
1898 * @new_fcf_record: pointer to fcf record.
1899 * @boot_flag: Indicates if this record used by boot bios.
1900 * @addr_mode: The address mode to be used by this FCF
1901 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1903 * This routine compare the fcf record with connect list obtained from the
1904 * config region to decide if this FCF can be used for SAN discovery. It returns
1905 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1906 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1907 * is used by boot bios and addr_mode will indicate the addressing mode to be
1908 * used for this FCF when the function returns.
1909 * If the FCF record need to be used with a particular vlan id, the vlan is
1910 * set in the vlan_id on return of the function. If not VLAN tagging need to
1911 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1914 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1915 struct fcf_record *new_fcf_record,
1916 uint32_t *boot_flag, uint32_t *addr_mode,
1919 struct lpfc_fcf_conn_entry *conn_entry;
1920 int i, j, fcf_vlan_id = 0;
1922 /* Find the lowest VLAN id in the FCF record */
1923 for (i = 0; i < 512; i++) {
1924 if (new_fcf_record->vlan_bitmap[i]) {
1925 fcf_vlan_id = i * 8;
1927 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1935 /* FCF not valid/available or solicitation in progress */
1936 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1937 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1938 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1941 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1943 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1945 if (phba->valid_vlan)
1946 *vlan_id = phba->vlan_id;
1948 *vlan_id = LPFC_FCOE_NULL_VID;
1953 * If there are no FCF connection table entry, driver connect to all
1956 if (list_empty(&phba->fcf_conn_rec_list)) {
1958 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1962 * When there are no FCF connect entries, use driver's default
1963 * addressing mode - FPMA.
1965 if (*addr_mode & LPFC_FCF_FPMA)
1966 *addr_mode = LPFC_FCF_FPMA;
1968 /* If FCF record report a vlan id use that vlan id */
1970 *vlan_id = fcf_vlan_id;
1972 *vlan_id = LPFC_FCOE_NULL_VID;
1976 list_for_each_entry(conn_entry,
1977 &phba->fcf_conn_rec_list, list) {
1978 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1981 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1982 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1985 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1986 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1989 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1991 * If the vlan bit map does not have the bit set for the
1992 * vlan id to be used, then it is not a match.
1994 if (!(new_fcf_record->vlan_bitmap
1995 [conn_entry->conn_rec.vlan_tag / 8] &
1996 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
2001 * If connection record does not support any addressing mode,
2002 * skip the FCF record.
2004 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
2005 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
2009 * Check if the connection record specifies a required
2012 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2013 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
2016 * If SPMA required but FCF not support this continue.
2018 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2019 !(bf_get(lpfc_fcf_record_mac_addr_prov,
2020 new_fcf_record) & LPFC_FCF_SPMA))
2024 * If FPMA required but FCF not support this continue.
2026 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2027 !(bf_get(lpfc_fcf_record_mac_addr_prov,
2028 new_fcf_record) & LPFC_FCF_FPMA))
2033 * This fcf record matches filtering criteria.
2035 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
2041 * If user did not specify any addressing mode, or if the
2042 * preferred addressing mode specified by user is not supported
2043 * by FCF, allow fabric to pick the addressing mode.
2045 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
2048 * If the user specified a required address mode, assign that
2051 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2052 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
2053 *addr_mode = (conn_entry->conn_rec.flags &
2055 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
2057 * If the user specified a preferred address mode, use the
2058 * addr mode only if FCF support the addr_mode.
2060 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2061 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2062 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2063 (*addr_mode & LPFC_FCF_SPMA))
2064 *addr_mode = LPFC_FCF_SPMA;
2065 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2066 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2067 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2068 (*addr_mode & LPFC_FCF_FPMA))
2069 *addr_mode = LPFC_FCF_FPMA;
2071 /* If matching connect list has a vlan id, use it */
2072 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
2073 *vlan_id = conn_entry->conn_rec.vlan_tag;
2075 * If no vlan id is specified in connect list, use the vlan id
2078 else if (fcf_vlan_id)
2079 *vlan_id = fcf_vlan_id;
2081 *vlan_id = LPFC_FCOE_NULL_VID;
2090 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
2091 * @phba: pointer to lpfc hba data structure.
2092 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
2094 * This function check if there is any fcoe event pending while driver
2095 * scan FCF entries. If there is any pending event, it will restart the
2096 * FCF saning and return 1 else return 0.
2099 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
2102 * If the Link is up and no FCoE events while in the
2103 * FCF discovery, no need to restart FCF discovery.
2105 if ((phba->link_state >= LPFC_LINK_UP) &&
2106 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
2109 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2110 "2768 Pending link or FCF event during current "
2111 "handling of the previous event: link_state:x%x, "
2112 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
2113 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
2114 phba->fcoe_eventtag);
2116 spin_lock_irq(&phba->hbalock);
2117 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
2118 spin_unlock_irq(&phba->hbalock);
2120 if (phba->link_state >= LPFC_LINK_UP) {
2121 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2122 "2780 Restart FCF table scan due to "
2123 "pending FCF event:evt_tag_at_scan:x%x, "
2124 "evt_tag_current:x%x\n",
2125 phba->fcoe_eventtag_at_fcf_scan,
2126 phba->fcoe_eventtag);
2127 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
2130 * Do not continue FCF discovery and clear FCF_TS_INPROG
2133 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2134 "2833 Stop FCF discovery process due to link "
2135 "state change (x%x)\n", phba->link_state);
2136 spin_lock_irq(&phba->hbalock);
2137 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
2138 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
2139 spin_unlock_irq(&phba->hbalock);
2142 /* Unregister the currently registered FCF if required */
2144 spin_lock_irq(&phba->hbalock);
2145 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
2146 spin_unlock_irq(&phba->hbalock);
2147 lpfc_sli4_unregister_fcf(phba);
2153 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
2154 * @phba: pointer to lpfc hba data structure.
2155 * @fcf_cnt: number of eligible fcf record seen so far.
2157 * This function makes an running random selection decision on FCF record to
2158 * use through a sequence of @fcf_cnt eligible FCF records with equal
2159 * probability. To perform integer manunipulation of random numbers with
2160 * size unit32_t, a 16-bit random number returned from get_random_u16() is
2161 * taken as the random random number generated.
2163 * Returns true when outcome is for the newly read FCF record should be
2164 * chosen; otherwise, return false when outcome is for keeping the previously
2165 * chosen FCF record.
2168 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
2172 /* Get 16-bit uniform random number */
2173 rand_num = get_random_u16();
2175 /* Decision with probability 1/fcf_cnt */
2176 if ((fcf_cnt * rand_num) < 0xFFFF)
2183 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
2184 * @phba: pointer to lpfc hba data structure.
2185 * @mboxq: pointer to mailbox object.
2186 * @next_fcf_index: pointer to holder of next fcf index.
2188 * This routine parses the non-embedded fcf mailbox command by performing the
2189 * necessarily error checking, non-embedded read FCF record mailbox command
2190 * SGE parsing, and endianness swapping.
2192 * Returns the pointer to the new FCF record in the non-embedded mailbox
2193 * command DMA memory if successfully, other NULL.
2195 static struct fcf_record *
2196 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
2197 uint16_t *next_fcf_index)
2200 struct lpfc_mbx_sge sge;
2201 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2202 uint32_t shdr_status, shdr_add_status, if_type;
2203 union lpfc_sli4_cfg_shdr *shdr;
2204 struct fcf_record *new_fcf_record;
2206 /* Get the first SGE entry from the non-embedded DMA memory. This
2207 * routine only uses a single SGE.
2209 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2210 if (unlikely(!mboxq->sge_array)) {
2211 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2212 "2524 Failed to get the non-embedded SGE "
2213 "virtual address\n");
2216 virt_addr = mboxq->sge_array->addr[0];
2218 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
2219 lpfc_sli_pcimem_bcopy(shdr, shdr,
2220 sizeof(union lpfc_sli4_cfg_shdr));
2221 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2222 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2223 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2224 if (shdr_status || shdr_add_status) {
2225 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
2226 if_type == LPFC_SLI_INTF_IF_TYPE_2)
2227 lpfc_printf_log(phba, KERN_ERR,
2229 "2726 READ_FCF_RECORD Indicates empty "
2232 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2233 "2521 READ_FCF_RECORD mailbox failed "
2234 "with status x%x add_status x%x, "
2235 "mbx\n", shdr_status, shdr_add_status);
2239 /* Interpreting the returned information of the FCF record */
2240 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2241 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
2242 sizeof(struct lpfc_mbx_read_fcf_tbl));
2243 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
2244 new_fcf_record = (struct fcf_record *)(virt_addr +
2245 sizeof(struct lpfc_mbx_read_fcf_tbl));
2246 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
2247 offsetof(struct fcf_record, vlan_bitmap));
2248 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
2249 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
2251 return new_fcf_record;
2255 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
2256 * @phba: pointer to lpfc hba data structure.
2257 * @fcf_record: pointer to the fcf record.
2258 * @vlan_id: the lowest vlan identifier associated to this fcf record.
2259 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
2261 * This routine logs the detailed FCF record if the LOG_FIP loggin is
2265 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
2266 struct fcf_record *fcf_record,
2268 uint16_t next_fcf_index)
2270 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2271 "2764 READ_FCF_RECORD:\n"
2272 "\tFCF_Index : x%x\n"
2273 "\tFCF_Avail : x%x\n"
2274 "\tFCF_Valid : x%x\n"
2276 "\tFIP_Priority : x%x\n"
2277 "\tMAC_Provider : x%x\n"
2278 "\tLowest VLANID : x%x\n"
2279 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
2280 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2281 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2282 "\tNext_FCF_Index: x%x\n",
2283 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
2284 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
2285 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
2286 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
2287 fcf_record->fip_priority,
2288 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
2290 bf_get(lpfc_fcf_record_mac_0, fcf_record),
2291 bf_get(lpfc_fcf_record_mac_1, fcf_record),
2292 bf_get(lpfc_fcf_record_mac_2, fcf_record),
2293 bf_get(lpfc_fcf_record_mac_3, fcf_record),
2294 bf_get(lpfc_fcf_record_mac_4, fcf_record),
2295 bf_get(lpfc_fcf_record_mac_5, fcf_record),
2296 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
2297 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
2298 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
2299 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
2300 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
2301 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
2302 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
2303 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
2304 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
2305 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
2306 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
2307 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
2308 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
2309 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
2310 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
2311 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
2316 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
2317 * @phba: pointer to lpfc hba data structure.
2318 * @fcf_rec: pointer to an existing FCF record.
2319 * @new_fcf_record: pointer to a new FCF record.
2320 * @new_vlan_id: vlan id from the new FCF record.
2322 * This function performs matching test of a new FCF record against an existing
2323 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2324 * will not be used as part of the FCF record matching criteria.
2326 * Returns true if all the fields matching, otherwise returns false.
2329 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2330 struct lpfc_fcf_rec *fcf_rec,
2331 struct fcf_record *new_fcf_record,
2332 uint16_t new_vlan_id)
2334 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2335 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2337 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2339 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2341 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2343 if (fcf_rec->priority != new_fcf_record->fip_priority)
2349 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2350 * @vport: Pointer to vport object.
2351 * @fcf_index: index to next fcf.
2353 * This function processing the roundrobin fcf failover to next fcf index.
2354 * When this function is invoked, there will be a current fcf registered
2356 * Return: 0 for continue retrying flogi on currently registered fcf;
2357 * 1 for stop flogi on currently registered fcf;
2359 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2361 struct lpfc_hba *phba = vport->phba;
2364 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2365 spin_lock_irq(&phba->hbalock);
2366 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2367 spin_unlock_irq(&phba->hbalock);
2368 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2369 "2872 Devloss tmo with no eligible "
2370 "FCF, unregister in-use FCF (x%x) "
2371 "and rescan FCF table\n",
2372 phba->fcf.current_rec.fcf_indx);
2373 lpfc_unregister_fcf_rescan(phba);
2374 goto stop_flogi_current_fcf;
2376 /* Mark the end to FLOGI roundrobin failover */
2377 phba->hba_flag &= ~FCF_RR_INPROG;
2378 /* Allow action to new fcf asynchronous event */
2379 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2380 spin_unlock_irq(&phba->hbalock);
2381 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2382 "2865 No FCF available, stop roundrobin FCF "
2383 "failover and change port state:x%x/x%x\n",
2384 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2385 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2387 if (!phba->fcf.fcf_redisc_attempted) {
2388 lpfc_unregister_fcf(phba);
2390 rc = lpfc_sli4_redisc_fcf_table(phba);
2392 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2393 "3195 Rediscover FCF table\n");
2394 phba->fcf.fcf_redisc_attempted = 1;
2395 lpfc_sli4_clear_fcf_rr_bmask(phba);
2397 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2398 "3196 Rediscover FCF table "
2399 "failed. Status:x%x\n", rc);
2402 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2403 "3197 Already rediscover FCF table "
2404 "attempted. No more retry\n");
2406 goto stop_flogi_current_fcf;
2408 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2409 "2794 Try FLOGI roundrobin FCF failover to "
2410 "(x%x)\n", fcf_index);
2411 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2413 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2414 "2761 FLOGI roundrobin FCF failover "
2415 "failed (rc:x%x) to read FCF (x%x)\n",
2416 rc, phba->fcf.current_rec.fcf_indx);
2418 goto stop_flogi_current_fcf;
2422 stop_flogi_current_fcf:
2423 lpfc_can_disctmo(vport);
2428 * lpfc_sli4_fcf_pri_list_del
2429 * @phba: pointer to lpfc hba data structure.
2430 * @fcf_index: the index of the fcf record to delete
2431 * This routine checks the on list flag of the fcf_index to be deleted.
2432 * If it is one the list then it is removed from the list, and the flag
2433 * is cleared. This routine grab the hbalock before removing the fcf
2434 * record from the list.
2436 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2439 struct lpfc_fcf_pri *new_fcf_pri;
2441 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2442 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2443 "3058 deleting idx x%x pri x%x flg x%x\n",
2444 fcf_index, new_fcf_pri->fcf_rec.priority,
2445 new_fcf_pri->fcf_rec.flag);
2446 spin_lock_irq(&phba->hbalock);
2447 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2448 if (phba->fcf.current_rec.priority ==
2449 new_fcf_pri->fcf_rec.priority)
2450 phba->fcf.eligible_fcf_cnt--;
2451 list_del_init(&new_fcf_pri->list);
2452 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2454 spin_unlock_irq(&phba->hbalock);
2458 * lpfc_sli4_set_fcf_flogi_fail
2459 * @phba: pointer to lpfc hba data structure.
2460 * @fcf_index: the index of the fcf record to update
2461 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2462 * flag so the round robin selection for the particular priority level
2463 * will try a different fcf record that does not have this bit set.
2464 * If the fcf record is re-read for any reason this flag is cleared brfore
2465 * adding it to the priority list.
2468 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2470 struct lpfc_fcf_pri *new_fcf_pri;
2471 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2472 spin_lock_irq(&phba->hbalock);
2473 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2474 spin_unlock_irq(&phba->hbalock);
2478 * lpfc_sli4_fcf_pri_list_add
2479 * @phba: pointer to lpfc hba data structure.
2480 * @fcf_index: the index of the fcf record to add
2481 * @new_fcf_record: pointer to a new FCF record.
2482 * This routine checks the priority of the fcf_index to be added.
2483 * If it is a lower priority than the current head of the fcf_pri list
2484 * then it is added to the list in the right order.
2485 * If it is the same priority as the current head of the list then it
2486 * is added to the head of the list and its bit in the rr_bmask is set.
2487 * If the fcf_index to be added is of a higher priority than the current
2488 * head of the list then the rr_bmask is cleared, its bit is set in the
2489 * rr_bmask and it is added to the head of the list.
2491 * 0=success 1=failure
2493 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2495 struct fcf_record *new_fcf_record)
2497 uint16_t current_fcf_pri;
2498 uint16_t last_index;
2499 struct lpfc_fcf_pri *fcf_pri;
2500 struct lpfc_fcf_pri *next_fcf_pri;
2501 struct lpfc_fcf_pri *new_fcf_pri;
2504 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2505 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2506 "3059 adding idx x%x pri x%x flg x%x\n",
2507 fcf_index, new_fcf_record->fip_priority,
2508 new_fcf_pri->fcf_rec.flag);
2509 spin_lock_irq(&phba->hbalock);
2510 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2511 list_del_init(&new_fcf_pri->list);
2512 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2513 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2514 if (list_empty(&phba->fcf.fcf_pri_list)) {
2515 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2516 ret = lpfc_sli4_fcf_rr_index_set(phba,
2517 new_fcf_pri->fcf_rec.fcf_index);
2521 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2522 LPFC_SLI4_FCF_TBL_INDX_MAX);
2523 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2524 ret = 0; /* Empty rr list */
2527 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2528 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2529 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2530 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2531 memset(phba->fcf.fcf_rr_bmask, 0,
2532 sizeof(*phba->fcf.fcf_rr_bmask));
2533 /* fcfs_at_this_priority_level = 1; */
2534 phba->fcf.eligible_fcf_cnt = 1;
2536 /* fcfs_at_this_priority_level++; */
2537 phba->fcf.eligible_fcf_cnt++;
2538 ret = lpfc_sli4_fcf_rr_index_set(phba,
2539 new_fcf_pri->fcf_rec.fcf_index);
2543 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2544 &phba->fcf.fcf_pri_list, list) {
2545 if (new_fcf_pri->fcf_rec.priority <=
2546 fcf_pri->fcf_rec.priority) {
2547 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2548 list_add(&new_fcf_pri->list,
2549 &phba->fcf.fcf_pri_list);
2551 list_add(&new_fcf_pri->list,
2552 &((struct lpfc_fcf_pri *)
2553 fcf_pri->list.prev)->list);
2556 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2557 || new_fcf_pri->fcf_rec.priority <
2558 next_fcf_pri->fcf_rec.priority) {
2559 list_add(&new_fcf_pri->list, &fcf_pri->list);
2563 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2569 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2570 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2571 spin_unlock_irq(&phba->hbalock);
2576 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2577 * @phba: pointer to lpfc hba data structure.
2578 * @mboxq: pointer to mailbox object.
2580 * This function iterates through all the fcf records available in
2581 * HBA and chooses the optimal FCF record for discovery. After finding
2582 * the FCF for discovery it registers the FCF record and kicks start
2584 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2585 * use an FCF record which matches fabric name and mac address of the
2586 * currently used FCF record.
2587 * If the driver supports only one FCF, it will try to use the FCF record
2588 * used by BOOT_BIOS.
2591 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2593 struct fcf_record *new_fcf_record;
2594 uint32_t boot_flag, addr_mode;
2595 uint16_t fcf_index, next_fcf_index;
2596 struct lpfc_fcf_rec *fcf_rec = NULL;
2597 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2598 bool select_new_fcf;
2601 /* If there is pending FCoE event restart FCF table scan */
2602 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2603 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2607 /* Parse the FCF record from the non-embedded mailbox command */
2608 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2610 if (!new_fcf_record) {
2611 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2612 "2765 Mailbox command READ_FCF_RECORD "
2613 "failed to retrieve a FCF record.\n");
2614 /* Let next new FCF event trigger fast failover */
2615 spin_lock_irq(&phba->hbalock);
2616 phba->hba_flag &= ~FCF_TS_INPROG;
2617 spin_unlock_irq(&phba->hbalock);
2618 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2622 /* Check the FCF record against the connection list */
2623 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2624 &addr_mode, &vlan_id);
2626 /* Log the FCF record information if turned on */
2627 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2631 * If the fcf record does not match with connect list entries
2632 * read the next entry; otherwise, this is an eligible FCF
2633 * record for roundrobin FCF failover.
2636 lpfc_sli4_fcf_pri_list_del(phba,
2637 bf_get(lpfc_fcf_record_fcf_index,
2639 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2640 "2781 FCF (x%x) failed connection "
2641 "list check: (x%x/x%x/%x)\n",
2642 bf_get(lpfc_fcf_record_fcf_index,
2644 bf_get(lpfc_fcf_record_fcf_avail,
2646 bf_get(lpfc_fcf_record_fcf_valid,
2648 bf_get(lpfc_fcf_record_fcf_sol,
2650 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2651 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2652 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2653 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2654 phba->fcf.current_rec.fcf_indx) {
2655 lpfc_printf_log(phba, KERN_ERR,
2657 "2862 FCF (x%x) matches property "
2658 "of in-use FCF (x%x)\n",
2659 bf_get(lpfc_fcf_record_fcf_index,
2661 phba->fcf.current_rec.fcf_indx);
2665 * In case the current in-use FCF record becomes
2666 * invalid/unavailable during FCF discovery that
2667 * was not triggered by fast FCF failover process,
2668 * treat it as fast FCF failover.
2670 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2671 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2672 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2673 "2835 Invalid in-use FCF "
2674 "(x%x), enter FCF failover "
2676 phba->fcf.current_rec.fcf_indx);
2677 spin_lock_irq(&phba->hbalock);
2678 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2679 spin_unlock_irq(&phba->hbalock);
2680 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2681 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2682 LPFC_FCOE_FCF_GET_FIRST);
2688 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2689 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2696 * If this is not the first FCF discovery of the HBA, use last
2697 * FCF record for the discovery. The condition that a rescan
2698 * matches the in-use FCF record: fabric name, switch name, mac
2699 * address, and vlan_id.
2701 spin_lock_irq(&phba->hbalock);
2702 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2703 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2704 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2705 new_fcf_record, vlan_id)) {
2706 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2707 phba->fcf.current_rec.fcf_indx) {
2708 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2709 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2710 /* Stop FCF redisc wait timer */
2711 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2713 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2714 /* Fast failover, mark completed */
2715 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2716 spin_unlock_irq(&phba->hbalock);
2717 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2718 "2836 New FCF matches in-use "
2719 "FCF (x%x), port_state:x%x, "
2721 phba->fcf.current_rec.fcf_indx,
2722 phba->pport->port_state,
2723 phba->pport->fc_flag);
2726 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2727 "2863 New FCF (x%x) matches "
2728 "property of in-use FCF (x%x)\n",
2729 bf_get(lpfc_fcf_record_fcf_index,
2731 phba->fcf.current_rec.fcf_indx);
2734 * Read next FCF record from HBA searching for the matching
2735 * with in-use record only if not during the fast failover
2736 * period. In case of fast failover period, it shall try to
2737 * determine whether the FCF record just read should be the
2740 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2741 spin_unlock_irq(&phba->hbalock);
2746 * Update on failover FCF record only if it's in FCF fast-failover
2747 * period; otherwise, update on current FCF record.
2749 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2750 fcf_rec = &phba->fcf.failover_rec;
2752 fcf_rec = &phba->fcf.current_rec;
2754 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2756 * If the driver FCF record does not have boot flag
2757 * set and new hba fcf record has boot flag set, use
2758 * the new hba fcf record.
2760 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2761 /* Choose this FCF record */
2762 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2763 "2837 Update current FCF record "
2764 "(x%x) with new FCF record (x%x)\n",
2766 bf_get(lpfc_fcf_record_fcf_index,
2768 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2769 addr_mode, vlan_id, BOOT_ENABLE);
2770 spin_unlock_irq(&phba->hbalock);
2774 * If the driver FCF record has boot flag set and the
2775 * new hba FCF record does not have boot flag, read
2776 * the next FCF record.
2778 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2779 spin_unlock_irq(&phba->hbalock);
2783 * If the new hba FCF record has lower priority value
2784 * than the driver FCF record, use the new record.
2786 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2787 /* Choose the new FCF record with lower priority */
2788 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2789 "2838 Update current FCF record "
2790 "(x%x) with new FCF record (x%x)\n",
2792 bf_get(lpfc_fcf_record_fcf_index,
2794 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2795 addr_mode, vlan_id, 0);
2796 /* Reset running random FCF selection count */
2797 phba->fcf.eligible_fcf_cnt = 1;
2798 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2799 /* Update running random FCF selection count */
2800 phba->fcf.eligible_fcf_cnt++;
2801 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2802 phba->fcf.eligible_fcf_cnt);
2803 if (select_new_fcf) {
2804 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2805 "2839 Update current FCF record "
2806 "(x%x) with new FCF record (x%x)\n",
2808 bf_get(lpfc_fcf_record_fcf_index,
2810 /* Choose the new FCF by random selection */
2811 __lpfc_update_fcf_record(phba, fcf_rec,
2813 addr_mode, vlan_id, 0);
2816 spin_unlock_irq(&phba->hbalock);
2820 * This is the first suitable FCF record, choose this record for
2821 * initial best-fit FCF.
2824 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2825 "2840 Update initial FCF candidate "
2827 bf_get(lpfc_fcf_record_fcf_index,
2829 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2830 addr_mode, vlan_id, (boot_flag ?
2832 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2833 /* Setup initial running random FCF selection count */
2834 phba->fcf.eligible_fcf_cnt = 1;
2836 spin_unlock_irq(&phba->hbalock);
2840 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2841 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2842 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2844 * Case of FCF fast failover scan
2848 * It has not found any suitable FCF record, cancel
2849 * FCF scan inprogress, and do nothing
2851 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2852 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2853 "2782 No suitable FCF found: "
2855 phba->fcoe_eventtag_at_fcf_scan,
2856 bf_get(lpfc_fcf_record_fcf_index,
2858 spin_lock_irq(&phba->hbalock);
2859 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2860 phba->hba_flag &= ~FCF_TS_INPROG;
2861 spin_unlock_irq(&phba->hbalock);
2862 /* Unregister in-use FCF and rescan */
2863 lpfc_printf_log(phba, KERN_INFO,
2865 "2864 On devloss tmo "
2866 "unreg in-use FCF and "
2867 "rescan FCF table\n");
2868 lpfc_unregister_fcf_rescan(phba);
2872 * Let next new FCF event trigger fast failover
2874 phba->hba_flag &= ~FCF_TS_INPROG;
2875 spin_unlock_irq(&phba->hbalock);
2879 * It has found a suitable FCF record that is not
2880 * the same as in-use FCF record, unregister the
2881 * in-use FCF record, replace the in-use FCF record
2882 * with the new FCF record, mark FCF fast failover
2883 * completed, and then start register the new FCF
2887 /* Unregister the current in-use FCF record */
2888 lpfc_unregister_fcf(phba);
2890 /* Replace in-use record with the new record */
2891 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2892 "2842 Replace in-use FCF (x%x) "
2893 "with failover FCF (x%x)\n",
2894 phba->fcf.current_rec.fcf_indx,
2895 phba->fcf.failover_rec.fcf_indx);
2896 memcpy(&phba->fcf.current_rec,
2897 &phba->fcf.failover_rec,
2898 sizeof(struct lpfc_fcf_rec));
2900 * Mark the fast FCF failover rediscovery completed
2901 * and the start of the first round of the roundrobin
2904 spin_lock_irq(&phba->hbalock);
2905 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2906 spin_unlock_irq(&phba->hbalock);
2907 /* Register to the new FCF record */
2908 lpfc_register_fcf(phba);
2911 * In case of transaction period to fast FCF failover,
2912 * do nothing when search to the end of the FCF table.
2914 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2915 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2918 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2919 phba->fcf.fcf_flag & FCF_IN_USE) {
2921 * In case the current in-use FCF record no
2922 * longer existed during FCF discovery that
2923 * was not triggered by fast FCF failover
2924 * process, treat it as fast FCF failover.
2926 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2927 "2841 In-use FCF record (x%x) "
2928 "not reported, entering fast "
2929 "FCF failover mode scanning.\n",
2930 phba->fcf.current_rec.fcf_indx);
2931 spin_lock_irq(&phba->hbalock);
2932 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2933 spin_unlock_irq(&phba->hbalock);
2934 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2935 LPFC_FCOE_FCF_GET_FIRST);
2938 /* Register to the new FCF record */
2939 lpfc_register_fcf(phba);
2942 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2946 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2947 lpfc_register_fcf(phba);
2953 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2954 * @phba: pointer to lpfc hba data structure.
2955 * @mboxq: pointer to mailbox object.
2957 * This is the callback function for FLOGI failure roundrobin FCF failover
2958 * read FCF record mailbox command from the eligible FCF record bmask for
2959 * performing the failover. If the FCF read back is not valid/available, it
2960 * fails through to retrying FLOGI to the currently registered FCF again.
2961 * Otherwise, if the FCF read back is valid and available, it will set the
2962 * newly read FCF record to the failover FCF record, unregister currently
2963 * registered FCF record, copy the failover FCF record to the current
2964 * FCF record, and then register the current FCF record before proceeding
2965 * to trying FLOGI on the new failover FCF.
2968 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2970 struct fcf_record *new_fcf_record;
2971 uint32_t boot_flag, addr_mode;
2972 uint16_t next_fcf_index, fcf_index;
2973 uint16_t current_fcf_index;
2974 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2977 /* If link state is not up, stop the roundrobin failover process */
2978 if (phba->link_state < LPFC_LINK_UP) {
2979 spin_lock_irq(&phba->hbalock);
2980 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2981 phba->hba_flag &= ~FCF_RR_INPROG;
2982 spin_unlock_irq(&phba->hbalock);
2986 /* Parse the FCF record from the non-embedded mailbox command */
2987 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2989 if (!new_fcf_record) {
2990 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2991 "2766 Mailbox command READ_FCF_RECORD "
2992 "failed to retrieve a FCF record. "
2993 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2994 phba->fcf.fcf_flag);
2995 lpfc_unregister_fcf_rescan(phba);
2999 /* Get the needed parameters from FCF record */
3000 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3001 &addr_mode, &vlan_id);
3003 /* Log the FCF record information if turned on */
3004 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3007 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
3009 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3010 "2848 Remove ineligible FCF (x%x) from "
3011 "from roundrobin bmask\n", fcf_index);
3012 /* Clear roundrobin bmask bit for ineligible FCF */
3013 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
3014 /* Perform next round of roundrobin FCF failover */
3015 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
3016 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
3022 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
3023 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3024 "2760 Perform FLOGI roundrobin FCF failover: "
3025 "FCF (x%x) back to FCF (x%x)\n",
3026 phba->fcf.current_rec.fcf_indx, fcf_index);
3027 /* Wait 500 ms before retrying FLOGI to current FCF */
3029 lpfc_issue_init_vfi(phba->pport);
3033 /* Upload new FCF record to the failover FCF record */
3034 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3035 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
3036 phba->fcf.failover_rec.fcf_indx, fcf_index);
3037 spin_lock_irq(&phba->hbalock);
3038 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
3039 new_fcf_record, addr_mode, vlan_id,
3040 (boot_flag ? BOOT_ENABLE : 0));
3041 spin_unlock_irq(&phba->hbalock);
3043 current_fcf_index = phba->fcf.current_rec.fcf_indx;
3045 /* Unregister the current in-use FCF record */
3046 lpfc_unregister_fcf(phba);
3048 /* Replace in-use record with the new record */
3049 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
3050 sizeof(struct lpfc_fcf_rec));
3052 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3053 "2783 Perform FLOGI roundrobin FCF failover: FCF "
3054 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
3057 lpfc_register_fcf(phba);
3059 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3063 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
3064 * @phba: pointer to lpfc hba data structure.
3065 * @mboxq: pointer to mailbox object.
3067 * This is the callback function of read FCF record mailbox command for
3068 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
3069 * failover when a new FCF event happened. If the FCF read back is
3070 * valid/available and it passes the connection list check, it updates
3071 * the bmask for the eligible FCF record for roundrobin failover.
3074 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3076 struct fcf_record *new_fcf_record;
3077 uint32_t boot_flag, addr_mode;
3078 uint16_t fcf_index, next_fcf_index;
3079 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
3082 /* If link state is not up, no need to proceed */
3083 if (phba->link_state < LPFC_LINK_UP)
3086 /* If FCF discovery period is over, no need to proceed */
3087 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
3090 /* Parse the FCF record from the non-embedded mailbox command */
3091 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
3093 if (!new_fcf_record) {
3094 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3095 "2767 Mailbox command READ_FCF_RECORD "
3096 "failed to retrieve a FCF record.\n");
3100 /* Check the connection list for eligibility */
3101 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3102 &addr_mode, &vlan_id);
3104 /* Log the FCF record information if turned on */
3105 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3111 /* Update the eligible FCF record index bmask */
3112 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
3114 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
3117 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3121 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
3122 * @phba: pointer to lpfc hba data structure.
3123 * @mboxq: pointer to mailbox data structure.
3125 * This function handles completion of init vfi mailbox command.
3128 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3130 struct lpfc_vport *vport = mboxq->vport;
3133 * VFI not supported on interface type 0, just do the flogi
3134 * Also continue if the VFI is in use - just use the same one.
3136 if (mboxq->u.mb.mbxStatus &&
3137 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3138 LPFC_SLI_INTF_IF_TYPE_0) &&
3139 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3140 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3141 "2891 Init VFI mailbox failed 0x%x\n",
3142 mboxq->u.mb.mbxStatus);
3143 mempool_free(mboxq, phba->mbox_mem_pool);
3144 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3148 lpfc_initial_flogi(vport);
3149 mempool_free(mboxq, phba->mbox_mem_pool);
3154 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
3155 * @vport: pointer to lpfc_vport data structure.
3157 * This function issue a init_vfi mailbox command to initialize the VFI and
3158 * VPI for the physical port.
3161 lpfc_issue_init_vfi(struct lpfc_vport *vport)
3163 LPFC_MBOXQ_t *mboxq;
3165 struct lpfc_hba *phba = vport->phba;
3167 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3169 lpfc_printf_vlog(vport, KERN_ERR,
3170 LOG_TRACE_EVENT, "2892 Failed to allocate "
3171 "init_vfi mailbox\n");
3174 lpfc_init_vfi(mboxq, vport);
3175 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
3176 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
3177 if (rc == MBX_NOT_FINISHED) {
3178 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3179 "2893 Failed to issue init_vfi mailbox\n");
3180 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3185 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
3186 * @phba: pointer to lpfc hba data structure.
3187 * @mboxq: pointer to mailbox data structure.
3189 * This function handles completion of init vpi mailbox command.
3192 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3194 struct lpfc_vport *vport = mboxq->vport;
3195 struct lpfc_nodelist *ndlp;
3196 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3198 if (mboxq->u.mb.mbxStatus) {
3199 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3200 "2609 Init VPI mailbox failed 0x%x\n",
3201 mboxq->u.mb.mbxStatus);
3202 mempool_free(mboxq, phba->mbox_mem_pool);
3203 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3206 spin_lock_irq(shost->host_lock);
3207 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3208 spin_unlock_irq(shost->host_lock);
3210 /* If this port is physical port or FDISC is done, do reg_vpi */
3211 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
3212 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3214 lpfc_printf_vlog(vport, KERN_ERR,
3216 "2731 Cannot find fabric "
3217 "controller node\n");
3219 lpfc_register_new_vport(phba, vport, ndlp);
3220 mempool_free(mboxq, phba->mbox_mem_pool);
3224 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3225 lpfc_initial_fdisc(vport);
3227 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
3228 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3229 "2606 No NPIV Fabric support\n");
3231 mempool_free(mboxq, phba->mbox_mem_pool);
3236 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
3237 * @vport: pointer to lpfc_vport data structure.
3239 * This function issue a init_vpi mailbox command to initialize
3240 * VPI for the vport.
3243 lpfc_issue_init_vpi(struct lpfc_vport *vport)
3245 LPFC_MBOXQ_t *mboxq;
3248 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
3249 vpi = lpfc_alloc_vpi(vport->phba);
3251 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3252 "3303 Failed to obtain vport vpi\n");
3253 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3259 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
3261 lpfc_printf_vlog(vport, KERN_ERR,
3262 LOG_TRACE_EVENT, "2607 Failed to allocate "
3263 "init_vpi mailbox\n");
3266 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
3267 mboxq->vport = vport;
3268 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
3269 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
3270 if (rc == MBX_NOT_FINISHED) {
3271 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3272 "2608 Failed to issue init_vpi mailbox\n");
3273 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3278 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
3279 * @phba: pointer to lpfc hba data structure.
3281 * This function loops through the list of vports on the @phba and issues an
3282 * FDISC if possible.
3285 lpfc_start_fdiscs(struct lpfc_hba *phba)
3287 struct lpfc_vport **vports;
3290 vports = lpfc_create_vport_work_array(phba);
3291 if (vports != NULL) {
3292 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3293 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
3295 /* There are no vpi for this vport */
3296 if (vports[i]->vpi > phba->max_vpi) {
3297 lpfc_vport_set_state(vports[i],
3301 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3302 lpfc_vport_set_state(vports[i],
3306 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
3307 lpfc_issue_init_vpi(vports[i]);
3310 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3311 lpfc_initial_fdisc(vports[i]);
3313 lpfc_vport_set_state(vports[i],
3314 FC_VPORT_NO_FABRIC_SUPP);
3315 lpfc_printf_vlog(vports[i], KERN_ERR,
3318 "Fabric support\n");
3322 lpfc_destroy_vport_work_array(phba, vports);
3326 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3328 struct lpfc_vport *vport = mboxq->vport;
3329 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3332 * VFI not supported for interface type 0, so ignore any mailbox
3333 * error (except VFI in use) and continue with the discovery.
3335 if (mboxq->u.mb.mbxStatus &&
3336 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3337 LPFC_SLI_INTF_IF_TYPE_0) &&
3338 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3339 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3340 "2018 REG_VFI mbxStatus error x%x "
3342 mboxq->u.mb.mbxStatus, vport->port_state);
3343 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3344 /* FLOGI failed, use loop map to make discovery list */
3345 lpfc_disc_list_loopmap(vport);
3346 /* Start discovery */
3347 lpfc_disc_start(vport);
3350 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3354 /* If the VFI is already registered, there is nothing else to do
3355 * Unless this was a VFI update and we are in PT2PT mode, then
3356 * we should drop through to set the port state to ready.
3358 if (vport->fc_flag & FC_VFI_REGISTERED)
3359 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3360 vport->fc_flag & FC_PT2PT))
3363 /* The VPI is implicitly registered when the VFI is registered */
3364 spin_lock_irq(shost->host_lock);
3365 vport->vpi_state |= LPFC_VPI_REGISTERED;
3366 vport->fc_flag |= FC_VFI_REGISTERED;
3367 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3368 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3369 spin_unlock_irq(shost->host_lock);
3371 /* In case SLI4 FC loopback test, we are ready */
3372 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3373 (phba->link_flag & LS_LOOPBACK_MODE)) {
3374 phba->link_state = LPFC_HBA_READY;
3378 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3379 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3380 "alpacnt:%d LinkState:%x topology:%x\n",
3381 vport->port_state, vport->fc_flag, vport->fc_myDID,
3382 vport->phba->alpa_map[0],
3383 phba->link_state, phba->fc_topology);
3385 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3387 * For private loop or for NPort pt2pt,
3388 * just start discovery and we are done.
3390 if ((vport->fc_flag & FC_PT2PT) ||
3391 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3392 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3394 /* Use loop map to make discovery list */
3395 lpfc_disc_list_loopmap(vport);
3396 /* Start discovery */
3397 if (vport->fc_flag & FC_PT2PT)
3398 vport->port_state = LPFC_VPORT_READY;
3400 lpfc_disc_start(vport);
3402 lpfc_start_fdiscs(phba);
3403 lpfc_do_scr_ns_plogi(phba, vport);
3408 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
3412 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3414 MAILBOX_t *mb = &pmb->u.mb;
3415 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3416 struct lpfc_vport *vport = pmb->vport;
3417 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3418 struct serv_parm *sp = &vport->fc_sparam;
3421 /* Check for error */
3422 if (mb->mbxStatus) {
3423 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3424 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3425 "0319 READ_SPARAM mbxStatus error x%x "
3427 mb->mbxStatus, vport->port_state);
3428 lpfc_linkdown(phba);
3432 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3433 sizeof (struct serv_parm));
3435 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3436 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3437 ed_tov = (ed_tov + 999999) / 1000000;
3439 phba->fc_edtov = ed_tov;
3440 phba->fc_ratov = (2 * ed_tov) / 1000;
3441 if (phba->fc_ratov < FF_DEF_RATOV) {
3442 /* RA_TOV should be atleast 10sec for initial flogi */
3443 phba->fc_ratov = FF_DEF_RATOV;
3446 lpfc_update_vport_wwn(vport);
3447 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3448 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3449 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3450 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3453 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3455 /* Check if sending the FLOGI is being deferred to after we get
3456 * up to date CSPs from MBX_READ_SPARAM.
3458 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3459 lpfc_initial_flogi(vport);
3460 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3465 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3466 lpfc_issue_clear_la(phba, vport);
3470 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3472 struct lpfc_vport *vport = phba->pport;
3473 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3474 struct Scsi_Host *shost;
3477 struct fcf_record *fcf_record;
3478 uint32_t fc_flags = 0;
3479 unsigned long iflags;
3481 spin_lock_irqsave(&phba->hbalock, iflags);
3482 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3484 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3485 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3486 case LPFC_LINK_SPEED_1GHZ:
3487 case LPFC_LINK_SPEED_2GHZ:
3488 case LPFC_LINK_SPEED_4GHZ:
3489 case LPFC_LINK_SPEED_8GHZ:
3490 case LPFC_LINK_SPEED_10GHZ:
3491 case LPFC_LINK_SPEED_16GHZ:
3492 case LPFC_LINK_SPEED_32GHZ:
3493 case LPFC_LINK_SPEED_64GHZ:
3494 case LPFC_LINK_SPEED_128GHZ:
3495 case LPFC_LINK_SPEED_256GHZ:
3498 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3503 if (phba->fc_topology &&
3504 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3505 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3506 "3314 Toplogy changed was 0x%x is 0x%x\n",
3508 bf_get(lpfc_mbx_read_top_topology, la));
3509 phba->fc_topology_changed = 1;
3512 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3513 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
3515 shost = lpfc_shost_from_vport(vport);
3516 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3517 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3519 /* if npiv is enabled and this adapter supports npiv log
3520 * a message that npiv is not supported in this topology
3522 if (phba->cfg_enable_npiv && phba->max_vpi)
3523 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3524 "1309 Link Up Event npiv not supported in loop "
3526 /* Get Loop Map information */
3527 if (bf_get(lpfc_mbx_read_top_il, la))
3528 fc_flags |= FC_LBIT;
3530 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3531 i = la->lilpBde64.tus.f.bdeSize;
3534 phba->alpa_map[0] = 0;
3536 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3547 numalpa = phba->alpa_map[0];
3549 while (j < numalpa) {
3550 memset(un.pamap, 0, 16);
3551 for (k = 1; j < numalpa; k++) {
3553 phba->alpa_map[j + 1];
3558 /* Link Up Event ALPA map */
3559 lpfc_printf_log(phba,
3562 "1304 Link Up Event "
3563 "ALPA map Data: x%x "
3565 un.pa.wd1, un.pa.wd2,
3566 un.pa.wd3, un.pa.wd4);
3571 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3572 if (phba->max_vpi && phba->cfg_enable_npiv &&
3573 (phba->sli_rev >= LPFC_SLI_REV3))
3574 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3576 vport->fc_myDID = phba->fc_pref_DID;
3577 fc_flags |= FC_LBIT;
3579 spin_unlock_irqrestore(&phba->hbalock, iflags);
3582 spin_lock_irqsave(shost->host_lock, iflags);
3583 vport->fc_flag |= fc_flags;
3584 spin_unlock_irqrestore(shost->host_lock, iflags);
3590 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3594 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3596 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3599 sparam_mbox->vport = vport;
3600 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3601 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3602 if (rc == MBX_NOT_FINISHED) {
3603 lpfc_mbox_rsrc_cleanup(phba, sparam_mbox, MBOX_THD_UNLOCKED);
3607 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3608 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3611 vport->port_state = LPFC_LOCAL_CFG_LINK;
3612 lpfc_config_link(phba, cfglink_mbox);
3613 cfglink_mbox->vport = vport;
3614 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3615 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3616 if (rc == MBX_NOT_FINISHED) {
3617 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3621 vport->port_state = LPFC_VPORT_UNKNOWN;
3623 * Add the driver's default FCF record at FCF index 0 now. This
3624 * is phase 1 implementation that support FCF index 0 and driver
3627 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3628 fcf_record = kzalloc(sizeof(struct fcf_record),
3630 if (unlikely(!fcf_record)) {
3631 lpfc_printf_log(phba, KERN_ERR,
3633 "2554 Could not allocate memory for "
3639 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3640 LPFC_FCOE_FCF_DEF_INDEX);
3641 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3643 lpfc_printf_log(phba, KERN_ERR,
3645 "2013 Could not manually add FCF "
3646 "record 0, status %d\n", rc);
3654 * The driver is expected to do FIP/FCF. Call the port
3655 * and get the FCF Table.
3657 spin_lock_irqsave(&phba->hbalock, iflags);
3658 if (phba->hba_flag & FCF_TS_INPROG) {
3659 spin_unlock_irqrestore(&phba->hbalock, iflags);
3662 /* This is the initial FCF discovery scan */
3663 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3664 spin_unlock_irqrestore(&phba->hbalock, iflags);
3665 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3666 "2778 Start FCF table scan at linkup\n");
3667 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3668 LPFC_FCOE_FCF_GET_FIRST);
3670 spin_lock_irqsave(&phba->hbalock, iflags);
3671 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3672 spin_unlock_irqrestore(&phba->hbalock, iflags);
3675 /* Reset FCF roundrobin bmask for new discovery */
3676 lpfc_sli4_clear_fcf_rr_bmask(phba);
3679 /* Prepare for LINK up registrations */
3680 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3681 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3682 init_utsname()->nodename);
3685 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3686 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3687 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3688 vport->port_state, sparam_mbox, cfglink_mbox);
3689 lpfc_issue_clear_la(phba, vport);
3694 lpfc_enable_la(struct lpfc_hba *phba)
3697 struct lpfc_sli *psli = &phba->sli;
3698 spin_lock_irq(&phba->hbalock);
3699 psli->sli_flag |= LPFC_PROCESS_LA;
3700 if (phba->sli_rev <= LPFC_SLI_REV3) {
3701 control = readl(phba->HCregaddr);
3702 control |= HC_LAINT_ENA;
3703 writel(control, phba->HCregaddr);
3704 readl(phba->HCregaddr); /* flush */
3706 spin_unlock_irq(&phba->hbalock);
3710 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3712 lpfc_linkdown(phba);
3713 lpfc_enable_la(phba);
3714 lpfc_unregister_unused_fcf(phba);
3715 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3720 * This routine handles processing a READ_TOPOLOGY mailbox
3721 * command upon completion. It is setup in the LPFC_MBOXQ
3722 * as the completion routine when the command is
3723 * handed off to the SLI layer. SLI4 only.
3726 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3728 struct lpfc_vport *vport = pmb->vport;
3729 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3730 struct lpfc_mbx_read_top *la;
3731 struct lpfc_sli_ring *pring;
3732 MAILBOX_t *mb = &pmb->u.mb;
3733 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3735 unsigned long iflags;
3737 /* Unblock ELS traffic */
3738 pring = lpfc_phba_elsring(phba);
3740 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3742 /* Check for error */
3743 if (mb->mbxStatus) {
3744 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3745 "1307 READ_LA mbox error x%x state x%x\n",
3746 mb->mbxStatus, vport->port_state);
3747 lpfc_mbx_issue_link_down(phba);
3748 phba->link_state = LPFC_HBA_ERROR;
3749 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3752 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3753 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3755 memcpy(&phba->alpa_map[0], mp->virt, 128);
3757 spin_lock_irqsave(shost->host_lock, iflags);
3758 if (bf_get(lpfc_mbx_read_top_pb, la))
3759 vport->fc_flag |= FC_BYPASSED_MODE;
3761 vport->fc_flag &= ~FC_BYPASSED_MODE;
3762 spin_unlock_irqrestore(shost->host_lock, iflags);
3764 if (phba->fc_eventTag <= la->eventTag) {
3765 phba->fc_stat.LinkMultiEvent++;
3766 if (attn_type == LPFC_ATT_LINK_UP)
3767 if (phba->fc_eventTag != 0)
3768 lpfc_linkdown(phba);
3771 phba->fc_eventTag = la->eventTag;
3772 phba->link_events++;
3773 if (attn_type == LPFC_ATT_LINK_UP) {
3774 phba->fc_stat.LinkUp++;
3775 if (phba->link_flag & LS_LOOPBACK_MODE) {
3776 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3777 "1306 Link Up Event in loop back mode "
3778 "x%x received Data: x%x x%x x%x x%x\n",
3779 la->eventTag, phba->fc_eventTag,
3780 bf_get(lpfc_mbx_read_top_alpa_granted,
3782 bf_get(lpfc_mbx_read_top_link_spd, la),
3785 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3786 "1303 Link Up Event x%x received "
3787 "Data: x%x x%x x%x x%x x%x\n",
3788 la->eventTag, phba->fc_eventTag,
3789 bf_get(lpfc_mbx_read_top_alpa_granted,
3791 bf_get(lpfc_mbx_read_top_link_spd, la),
3793 bf_get(lpfc_mbx_read_top_fa, la));
3795 lpfc_mbx_process_link_up(phba, la);
3797 if (phba->cmf_active_mode != LPFC_CFG_OFF)
3798 lpfc_cmf_signal_init(phba);
3800 if (phba->lmt & LMT_64Gb)
3801 lpfc_read_lds_params(phba);
3803 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3804 attn_type == LPFC_ATT_UNEXP_WWPN) {
3805 phba->fc_stat.LinkDown++;
3806 if (phba->link_flag & LS_LOOPBACK_MODE)
3807 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3808 "1308 Link Down Event in loop back mode "
3810 "Data: x%x x%x x%x\n",
3811 la->eventTag, phba->fc_eventTag,
3812 phba->pport->port_state, vport->fc_flag);
3813 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3814 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3815 "1313 Link Down Unexpected FA WWPN Event x%x "
3816 "received Data: x%x x%x x%x x%x\n",
3817 la->eventTag, phba->fc_eventTag,
3818 phba->pport->port_state, vport->fc_flag,
3819 bf_get(lpfc_mbx_read_top_fa, la));
3821 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3822 "1305 Link Down Event x%x received "
3823 "Data: x%x x%x x%x x%x\n",
3824 la->eventTag, phba->fc_eventTag,
3825 phba->pport->port_state, vport->fc_flag,
3826 bf_get(lpfc_mbx_read_top_fa, la));
3827 lpfc_mbx_issue_link_down(phba);
3830 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3831 bf_get(lpfc_mbx_read_top_fa, la))
3832 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3834 bf_get(lpfc_mbx_read_top_fa, la));
3836 lpfc_mbx_cmpl_read_topology_free_mbuf:
3837 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3841 * This routine handles processing a REG_LOGIN mailbox
3842 * command upon completion. It is setup in the LPFC_MBOXQ
3843 * as the completion routine when the command is
3844 * handed off to the SLI layer.
3847 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3849 struct lpfc_vport *vport = pmb->vport;
3850 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3851 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3853 /* The driver calls the state machine with the pmb pointer
3854 * but wants to make sure a stale ctx_buf isn't acted on.
3855 * The ctx_buf is restored later and cleaned up.
3857 pmb->ctx_buf = NULL;
3858 pmb->ctx_ndlp = NULL;
3860 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
3861 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3862 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3863 kref_read(&ndlp->kref),
3865 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3866 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3868 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3869 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3870 /* We rcvd a rscn after issuing this
3871 * mbox reg login, we may have cycled
3872 * back through the state and be
3873 * back at reg login state so this
3874 * mbox needs to be ignored becase
3875 * there is another reg login in
3878 spin_lock_irq(&ndlp->lock);
3879 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3880 spin_unlock_irq(&ndlp->lock);
3883 * We cannot leave the RPI registered because
3884 * if we go thru discovery again for this ndlp
3885 * a subsequent REG_RPI will fail.
3887 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3888 lpfc_unreg_rpi(vport, ndlp);
3891 /* Call state machine */
3892 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3894 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3896 /* decrement the node reference count held for this callback
3905 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3907 MAILBOX_t *mb = &pmb->u.mb;
3908 struct lpfc_vport *vport = pmb->vport;
3909 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3911 switch (mb->mbxStatus) {
3914 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3915 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3918 /* If VPI is busy, reset the HBA */
3920 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3921 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3922 vport->vpi, mb->mbxStatus);
3923 if (!(phba->pport->load_flag & FC_UNLOADING))
3924 lpfc_workq_post_event(phba, NULL, NULL,
3925 LPFC_EVT_RESET_HBA);
3927 spin_lock_irq(shost->host_lock);
3928 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3929 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3930 spin_unlock_irq(shost->host_lock);
3931 mempool_free(pmb, phba->mbox_mem_pool);
3932 lpfc_cleanup_vports_rrqs(vport, NULL);
3934 * This shost reference might have been taken at the beginning of
3935 * lpfc_vport_delete()
3937 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3938 scsi_host_put(shost);
3942 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3944 struct lpfc_hba *phba = vport->phba;
3948 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3952 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3953 mbox->vport = vport;
3954 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3955 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3956 if (rc == MBX_NOT_FINISHED) {
3957 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3958 "1800 Could not issue unreg_vpi\n");
3959 mempool_free(mbox, phba->mbox_mem_pool);
3966 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3968 struct lpfc_vport *vport = pmb->vport;
3969 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3970 MAILBOX_t *mb = &pmb->u.mb;
3972 switch (mb->mbxStatus) {
3976 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3977 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3979 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3980 spin_lock_irq(shost->host_lock);
3981 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3982 spin_unlock_irq(shost->host_lock);
3983 vport->fc_myDID = 0;
3985 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3986 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3987 if (phba->nvmet_support)
3988 lpfc_nvmet_update_targetport(phba);
3990 lpfc_nvme_update_localport(vport);
3995 spin_lock_irq(shost->host_lock);
3996 vport->vpi_state |= LPFC_VPI_REGISTERED;
3997 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3998 spin_unlock_irq(shost->host_lock);
3999 vport->num_disc_nodes = 0;
4000 /* go thru NPR list and issue ELS PLOGIs */
4001 if (vport->fc_npr_cnt)
4002 lpfc_els_disc_plogi(vport);
4004 if (!vport->num_disc_nodes) {
4005 spin_lock_irq(shost->host_lock);
4006 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4007 spin_unlock_irq(shost->host_lock);
4008 lpfc_can_disctmo(vport);
4010 vport->port_state = LPFC_VPORT_READY;
4013 mempool_free(pmb, phba->mbox_mem_pool);
4018 * lpfc_create_static_vport - Read HBA config region to create static vports.
4019 * @phba: pointer to lpfc hba data structure.
4021 * This routine issue a DUMP mailbox command for config region 22 to get
4022 * the list of static vports to be created. The function create vports
4023 * based on the information returned from the HBA.
4026 lpfc_create_static_vport(struct lpfc_hba *phba)
4028 LPFC_MBOXQ_t *pmb = NULL;
4030 struct static_vport_info *vport_info;
4031 int mbx_wait_rc = 0, i;
4032 struct fc_vport_identifiers vport_id;
4033 struct fc_vport *new_fc_vport;
4034 struct Scsi_Host *shost;
4035 struct lpfc_vport *vport;
4036 uint16_t offset = 0;
4037 uint8_t *vport_buff;
4038 struct lpfc_dmabuf *mp;
4039 uint32_t byte_count = 0;
4041 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4043 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4044 "0542 lpfc_create_static_vport failed to"
4045 " allocate mailbox memory\n");
4048 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
4051 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
4053 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4054 "0543 lpfc_create_static_vport failed to"
4055 " allocate vport_info\n");
4056 mempool_free(pmb, phba->mbox_mem_pool);
4060 vport_buff = (uint8_t *) vport_info;
4062 /* While loop iteration forces a free dma buffer from
4063 * the previous loop because the mbox is reused and
4064 * the dump routine is a single-use construct.
4067 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4068 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4070 pmb->ctx_buf = NULL;
4072 if (lpfc_dump_static_vport(phba, pmb, offset))
4075 pmb->vport = phba->pport;
4076 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
4079 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
4080 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4081 "0544 lpfc_create_static_vport failed to"
4082 " issue dump mailbox command ret 0x%x "
4084 mbx_wait_rc, mb->mbxStatus);
4088 if (phba->sli_rev == LPFC_SLI_REV4) {
4089 byte_count = pmb->u.mqe.un.mb_words[5];
4090 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4091 if (byte_count > sizeof(struct static_vport_info) -
4093 byte_count = sizeof(struct static_vport_info)
4095 memcpy(vport_buff + offset, mp->virt, byte_count);
4096 offset += byte_count;
4098 if (mb->un.varDmp.word_cnt >
4099 sizeof(struct static_vport_info) - offset)
4100 mb->un.varDmp.word_cnt =
4101 sizeof(struct static_vport_info)
4103 byte_count = mb->un.varDmp.word_cnt;
4104 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
4105 vport_buff + offset,
4108 offset += byte_count;
4111 } while (byte_count &&
4112 offset < sizeof(struct static_vport_info));
4115 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
4116 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
4117 != VPORT_INFO_REV)) {
4118 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4119 "0545 lpfc_create_static_vport bad"
4120 " information header 0x%x 0x%x\n",
4121 le32_to_cpu(vport_info->signature),
4122 le32_to_cpu(vport_info->rev) &
4123 VPORT_INFO_REV_MASK);
4128 shost = lpfc_shost_from_vport(phba->pport);
4130 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
4131 memset(&vport_id, 0, sizeof(vport_id));
4132 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
4133 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
4134 if (!vport_id.port_name || !vport_id.node_name)
4137 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
4138 vport_id.vport_type = FC_PORTTYPE_NPIV;
4139 vport_id.disable = false;
4140 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
4142 if (!new_fc_vport) {
4143 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4144 "0546 lpfc_create_static_vport failed to"
4149 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
4150 vport->vport_flag |= STATIC_VPORT;
4155 if (mbx_wait_rc != MBX_TIMEOUT)
4156 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4160 * This routine handles processing a Fabric REG_LOGIN mailbox
4161 * command upon completion. It is setup in the LPFC_MBOXQ
4162 * as the completion routine when the command is
4163 * handed off to the SLI layer.
4166 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4168 struct lpfc_vport *vport = pmb->vport;
4169 MAILBOX_t *mb = &pmb->u.mb;
4170 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4171 struct Scsi_Host *shost;
4173 pmb->ctx_ndlp = NULL;
4175 if (mb->mbxStatus) {
4176 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4177 "0258 Register Fabric login error: 0x%x\n",
4179 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4180 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4181 /* FLOGI failed, use loop map to make discovery list */
4182 lpfc_disc_list_loopmap(vport);
4184 /* Start discovery */
4185 lpfc_disc_start(vport);
4186 /* Decrement the reference count to ndlp after the
4187 * reference to the ndlp are done.
4193 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4194 /* Decrement the reference count to ndlp after the reference
4195 * to the ndlp are done.
4201 if (phba->sli_rev < LPFC_SLI_REV4)
4202 ndlp->nlp_rpi = mb->un.varWords[0];
4203 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4204 ndlp->nlp_type |= NLP_FABRIC;
4205 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4207 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
4208 /* when physical port receive logo donot start
4209 * vport discovery */
4210 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
4211 lpfc_start_fdiscs(phba);
4213 shost = lpfc_shost_from_vport(vport);
4214 spin_lock_irq(shost->host_lock);
4215 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
4216 spin_unlock_irq(shost->host_lock);
4218 lpfc_do_scr_ns_plogi(phba, vport);
4221 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4223 /* Drop the reference count from the mbox at the end after
4224 * all the current reference to the ndlp have been done.
4231 * This routine will issue a GID_FT for each FC4 Type supported
4232 * by the driver. ALL GID_FTs must complete before discovery is started.
4235 lpfc_issue_gidft(struct lpfc_vport *vport)
4237 /* Good status, issue CT Request to NameServer */
4238 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4239 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
4240 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
4241 /* Cannot issue NameServer FCP Query, so finish up
4244 lpfc_printf_vlog(vport, KERN_ERR,
4246 "0604 %s FC TYPE %x %s\n",
4247 "Failed to issue GID_FT to ",
4249 "Finishing discovery.");
4255 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4256 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4257 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4258 /* Cannot issue NameServer NVME Query, so finish up
4261 lpfc_printf_vlog(vport, KERN_ERR,
4263 "0605 %s FC_TYPE %x %s %d\n",
4264 "Failed to issue GID_FT to ",
4266 "Finishing discovery: gidftinp ",
4268 if (vport->gidft_inp == 0)
4273 return vport->gidft_inp;
4277 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4278 * @vport: The virtual port for which this call is being executed.
4280 * This routine will issue a GID_PT to get a list of all N_Ports
4283 * 0 - Failure to issue a GID_PT
4287 lpfc_issue_gidpt(struct lpfc_vport *vport)
4289 /* Good status, issue CT Request to NameServer */
4290 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4291 /* Cannot issue NameServer FCP Query, so finish up
4294 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4295 "0606 %s Port TYPE %x %s\n",
4296 "Failed to issue GID_PT to ",
4298 "Finishing discovery.");
4306 * This routine handles processing a NameServer REG_LOGIN mailbox
4307 * command upon completion. It is setup in the LPFC_MBOXQ
4308 * as the completion routine when the command is
4309 * handed off to the SLI layer.
4312 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4314 MAILBOX_t *mb = &pmb->u.mb;
4315 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4316 struct lpfc_vport *vport = pmb->vport;
4319 pmb->ctx_ndlp = NULL;
4320 vport->gidft_inp = 0;
4322 if (mb->mbxStatus) {
4323 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4324 "0260 Register NameServer error: 0x%x\n",
4328 /* decrement the node reference count held for this
4329 * callback function.
4332 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4334 /* If the node is not registered with the scsi or nvme
4335 * transport, remove the fabric node. The failed reg_login
4338 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4339 spin_lock_irq(&ndlp->lock);
4340 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4341 spin_unlock_irq(&ndlp->lock);
4342 lpfc_nlp_not_used(ndlp);
4345 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4347 * RegLogin failed, use loop map to make discovery
4350 lpfc_disc_list_loopmap(vport);
4352 /* Start discovery */
4353 lpfc_disc_start(vport);
4356 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4360 if (phba->sli_rev < LPFC_SLI_REV4)
4361 ndlp->nlp_rpi = mb->un.varWords[0];
4362 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4363 ndlp->nlp_type |= NLP_FABRIC;
4364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4365 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4366 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4367 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4368 kref_read(&ndlp->kref),
4371 if (vport->port_state < LPFC_VPORT_READY) {
4372 /* Link up discovery requires Fabric registration. */
4373 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4374 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4375 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4376 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4378 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4379 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4380 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4382 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4383 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4384 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4387 /* Issue SCR just before NameServer GID_FT Query */
4388 lpfc_issue_els_scr(vport, 0);
4390 /* Link was bounced or a Fabric LOGO occurred. Start EDC
4391 * with initial FW values provided the congestion mode is
4392 * not off. Note that signals may or may not be supported
4393 * by the adapter but FPIN is provided by default for 1
4394 * or both missing signals support.
4396 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
4397 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
4398 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
4399 rc = lpfc_issue_els_edc(vport, 0);
4400 lpfc_printf_log(phba, KERN_INFO,
4401 LOG_INIT | LOG_ELS | LOG_DISCOVERY,
4402 "4220 Issue EDC status x%x Data x%x\n",
4403 rc, phba->cgn_init_reg_signal);
4404 } else if (phba->lmt & LMT_64Gb) {
4405 /* may send link fault capability descriptor */
4406 lpfc_issue_els_edc(vport, 0);
4408 lpfc_issue_els_rdf(vport, 0);
4412 vport->fc_ns_retry = 0;
4413 if (lpfc_issue_gidft(vport) == 0)
4417 * At this point in time we may need to wait for multiple
4418 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4420 * decrement the node reference count held for this
4421 * callback function.
4424 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4429 * This routine handles processing a Fabric Controller REG_LOGIN mailbox
4430 * command upon completion. It is setup in the LPFC_MBOXQ
4431 * as the completion routine when the command is handed off to the SLI layer.
4434 lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4436 struct lpfc_vport *vport = pmb->vport;
4437 MAILBOX_t *mb = &pmb->u.mb;
4438 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4440 pmb->ctx_ndlp = NULL;
4441 if (mb->mbxStatus) {
4442 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4443 "0933 %s: Register FC login error: 0x%x\n",
4444 __func__, mb->mbxStatus);
4448 lpfc_check_nlp_post_devloss(vport, ndlp);
4450 if (phba->sli_rev < LPFC_SLI_REV4)
4451 ndlp->nlp_rpi = mb->un.varWords[0];
4453 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4454 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4455 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4458 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4459 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4460 ndlp->nlp_type |= NLP_FABRIC;
4461 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4464 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4466 /* Drop the reference count from the mbox at the end after
4467 * all the current reference to the ndlp have been done.
4473 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4475 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4476 struct fc_rport *rport;
4477 struct lpfc_rport_data *rdata;
4478 struct fc_rport_identifiers rport_ids;
4479 struct lpfc_hba *phba = vport->phba;
4480 unsigned long flags;
4482 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4485 /* Remote port has reappeared. Re-register w/ FC transport */
4486 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4487 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4488 rport_ids.port_id = ndlp->nlp_DID;
4489 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4492 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4493 "rport add: did:x%x flg:x%x type x%x",
4494 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4496 /* Don't add the remote port if unloading. */
4497 if (vport->load_flag & FC_UNLOADING)
4501 * Disassociate any older association between this ndlp and rport
4504 rdata = ndlp->rport->dd_data;
4505 rdata->pnode = NULL;
4508 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4510 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4511 "Warning: fc_remote_port_add failed\n");
4515 /* Successful port add. Complete initializing node data */
4516 rport->maxframe_size = ndlp->nlp_maxframe;
4517 rport->supported_classes = ndlp->nlp_class_sup;
4518 rdata = rport->dd_data;
4519 rdata->pnode = lpfc_nlp_get(ndlp);
4520 if (!rdata->pnode) {
4521 dev_warn(&phba->pcidev->dev,
4522 "Warning - node ref failed. Unreg rport\n");
4523 fc_remote_port_delete(rport);
4528 spin_lock_irqsave(&ndlp->lock, flags);
4529 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4530 spin_unlock_irqrestore(&ndlp->lock, flags);
4532 if (ndlp->nlp_type & NLP_FCP_TARGET)
4533 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4534 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4535 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4536 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4537 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4538 if (ndlp->nlp_type & NLP_NVME_TARGET)
4539 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4540 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4541 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4543 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4544 fc_remote_port_rolechg(rport, rport_ids.roles);
4546 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4547 "3183 %s rport x%px DID x%x, role x%x refcnt %d\n",
4548 __func__, rport, rport->port_id, rport->roles,
4549 kref_read(&ndlp->kref));
4551 if ((rport->scsi_target_id != -1) &&
4552 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4553 ndlp->nlp_sid = rport->scsi_target_id;
4560 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4562 struct fc_rport *rport = ndlp->rport;
4563 struct lpfc_vport *vport = ndlp->vport;
4565 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4568 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4569 "rport delete: did:x%x flg:x%x type x%x",
4570 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4572 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4573 "3184 rport unregister x%06x, rport x%px "
4574 "xptflg x%x refcnt %d\n",
4575 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags,
4576 kref_read(&ndlp->kref));
4578 fc_remote_port_delete(rport);
4583 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4585 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4586 unsigned long iflags;
4588 spin_lock_irqsave(shost->host_lock, iflags);
4590 case NLP_STE_UNUSED_NODE:
4591 vport->fc_unused_cnt += count;
4593 case NLP_STE_PLOGI_ISSUE:
4594 vport->fc_plogi_cnt += count;
4596 case NLP_STE_ADISC_ISSUE:
4597 vport->fc_adisc_cnt += count;
4599 case NLP_STE_REG_LOGIN_ISSUE:
4600 vport->fc_reglogin_cnt += count;
4602 case NLP_STE_PRLI_ISSUE:
4603 vport->fc_prli_cnt += count;
4605 case NLP_STE_UNMAPPED_NODE:
4606 vport->fc_unmap_cnt += count;
4608 case NLP_STE_MAPPED_NODE:
4609 vport->fc_map_cnt += count;
4611 case NLP_STE_NPR_NODE:
4612 if (vport->fc_npr_cnt == 0 && count == -1)
4613 vport->fc_npr_cnt = 0;
4615 vport->fc_npr_cnt += count;
4618 spin_unlock_irqrestore(shost->host_lock, iflags);
4621 /* Register a node with backend if not already done */
4623 lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4625 unsigned long iflags;
4627 lpfc_check_nlp_post_devloss(vport, ndlp);
4629 spin_lock_irqsave(&ndlp->lock, iflags);
4630 if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) {
4631 /* Already registered with backend, trigger rescan */
4632 spin_unlock_irqrestore(&ndlp->lock, iflags);
4634 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD &&
4635 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) {
4636 lpfc_nvme_rescan_port(vport, ndlp);
4641 ndlp->fc4_xpt_flags |= NLP_XPT_REGD;
4642 spin_unlock_irqrestore(&ndlp->lock, iflags);
4644 if (lpfc_valid_xpt_node(ndlp)) {
4645 vport->phba->nport_event_cnt++;
4647 * Tell the fc transport about the port, if we haven't
4648 * already. If we have, and it's a scsi entity, be
4650 lpfc_register_remote_port(vport, ndlp);
4653 /* We are done if we do not have any NVME remote node */
4654 if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME))
4657 /* Notify the NVME transport of this new rport. */
4658 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4659 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4660 if (vport->phba->nvmet_support == 0) {
4661 /* Register this rport with the transport.
4662 * Only NVME Target Rports are registered with
4665 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4666 vport->phba->nport_event_cnt++;
4667 lpfc_nvme_register_port(vport, ndlp);
4670 /* Just take an NDLP ref count since the
4671 * target does not register rports.
4678 /* Unregister a node with backend if not already done */
4680 lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4682 unsigned long iflags;
4684 spin_lock_irqsave(&ndlp->lock, iflags);
4685 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) {
4686 spin_unlock_irqrestore(&ndlp->lock, iflags);
4687 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4688 "0999 %s Not regd: ndlp x%px rport x%px DID "
4689 "x%x FLG x%x XPT x%x\n",
4690 __func__, ndlp, ndlp->rport, ndlp->nlp_DID,
4691 ndlp->nlp_flag, ndlp->fc4_xpt_flags);
4695 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
4696 spin_unlock_irqrestore(&ndlp->lock, iflags);
4699 ndlp->fc4_xpt_flags & SCSI_XPT_REGD) {
4700 vport->phba->nport_event_cnt++;
4701 lpfc_unregister_remote_port(ndlp);
4702 } else if (!ndlp->rport) {
4703 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4704 "1999 %s NDLP in devloss x%px DID x%x FLG x%x"
4705 " XPT x%x refcnt %d\n",
4706 __func__, ndlp, ndlp->nlp_DID, ndlp->nlp_flag,
4707 ndlp->fc4_xpt_flags,
4708 kref_read(&ndlp->kref));
4711 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) {
4712 vport->phba->nport_event_cnt++;
4713 if (vport->phba->nvmet_support == 0) {
4714 /* Start devloss if target. */
4715 if (ndlp->nlp_type & NLP_NVME_TARGET)
4716 lpfc_nvme_unregister_port(vport, ndlp);
4718 /* NVMET has no upcall. */
4726 * Adisc state change handling
4729 lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4732 switch (new_state) {
4734 * Any state to ADISC_ISSUE
4735 * Do nothing, adisc cmpl handling will trigger state changes
4737 case NLP_STE_ADISC_ISSUE:
4741 * ADISC_ISSUE to mapped states
4742 * Trigger a registration with backend, it will be nop if
4743 * already registered
4745 case NLP_STE_UNMAPPED_NODE:
4746 ndlp->nlp_type |= NLP_FC_NODE;
4748 case NLP_STE_MAPPED_NODE:
4749 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4750 lpfc_nlp_reg_node(vport, ndlp);
4754 * ADISC_ISSUE to non-mapped states
4755 * We are moving from ADISC_ISSUE to a non-mapped state because
4756 * ADISC failed, we would have skipped unregistering with
4757 * backend, attempt it now
4759 case NLP_STE_NPR_NODE:
4760 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4763 lpfc_nlp_unreg_node(vport, ndlp);
4770 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4771 int old_state, int new_state)
4773 /* Trap ADISC changes here */
4774 if (new_state == NLP_STE_ADISC_ISSUE ||
4775 old_state == NLP_STE_ADISC_ISSUE) {
4776 lpfc_handle_adisc_state(vport, ndlp, new_state);
4780 if (new_state == NLP_STE_UNMAPPED_NODE) {
4781 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4782 ndlp->nlp_type |= NLP_FC_NODE;
4784 if (new_state == NLP_STE_MAPPED_NODE)
4785 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4786 if (new_state == NLP_STE_NPR_NODE)
4787 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4789 /* Reg/Unreg for FCP and NVME Transport interface */
4790 if ((old_state == NLP_STE_MAPPED_NODE ||
4791 old_state == NLP_STE_UNMAPPED_NODE)) {
4792 /* For nodes marked for ADISC, Handle unreg in ADISC cmpl
4793 * if linkup. In linkdown do unreg_node
4795 if (!(ndlp->nlp_flag & NLP_NPR_ADISC) ||
4796 !lpfc_is_link_up(vport->phba))
4797 lpfc_nlp_unreg_node(vport, ndlp);
4800 if (new_state == NLP_STE_MAPPED_NODE ||
4801 new_state == NLP_STE_UNMAPPED_NODE)
4802 lpfc_nlp_reg_node(vport, ndlp);
4805 * If the node just added to Mapped list was an FCP target,
4806 * but the remote port registration failed or assigned a target
4807 * id outside the presentable range - move the node to the
4810 if ((new_state == NLP_STE_MAPPED_NODE) &&
4811 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4813 ndlp->rport->scsi_target_id == -1 ||
4814 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4815 spin_lock_irq(&ndlp->lock);
4816 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4817 spin_unlock_irq(&ndlp->lock);
4818 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4823 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4825 static char *states[] = {
4826 [NLP_STE_UNUSED_NODE] = "UNUSED",
4827 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4828 [NLP_STE_ADISC_ISSUE] = "ADISC",
4829 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4830 [NLP_STE_PRLI_ISSUE] = "PRLI",
4831 [NLP_STE_LOGO_ISSUE] = "LOGO",
4832 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4833 [NLP_STE_MAPPED_NODE] = "MAPPED",
4834 [NLP_STE_NPR_NODE] = "NPR",
4837 if (state < NLP_STE_MAX_STATE && states[state])
4838 strlcpy(buffer, states[state], size);
4840 snprintf(buffer, size, "unknown (%d)", state);
4845 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4848 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4849 int old_state = ndlp->nlp_state;
4850 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
4851 char name1[16], name2[16];
4853 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4854 "0904 NPort state transition x%06x, %s -> %s\n",
4856 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4857 lpfc_nlp_state_name(name2, sizeof(name2), state));
4859 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4860 "node statechg did:x%x old:%d ste:%d",
4861 ndlp->nlp_DID, old_state, state);
4863 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4864 state != NLP_STE_UNUSED_NODE) {
4865 ndlp->nlp_flag &= ~NLP_DROPPED;
4869 if (old_state == NLP_STE_NPR_NODE &&
4870 state != NLP_STE_NPR_NODE)
4871 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4872 if (old_state == NLP_STE_UNMAPPED_NODE) {
4873 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4874 ndlp->nlp_type &= ~NLP_FC_NODE;
4877 if (list_empty(&ndlp->nlp_listp)) {
4878 spin_lock_irq(shost->host_lock);
4879 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4880 spin_unlock_irq(shost->host_lock);
4881 } else if (old_state)
4882 lpfc_nlp_counters(vport, old_state, -1);
4884 ndlp->nlp_state = state;
4885 lpfc_nlp_counters(vport, state, 1);
4886 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4890 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4892 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4894 if (list_empty(&ndlp->nlp_listp)) {
4895 spin_lock_irq(shost->host_lock);
4896 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4897 spin_unlock_irq(shost->host_lock);
4902 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4906 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4907 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4908 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4909 spin_lock_irq(shost->host_lock);
4910 list_del_init(&ndlp->nlp_listp);
4911 spin_unlock_irq(shost->host_lock);
4912 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4913 NLP_STE_UNUSED_NODE);
4917 * lpfc_initialize_node - Initialize all fields of node object
4918 * @vport: Pointer to Virtual Port object.
4919 * @ndlp: Pointer to FC node object.
4920 * @did: FC_ID of the node.
4922 * This function is always called when node object need to be initialized.
4923 * It initializes all the fields of the node object. Although the reference
4924 * to phba from @ndlp can be obtained indirectly through it's reference to
4925 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4926 * to the life-span of the @ndlp might go beyond the existence of @vport as
4927 * the final release of ndlp is determined by its reference count. And, the
4928 * operation on @ndlp needs the reference to phba.
4931 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4934 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4935 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4936 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4937 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4939 ndlp->nlp_DID = did;
4940 ndlp->vport = vport;
4941 ndlp->phba = vport->phba;
4942 ndlp->nlp_sid = NLP_NO_SID;
4943 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4944 kref_init(&ndlp->kref);
4945 atomic_set(&ndlp->cmd_pending, 0);
4946 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4947 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4951 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4954 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4955 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4956 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4957 * until ALL other outstanding threads have completed. We check
4958 * that the ndlp not already in the UNUSED state before we proceed.
4960 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4962 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4963 ndlp->nlp_flag |= NLP_DROPPED;
4964 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4965 lpfc_cleanup_vports_rrqs(vport, ndlp);
4966 lpfc_unreg_rpi(vport, ndlp);
4974 * Start / ReStart rescue timer for Discovery / RSCN handling
4977 lpfc_set_disctmo(struct lpfc_vport *vport)
4979 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4980 struct lpfc_hba *phba = vport->phba;
4983 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4984 /* For FAN, timeout should be greater than edtov */
4985 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4987 /* Normal discovery timeout should be > than ELS/CT timeout
4988 * FC spec states we need 3 * ratov for CT requests
4990 tmo = ((phba->fc_ratov * 3) + 3);
4994 if (!timer_pending(&vport->fc_disctmo)) {
4995 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4996 "set disc timer: tmo:x%x state:x%x flg:x%x",
4997 tmo, vport->port_state, vport->fc_flag);
5000 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
5001 spin_lock_irq(shost->host_lock);
5002 vport->fc_flag |= FC_DISC_TMO;
5003 spin_unlock_irq(shost->host_lock);
5005 /* Start Discovery Timer state <hba_state> */
5006 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5007 "0247 Start Discovery Timer state x%x "
5008 "Data: x%x x%lx x%x x%x\n",
5009 vport->port_state, tmo,
5010 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
5011 vport->fc_adisc_cnt);
5017 * Cancel rescue timer for Discovery / RSCN handling
5020 lpfc_can_disctmo(struct lpfc_vport *vport)
5022 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5023 unsigned long iflags;
5025 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5026 "can disc timer: state:x%x rtry:x%x flg:x%x",
5027 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5029 /* Turn off discovery timer if its running */
5030 if (vport->fc_flag & FC_DISC_TMO ||
5031 timer_pending(&vport->fc_disctmo)) {
5032 spin_lock_irqsave(shost->host_lock, iflags);
5033 vport->fc_flag &= ~FC_DISC_TMO;
5034 spin_unlock_irqrestore(shost->host_lock, iflags);
5035 del_timer_sync(&vport->fc_disctmo);
5036 spin_lock_irqsave(&vport->work_port_lock, iflags);
5037 vport->work_port_events &= ~WORKER_DISC_TMO;
5038 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
5041 /* Cancel Discovery Timer state <hba_state> */
5042 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5043 "0248 Cancel Discovery Timer state x%x "
5044 "Data: x%x x%x x%x\n",
5045 vport->port_state, vport->fc_flag,
5046 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
5051 * Check specified ring for outstanding IOCB on the SLI queue
5052 * Return true if iocb matches the specified nport
5055 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
5056 struct lpfc_sli_ring *pring,
5057 struct lpfc_iocbq *iocb,
5058 struct lpfc_nodelist *ndlp)
5060 struct lpfc_vport *vport = ndlp->vport;
5065 if (iocb->vport != vport)
5068 ulp_command = get_job_cmnd(phba, iocb);
5069 ulp_context = get_job_ulpcontext(phba, iocb);
5070 remote_id = get_job_els_rsp64_did(phba, iocb);
5072 if (pring->ringno == LPFC_ELS_RING) {
5073 switch (ulp_command) {
5074 case CMD_GEN_REQUEST64_CR:
5075 if (iocb->ndlp == ndlp)
5078 case CMD_ELS_REQUEST64_CR:
5079 if (remote_id == ndlp->nlp_DID)
5082 case CMD_XMIT_ELS_RSP64_CX:
5083 if (iocb->ndlp == ndlp)
5086 } else if (pring->ringno == LPFC_FCP_RING) {
5087 /* Skip match check if waiting to relogin to FCP target */
5088 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5089 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
5092 if (ulp_context == ndlp->nlp_rpi)
5099 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
5100 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
5101 struct list_head *dequeue_list)
5103 struct lpfc_iocbq *iocb, *next_iocb;
5105 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5106 /* Check to see if iocb matches the nport */
5107 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
5108 /* match, dequeue */
5109 list_move_tail(&iocb->list, dequeue_list);
5114 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
5115 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5117 struct lpfc_sli *psli = &phba->sli;
5120 spin_lock_irq(&phba->hbalock);
5121 for (i = 0; i < psli->num_rings; i++)
5122 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
5124 spin_unlock_irq(&phba->hbalock);
5128 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
5129 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5131 struct lpfc_sli_ring *pring;
5132 struct lpfc_queue *qp = NULL;
5134 spin_lock_irq(&phba->hbalock);
5135 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
5139 spin_lock(&pring->ring_lock);
5140 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
5141 spin_unlock(&pring->ring_lock);
5143 spin_unlock_irq(&phba->hbalock);
5147 * Free resources / clean up outstanding I/Os
5148 * associated with nlp_rpi in the LPFC_NODELIST entry.
5151 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5153 LIST_HEAD(completions);
5155 lpfc_fabric_abort_nport(ndlp);
5158 * Everything that matches on txcmplq will be returned
5159 * by firmware with a no rpi error.
5161 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5162 if (phba->sli_rev != LPFC_SLI_REV4)
5163 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
5165 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
5168 /* Cancel all the IOCBs from the completions list */
5169 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5176 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
5177 * @phba: Pointer to HBA context object.
5178 * @pmb: Pointer to mailbox object.
5180 * This function will issue an ELS LOGO command after completing
5184 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5186 struct lpfc_vport *vport = pmb->vport;
5187 struct lpfc_nodelist *ndlp;
5189 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
5192 lpfc_issue_els_logo(vport, ndlp, 0);
5194 /* Check to see if there are any deferred events to process */
5195 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
5196 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
5197 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5198 "1434 UNREG cmpl deferred logo x%x "
5199 "on NPort x%x Data: x%x x%px\n",
5200 ndlp->nlp_rpi, ndlp->nlp_DID,
5201 ndlp->nlp_defer_did, ndlp);
5203 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5204 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5205 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5207 /* NLP_RELEASE_RPI is only set for SLI4 ports. */
5208 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5209 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
5210 spin_lock_irq(&ndlp->lock);
5211 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5212 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5213 spin_unlock_irq(&ndlp->lock);
5215 spin_lock_irq(&ndlp->lock);
5216 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5217 spin_unlock_irq(&ndlp->lock);
5220 /* The node has an outstanding reference for the unreg. Now
5221 * that the LOGO action and cleanup are finished, release
5225 mempool_free(pmb, phba->mbox_mem_pool);
5229 * Sets the mailbox completion handler to be used for the
5230 * unreg_rpi command. The handler varies based on the state of
5231 * the port and what will be happening to the rpi next.
5234 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
5235 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
5237 unsigned long iflags;
5239 /* Driver always gets a reference on the mailbox job
5240 * in support of async jobs.
5242 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5243 if (!mbox->ctx_ndlp)
5246 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
5247 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
5249 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
5250 (!(vport->load_flag & FC_UNLOADING)) &&
5251 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
5252 LPFC_SLI_INTF_IF_TYPE_2) &&
5253 (kref_read(&ndlp->kref) > 0)) {
5254 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
5256 if (vport->load_flag & FC_UNLOADING) {
5257 if (phba->sli_rev == LPFC_SLI_REV4) {
5258 spin_lock_irqsave(&ndlp->lock, iflags);
5259 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5260 spin_unlock_irqrestore(&ndlp->lock, iflags);
5263 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5268 * Free rpi associated with LPFC_NODELIST entry.
5269 * This routine is called from lpfc_freenode(), when we are removing
5270 * a LPFC_NODELIST entry. It is also called if the driver initiates a
5271 * LOGO that completes successfully, and we are waiting to PLOGI back
5272 * to the remote NPort. In addition, it is called after we receive
5273 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
5274 * we are waiting to PLOGI back to the remote NPort.
5277 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5279 struct lpfc_hba *phba = vport->phba;
5281 int rc, acc_plogi = 1;
5284 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5285 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
5286 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
5287 lpfc_printf_vlog(vport, KERN_INFO,
5288 LOG_NODE | LOG_DISCOVERY,
5289 "3366 RPI x%x needs to be "
5290 "unregistered nlp_flag x%x "
5292 ndlp->nlp_rpi, ndlp->nlp_flag,
5295 /* If there is already an UNREG in progress for this ndlp,
5296 * no need to queue up another one.
5298 if (ndlp->nlp_flag & NLP_UNREG_INP) {
5299 lpfc_printf_vlog(vport, KERN_INFO,
5300 LOG_NODE | LOG_DISCOVERY,
5301 "1436 unreg_rpi SKIP UNREG x%x on "
5302 "NPort x%x deferred x%x flg x%x "
5304 ndlp->nlp_rpi, ndlp->nlp_DID,
5305 ndlp->nlp_defer_did,
5306 ndlp->nlp_flag, ndlp);
5310 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5312 /* SLI4 ports require the physical rpi value. */
5313 rpi = ndlp->nlp_rpi;
5314 if (phba->sli_rev == LPFC_SLI_REV4)
5315 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
5317 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
5318 mbox->vport = vport;
5319 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
5320 if (!mbox->ctx_ndlp) {
5321 mempool_free(mbox, phba->mbox_mem_pool);
5325 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
5327 * accept PLOGIs after unreg_rpi_cmpl
5330 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
5332 (!(vport->fc_flag & FC_OFFLINE_MODE)))
5333 ndlp->nlp_flag |= NLP_UNREG_INP;
5335 lpfc_printf_vlog(vport, KERN_INFO,
5336 LOG_NODE | LOG_DISCOVERY,
5337 "1433 unreg_rpi UNREG x%x on "
5338 "NPort x%x deferred flg x%x "
5340 ndlp->nlp_rpi, ndlp->nlp_DID,
5341 ndlp->nlp_flag, ndlp);
5343 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5344 if (rc == MBX_NOT_FINISHED) {
5345 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5346 mempool_free(mbox, phba->mbox_mem_pool);
5351 lpfc_printf_vlog(vport, KERN_INFO,
5352 LOG_NODE | LOG_DISCOVERY,
5353 "1444 Failed to allocate mempool "
5354 "unreg_rpi UNREG x%x, "
5355 "DID x%x, flag x%x, "
5357 ndlp->nlp_rpi, ndlp->nlp_DID,
5358 ndlp->nlp_flag, ndlp);
5360 /* Because mempool_alloc failed, we
5361 * will issue a LOGO here and keep the rpi alive if
5364 if (!(vport->load_flag & FC_UNLOADING)) {
5365 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5366 lpfc_issue_els_logo(vport, ndlp, 0);
5367 ndlp->nlp_prev_state = ndlp->nlp_state;
5368 lpfc_nlp_set_state(vport, ndlp,
5374 lpfc_no_rpi(phba, ndlp);
5376 if (phba->sli_rev != LPFC_SLI_REV4)
5378 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
5379 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5381 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5384 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5389 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5390 * @phba: pointer to lpfc hba data structure.
5392 * This routine is invoked to unregister all the currently registered RPIs
5396 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5398 struct lpfc_vport **vports;
5399 struct lpfc_nodelist *ndlp;
5400 struct Scsi_Host *shost;
5403 vports = lpfc_create_vport_work_array(phba);
5405 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5406 "2884 Vport array allocation failed \n");
5409 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5410 shost = lpfc_shost_from_vport(vports[i]);
5411 spin_lock_irq(shost->host_lock);
5412 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5413 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5414 /* The mempool_alloc might sleep */
5415 spin_unlock_irq(shost->host_lock);
5416 lpfc_unreg_rpi(vports[i], ndlp);
5417 spin_lock_irq(shost->host_lock);
5420 spin_unlock_irq(shost->host_lock);
5422 lpfc_destroy_vport_work_array(phba, vports);
5426 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5428 struct lpfc_hba *phba = vport->phba;
5432 if (phba->sli_rev == LPFC_SLI_REV4) {
5433 lpfc_sli4_unreg_all_rpis(vport);
5437 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5439 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5441 mbox->vport = vport;
5442 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5443 mbox->ctx_ndlp = NULL;
5444 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5445 if (rc != MBX_TIMEOUT)
5446 mempool_free(mbox, phba->mbox_mem_pool);
5448 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5449 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5450 "1836 Could not issue "
5451 "unreg_login(all_rpis) status %d\n",
5457 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5459 struct lpfc_hba *phba = vport->phba;
5463 /* Unreg DID is an SLI3 operation. */
5464 if (phba->sli_rev > LPFC_SLI_REV3)
5467 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5469 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5471 mbox->vport = vport;
5472 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5473 mbox->ctx_ndlp = NULL;
5474 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5475 if (rc != MBX_TIMEOUT)
5476 mempool_free(mbox, phba->mbox_mem_pool);
5478 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5479 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5480 "1815 Could not issue "
5481 "unreg_did (default rpis) status %d\n",
5487 * Free resources associated with LPFC_NODELIST entry
5488 * so it can be freed.
5491 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5493 struct lpfc_hba *phba = vport->phba;
5494 LPFC_MBOXQ_t *mb, *nextmb;
5496 /* Cleanup node for NPort <nlp_DID> */
5497 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5498 "0900 Cleanup node for NPort x%x "
5499 "Data: x%x x%x x%x\n",
5500 ndlp->nlp_DID, ndlp->nlp_flag,
5501 ndlp->nlp_state, ndlp->nlp_rpi);
5502 lpfc_dequeue_node(vport, ndlp);
5504 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5506 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5507 if ((mb = phba->sli.mbox_active)) {
5508 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5509 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5510 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5511 mb->ctx_ndlp = NULL;
5512 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5516 spin_lock_irq(&phba->hbalock);
5517 /* Cleanup REG_LOGIN completions which are not yet processed */
5518 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5519 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5520 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5521 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5524 mb->ctx_ndlp = NULL;
5525 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5528 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5529 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5530 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5531 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5532 list_del(&mb->list);
5533 lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_LOCKED);
5535 /* Don't invoke lpfc_nlp_put. The driver is in
5536 * lpfc_nlp_release context.
5540 spin_unlock_irq(&phba->hbalock);
5542 lpfc_els_abort(phba, ndlp);
5544 spin_lock_irq(&ndlp->lock);
5545 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5546 spin_unlock_irq(&ndlp->lock);
5548 ndlp->nlp_last_elscmd = 0;
5549 del_timer_sync(&ndlp->nlp_delayfunc);
5551 list_del_init(&ndlp->els_retry_evt.evt_listp);
5552 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5553 list_del_init(&ndlp->recovery_evt.evt_listp);
5554 lpfc_cleanup_vports_rrqs(vport, ndlp);
5556 if (phba->sli_rev == LPFC_SLI_REV4)
5557 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5563 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5566 D_ID mydid, ndlpdid, matchdid;
5568 if (did == Bcast_DID)
5571 /* First check for Direct match */
5572 if (ndlp->nlp_DID == did)
5575 /* Next check for area/domain identically equals 0 match */
5576 mydid.un.word = vport->fc_myDID;
5577 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5581 matchdid.un.word = did;
5582 ndlpdid.un.word = ndlp->nlp_DID;
5583 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5584 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5585 (mydid.un.b.area == matchdid.un.b.area)) {
5586 /* This code is supposed to match the ID
5587 * for a private loop device that is
5588 * connect to fl_port. But we need to
5589 * check that the port did not just go
5590 * from pt2pt to fabric or we could end
5591 * up matching ndlp->nlp_DID 000001 to
5592 * fabric DID 0x20101
5594 if ((ndlpdid.un.b.domain == 0) &&
5595 (ndlpdid.un.b.area == 0)) {
5596 if (ndlpdid.un.b.id &&
5597 vport->phba->fc_topology ==
5604 matchdid.un.word = ndlp->nlp_DID;
5605 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5606 (mydid.un.b.area == ndlpdid.un.b.area)) {
5607 if ((matchdid.un.b.domain == 0) &&
5608 (matchdid.un.b.area == 0)) {
5609 if (matchdid.un.b.id)
5617 /* Search for a nodelist entry */
5618 static struct lpfc_nodelist *
5619 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5621 struct lpfc_nodelist *ndlp;
5624 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5625 if (lpfc_matchdid(vport, ndlp, did)) {
5626 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5627 ((uint32_t)ndlp->nlp_xri << 16) |
5628 ((uint32_t)ndlp->nlp_type << 8)
5630 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5631 "0929 FIND node DID "
5632 "Data: x%px x%x x%x x%x x%x x%px\n",
5633 ndlp, ndlp->nlp_DID,
5634 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5635 ndlp->active_rrqs_xri_bitmap);
5640 /* FIND node did <did> NOT FOUND */
5641 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5642 "0932 FIND node did x%x NOT FOUND.\n", did);
5646 struct lpfc_nodelist *
5647 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5650 struct lpfc_nodelist *ndlp;
5651 unsigned long iflags;
5653 spin_lock_irqsave(shost->host_lock, iflags);
5654 ndlp = __lpfc_findnode_did(vport, did);
5655 spin_unlock_irqrestore(shost->host_lock, iflags);
5659 struct lpfc_nodelist *
5660 lpfc_findnode_mapped(struct lpfc_vport *vport)
5662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5663 struct lpfc_nodelist *ndlp;
5665 unsigned long iflags;
5667 spin_lock_irqsave(shost->host_lock, iflags);
5669 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5670 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5671 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5672 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5673 ((uint32_t)ndlp->nlp_xri << 16) |
5674 ((uint32_t)ndlp->nlp_type << 8) |
5675 ((uint32_t)ndlp->nlp_rpi & 0xff));
5676 spin_unlock_irqrestore(shost->host_lock, iflags);
5677 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5678 "2025 FIND node DID "
5679 "Data: x%px x%x x%x x%x x%px\n",
5680 ndlp, ndlp->nlp_DID,
5681 ndlp->nlp_flag, data1,
5682 ndlp->active_rrqs_xri_bitmap);
5686 spin_unlock_irqrestore(shost->host_lock, iflags);
5688 /* FIND node did <did> NOT FOUND */
5689 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5690 "2026 FIND mapped did NOT FOUND.\n");
5694 struct lpfc_nodelist *
5695 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5697 struct lpfc_nodelist *ndlp;
5699 ndlp = lpfc_findnode_did(vport, did);
5701 if (vport->phba->nvmet_support)
5703 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5704 lpfc_rscn_payload_check(vport, did) == 0)
5706 ndlp = lpfc_nlp_init(vport, did);
5709 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5711 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5712 "6453 Setup New Node 2B_DISC x%x "
5713 "Data:x%x x%x x%x\n",
5714 ndlp->nlp_DID, ndlp->nlp_flag,
5715 ndlp->nlp_state, vport->fc_flag);
5717 spin_lock_irq(&ndlp->lock);
5718 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5719 spin_unlock_irq(&ndlp->lock);
5723 /* The NVME Target does not want to actively manage an rport.
5724 * The goal is to allow the target to reset its state and clear
5725 * pending IO in preparation for the initiator to recover.
5727 if ((vport->fc_flag & FC_RSCN_MODE) &&
5728 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5729 if (lpfc_rscn_payload_check(vport, did)) {
5731 /* Since this node is marked for discovery,
5732 * delay timeout is not needed.
5734 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5736 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5737 "6455 Setup RSCN Node 2B_DISC x%x "
5738 "Data:x%x x%x x%x\n",
5739 ndlp->nlp_DID, ndlp->nlp_flag,
5740 ndlp->nlp_state, vport->fc_flag);
5742 /* NVME Target mode waits until rport is known to be
5743 * impacted by the RSCN before it transitions. No
5744 * active management - just go to NPR provided the
5745 * node had a valid login.
5747 if (vport->phba->nvmet_support)
5750 /* If we've already received a PLOGI from this NPort
5751 * we don't need to try to discover it again.
5753 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5755 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5758 ndlp->nlp_prev_state = ndlp->nlp_state;
5759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5761 spin_lock_irq(&ndlp->lock);
5762 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5763 spin_unlock_irq(&ndlp->lock);
5765 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5766 "6456 Skip Setup RSCN Node x%x "
5767 "Data:x%x x%x x%x\n",
5768 ndlp->nlp_DID, ndlp->nlp_flag,
5769 ndlp->nlp_state, vport->fc_flag);
5773 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5774 "6457 Setup Active Node 2B_DISC x%x "
5775 "Data:x%x x%x x%x\n",
5776 ndlp->nlp_DID, ndlp->nlp_flag,
5777 ndlp->nlp_state, vport->fc_flag);
5779 /* If the initiator received a PLOGI from this NPort or if the
5780 * initiator is already in the process of discovery on it,
5781 * there's no need to try to discover it again.
5783 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5784 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5785 (!vport->phba->nvmet_support &&
5786 ndlp->nlp_flag & NLP_RCV_PLOGI))
5789 if (vport->phba->nvmet_support)
5792 /* Moving to NPR state clears unsolicited flags and
5793 * allows for rediscovery
5795 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5797 spin_lock_irq(&ndlp->lock);
5798 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5799 spin_unlock_irq(&ndlp->lock);
5804 /* Build a list of nodes to discover based on the loopmap */
5806 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5808 struct lpfc_hba *phba = vport->phba;
5810 uint32_t alpa, index;
5812 if (!lpfc_is_link_up(phba))
5815 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5818 /* Check for loop map present or not */
5819 if (phba->alpa_map[0]) {
5820 for (j = 1; j <= phba->alpa_map[0]; j++) {
5821 alpa = phba->alpa_map[j];
5822 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5824 lpfc_setup_disc_node(vport, alpa);
5827 /* No alpamap, so try all alpa's */
5828 for (j = 0; j < FC_MAXLOOP; j++) {
5829 /* If cfg_scan_down is set, start from highest
5830 * ALPA (0xef) to lowest (0x1).
5832 if (vport->cfg_scan_down)
5835 index = FC_MAXLOOP - j - 1;
5836 alpa = lpfcAlpaArray[index];
5837 if ((vport->fc_myDID & 0xff) == alpa)
5839 lpfc_setup_disc_node(vport, alpa);
5847 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5850 struct lpfc_sli *psli = &phba->sli;
5851 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5852 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5856 * if it's not a physical port or if we already send
5857 * clear_la then don't send it.
5859 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5860 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5861 (phba->sli_rev == LPFC_SLI_REV4))
5864 /* Link up discovery */
5865 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5866 phba->link_state = LPFC_CLEAR_LA;
5867 lpfc_clear_la(phba, mbox);
5868 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5869 mbox->vport = vport;
5870 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5871 if (rc == MBX_NOT_FINISHED) {
5872 mempool_free(mbox, phba->mbox_mem_pool);
5873 lpfc_disc_flush_list(vport);
5874 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5875 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5876 phba->link_state = LPFC_HBA_ERROR;
5881 /* Reg_vpi to tell firmware to resume normal operations */
5883 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5885 LPFC_MBOXQ_t *regvpimbox;
5887 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5889 lpfc_reg_vpi(vport, regvpimbox);
5890 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5891 regvpimbox->vport = vport;
5892 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5893 == MBX_NOT_FINISHED) {
5894 mempool_free(regvpimbox, phba->mbox_mem_pool);
5899 /* Start Link up / RSCN discovery on NPR nodes */
5901 lpfc_disc_start(struct lpfc_vport *vport)
5903 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5904 struct lpfc_hba *phba = vport->phba;
5906 uint32_t clear_la_pending;
5908 if (!lpfc_is_link_up(phba)) {
5909 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5910 "3315 Link is not up %x\n",
5915 if (phba->link_state == LPFC_CLEAR_LA)
5916 clear_la_pending = 1;
5918 clear_la_pending = 0;
5920 if (vport->port_state < LPFC_VPORT_READY)
5921 vport->port_state = LPFC_DISC_AUTH;
5923 lpfc_set_disctmo(vport);
5925 vport->fc_prevDID = vport->fc_myDID;
5926 vport->num_disc_nodes = 0;
5928 /* Start Discovery state <hba_state> */
5929 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5930 "0202 Start Discovery port state x%x "
5931 "flg x%x Data: x%x x%x x%x\n",
5932 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5933 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5935 /* First do ADISCs - if any */
5936 num_sent = lpfc_els_disc_adisc(vport);
5941 /* Register the VPI for SLI3, NPIV only. */
5942 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5943 !(vport->fc_flag & FC_PT2PT) &&
5944 !(vport->fc_flag & FC_RSCN_MODE) &&
5945 (phba->sli_rev < LPFC_SLI_REV4)) {
5946 lpfc_issue_clear_la(phba, vport);
5947 lpfc_issue_reg_vpi(phba, vport);
5952 * For SLI2, we need to set port_state to READY and continue
5955 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5956 /* If we get here, there is nothing to ADISC */
5957 lpfc_issue_clear_la(phba, vport);
5959 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5960 vport->num_disc_nodes = 0;
5961 /* go thru NPR nodes and issue ELS PLOGIs */
5962 if (vport->fc_npr_cnt)
5963 lpfc_els_disc_plogi(vport);
5965 if (!vport->num_disc_nodes) {
5966 spin_lock_irq(shost->host_lock);
5967 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5968 spin_unlock_irq(shost->host_lock);
5969 lpfc_can_disctmo(vport);
5972 vport->port_state = LPFC_VPORT_READY;
5974 /* Next do PLOGIs - if any */
5975 num_sent = lpfc_els_disc_plogi(vport);
5980 if (vport->fc_flag & FC_RSCN_MODE) {
5981 /* Check to see if more RSCNs came in while we
5982 * were processing this one.
5984 if ((vport->fc_rscn_id_cnt == 0) &&
5985 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5986 spin_lock_irq(shost->host_lock);
5987 vport->fc_flag &= ~FC_RSCN_MODE;
5988 spin_unlock_irq(shost->host_lock);
5989 lpfc_can_disctmo(vport);
5991 lpfc_els_handle_rscn(vport);
5998 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
5999 * ring the match the sppecified nodelist.
6002 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
6004 LIST_HEAD(completions);
6005 struct lpfc_iocbq *iocb, *next_iocb;
6006 struct lpfc_sli_ring *pring;
6009 pring = lpfc_phba_elsring(phba);
6010 if (unlikely(!pring))
6013 /* Error matching iocb on txq or txcmplq
6014 * First check the txq.
6016 spin_lock_irq(&phba->hbalock);
6017 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6018 if (iocb->ndlp != ndlp)
6021 ulp_command = get_job_cmnd(phba, iocb);
6023 if (ulp_command == CMD_ELS_REQUEST64_CR ||
6024 ulp_command == CMD_XMIT_ELS_RSP64_CX) {
6026 list_move_tail(&iocb->list, &completions);
6030 /* Next check the txcmplq */
6031 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
6032 if (iocb->ndlp != ndlp)
6035 ulp_command = get_job_cmnd(phba, iocb);
6037 if (ulp_command == CMD_ELS_REQUEST64_CR ||
6038 ulp_command == CMD_XMIT_ELS_RSP64_CX) {
6039 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
6042 spin_unlock_irq(&phba->hbalock);
6044 /* Make sure HBA is alive */
6045 lpfc_issue_hb_tmo(phba);
6047 /* Cancel all the IOCBs from the completions list */
6048 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6053 lpfc_disc_flush_list(struct lpfc_vport *vport)
6055 struct lpfc_nodelist *ndlp, *next_ndlp;
6056 struct lpfc_hba *phba = vport->phba;
6058 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
6059 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6061 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
6062 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
6063 lpfc_free_tx(phba, ndlp);
6070 * lpfc_notify_xport_npr - notifies xport of node disappearance
6071 * @vport: Pointer to Virtual Port object.
6073 * Transitions all ndlps to NPR state. When lpfc_nlp_set_state
6074 * calls lpfc_nlp_state_cleanup, the ndlp->rport is unregistered
6075 * and transport notified that the node is gone.
6080 lpfc_notify_xport_npr(struct lpfc_vport *vport)
6082 struct lpfc_nodelist *ndlp, *next_ndlp;
6084 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6086 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6090 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
6092 lpfc_els_flush_rscn(vport);
6093 lpfc_els_flush_cmd(vport);
6094 lpfc_disc_flush_list(vport);
6095 if (pci_channel_offline(vport->phba->pcidev))
6096 lpfc_notify_xport_npr(vport);
6099 /*****************************************************************************/
6101 * NAME: lpfc_disc_timeout
6103 * FUNCTION: Fibre Channel driver discovery timeout routine.
6105 * EXECUTION ENVIRONMENT: interrupt only
6113 /*****************************************************************************/
6115 lpfc_disc_timeout(struct timer_list *t)
6117 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
6118 struct lpfc_hba *phba = vport->phba;
6119 uint32_t tmo_posted;
6120 unsigned long flags = 0;
6122 if (unlikely(!phba))
6125 spin_lock_irqsave(&vport->work_port_lock, flags);
6126 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
6128 vport->work_port_events |= WORKER_DISC_TMO;
6129 spin_unlock_irqrestore(&vport->work_port_lock, flags);
6132 lpfc_worker_wake_up(phba);
6137 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
6139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6140 struct lpfc_hba *phba = vport->phba;
6141 struct lpfc_sli *psli = &phba->sli;
6142 struct lpfc_nodelist *ndlp, *next_ndlp;
6143 LPFC_MBOXQ_t *initlinkmbox;
6144 int rc, clrlaerr = 0;
6146 if (!(vport->fc_flag & FC_DISC_TMO))
6149 spin_lock_irq(shost->host_lock);
6150 vport->fc_flag &= ~FC_DISC_TMO;
6151 spin_unlock_irq(shost->host_lock);
6153 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6154 "disc timeout: state:x%x rtry:x%x flg:x%x",
6155 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
6157 switch (vport->port_state) {
6159 case LPFC_LOCAL_CFG_LINK:
6161 * port_state is identically LPFC_LOCAL_CFG_LINK while
6162 * waiting for FAN timeout
6164 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
6165 "0221 FAN timeout\n");
6167 /* Start discovery by sending FLOGI, clean up old rpis */
6168 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6170 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
6172 if (ndlp->nlp_type & NLP_FABRIC) {
6173 /* Clean up the ndlp on Fabric connections */
6174 lpfc_drop_node(vport, ndlp);
6176 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
6177 /* Fail outstanding IO now since device
6178 * is marked for PLOGI.
6180 lpfc_unreg_rpi(vport, ndlp);
6183 if (vport->port_state != LPFC_FLOGI) {
6184 if (phba->sli_rev <= LPFC_SLI_REV3)
6185 lpfc_initial_flogi(vport);
6187 lpfc_issue_init_vfi(vport);
6194 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
6195 /* Initial FLOGI timeout */
6196 lpfc_printf_vlog(vport, KERN_ERR,
6198 "0222 Initial %s timeout\n",
6199 vport->vpi ? "FDISC" : "FLOGI");
6201 /* Assume no Fabric and go on with discovery.
6202 * Check for outstanding ELS FLOGI to abort.
6205 /* FLOGI failed, so just use loop map to make discovery list */
6206 lpfc_disc_list_loopmap(vport);
6208 /* Start discovery */
6209 lpfc_disc_start(vport);
6212 case LPFC_FABRIC_CFG_LINK:
6213 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
6215 lpfc_printf_vlog(vport, KERN_ERR,
6217 "0223 Timeout while waiting for "
6218 "NameServer login\n");
6219 /* Next look for NameServer ndlp */
6220 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6222 lpfc_els_abort(phba, ndlp);
6224 /* ReStart discovery */
6228 /* Check for wait for NameServer Rsp timeout */
6229 lpfc_printf_vlog(vport, KERN_ERR,
6231 "0224 NameServer Query timeout "
6233 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6235 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
6236 /* Try it one more time */
6237 vport->fc_ns_retry++;
6238 vport->gidft_inp = 0;
6239 rc = lpfc_issue_gidft(vport);
6243 vport->fc_ns_retry = 0;
6247 * Discovery is over.
6248 * set port_state to PORT_READY if SLI2.
6249 * cmpl_reg_vpi will set port_state to READY for SLI3.
6251 if (phba->sli_rev < LPFC_SLI_REV4) {
6252 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6253 lpfc_issue_reg_vpi(phba, vport);
6255 lpfc_issue_clear_la(phba, vport);
6256 vport->port_state = LPFC_VPORT_READY;
6260 /* Setup and issue mailbox INITIALIZE LINK command */
6261 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6262 if (!initlinkmbox) {
6263 lpfc_printf_vlog(vport, KERN_ERR,
6265 "0206 Device Discovery "
6266 "completion error\n");
6267 phba->link_state = LPFC_HBA_ERROR;
6271 lpfc_linkdown(phba);
6272 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
6273 phba->cfg_link_speed);
6274 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6275 initlinkmbox->vport = vport;
6276 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6277 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
6278 lpfc_set_loopback_flag(phba);
6279 if (rc == MBX_NOT_FINISHED)
6280 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6284 case LPFC_DISC_AUTH:
6285 /* Node Authentication timeout */
6286 lpfc_printf_vlog(vport, KERN_ERR,
6288 "0227 Node Authentication timeout\n");
6289 lpfc_disc_flush_list(vport);
6292 * set port_state to PORT_READY if SLI2.
6293 * cmpl_reg_vpi will set port_state to READY for SLI3.
6295 if (phba->sli_rev < LPFC_SLI_REV4) {
6296 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6297 lpfc_issue_reg_vpi(phba, vport);
6298 else { /* NPIV Not enabled */
6299 lpfc_issue_clear_la(phba, vport);
6300 vport->port_state = LPFC_VPORT_READY;
6305 case LPFC_VPORT_READY:
6306 if (vport->fc_flag & FC_RSCN_MODE) {
6307 lpfc_printf_vlog(vport, KERN_ERR,
6309 "0231 RSCN timeout Data: x%x "
6311 vport->fc_ns_retry, LPFC_MAX_NS_RETRY,
6312 vport->port_state, vport->gidft_inp);
6314 /* Cleanup any outstanding ELS commands */
6315 lpfc_els_flush_cmd(vport);
6317 lpfc_els_flush_rscn(vport);
6318 lpfc_disc_flush_list(vport);
6323 lpfc_printf_vlog(vport, KERN_ERR,
6325 "0273 Unexpected discovery timeout, "
6326 "vport State x%x\n", vport->port_state);
6330 switch (phba->link_state) {
6332 /* CLEAR LA timeout */
6333 lpfc_printf_vlog(vport, KERN_ERR,
6335 "0228 CLEAR LA timeout\n");
6340 lpfc_issue_clear_la(phba, vport);
6342 case LPFC_LINK_UNKNOWN:
6343 case LPFC_WARM_START:
6344 case LPFC_INIT_START:
6345 case LPFC_INIT_MBX_CMDS:
6346 case LPFC_LINK_DOWN:
6347 case LPFC_HBA_ERROR:
6348 lpfc_printf_vlog(vport, KERN_ERR,
6350 "0230 Unexpected timeout, hba link "
6351 "state x%x\n", phba->link_state);
6355 case LPFC_HBA_READY:
6360 lpfc_disc_flush_list(vport);
6361 if (phba->sli_rev != LPFC_SLI_REV4) {
6362 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6363 ~LPFC_STOP_IOCB_EVENT;
6364 psli->sli3_ring[LPFC_FCP_RING].flag &=
6365 ~LPFC_STOP_IOCB_EVENT;
6367 vport->port_state = LPFC_VPORT_READY;
6373 * This routine handles processing a NameServer REG_LOGIN mailbox
6374 * command upon completion. It is setup in the LPFC_MBOXQ
6375 * as the completion routine when the command is
6376 * handed off to the SLI layer.
6379 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6381 MAILBOX_t *mb = &pmb->u.mb;
6382 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6383 struct lpfc_vport *vport = pmb->vport;
6385 pmb->ctx_ndlp = NULL;
6387 if (phba->sli_rev < LPFC_SLI_REV4)
6388 ndlp->nlp_rpi = mb->un.varWords[0];
6389 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6390 ndlp->nlp_type |= NLP_FABRIC;
6391 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6392 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6393 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
6394 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6395 kref_read(&ndlp->kref),
6398 * Start issuing Fabric-Device Management Interface (FDMI) command to
6399 * 0xfffffa (FDMI well known port).
6400 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6401 * DPRT -> RPRT (vports)
6403 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6404 phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */
6405 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6407 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6411 /* decrement the node reference count held for this callback
6415 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
6420 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6422 uint16_t *rpi = param;
6424 return ndlp->nlp_rpi == *rpi;
6428 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6430 return memcmp(&ndlp->nlp_portname, param,
6431 sizeof(ndlp->nlp_portname)) == 0;
6434 static struct lpfc_nodelist *
6435 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6437 struct lpfc_nodelist *ndlp;
6439 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6440 if (filter(ndlp, param)) {
6441 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6442 "3185 FIND node filter %ps DID "
6443 "ndlp x%px did x%x flg x%x st x%x "
6444 "xri x%x type x%x rpi x%x\n",
6445 filter, ndlp, ndlp->nlp_DID,
6446 ndlp->nlp_flag, ndlp->nlp_state,
6447 ndlp->nlp_xri, ndlp->nlp_type,
6452 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6453 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6458 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6459 * returns the node list element pointer else return NULL.
6461 struct lpfc_nodelist *
6462 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6464 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6468 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6469 * returns the node element list pointer else return NULL.
6471 struct lpfc_nodelist *
6472 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6474 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6475 struct lpfc_nodelist *ndlp;
6477 spin_lock_irq(shost->host_lock);
6478 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6479 spin_unlock_irq(shost->host_lock);
6484 * This routine looks up the ndlp lists for the given RPI. If the rpi
6485 * is found, the routine returns the node element list pointer else
6488 struct lpfc_nodelist *
6489 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6491 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6492 struct lpfc_nodelist *ndlp;
6493 unsigned long flags;
6495 spin_lock_irqsave(shost->host_lock, flags);
6496 ndlp = __lpfc_findnode_rpi(vport, rpi);
6497 spin_unlock_irqrestore(shost->host_lock, flags);
6502 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6503 * @phba: pointer to lpfc hba data structure.
6504 * @vpi: the physical host virtual N_Port identifier.
6506 * This routine finds a vport on a HBA (referred by @phba) through a
6507 * @vpi. The function walks the HBA's vport list and returns the address
6508 * of the vport with the matching @vpi.
6511 * NULL - No vport with the matching @vpi found
6512 * Otherwise - Address to the vport with the matching @vpi.
6515 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6517 struct lpfc_vport *vport;
6518 unsigned long flags;
6521 /* The physical ports are always vpi 0 - translate is unnecessary. */
6524 * Translate the physical vpi to the logical vpi. The
6525 * vport stores the logical vpi.
6527 for (i = 0; i <= phba->max_vpi; i++) {
6528 if (vpi == phba->vpi_ids[i])
6532 if (i > phba->max_vpi) {
6533 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6534 "2936 Could not find Vport mapped "
6535 "to vpi %d\n", vpi);
6540 spin_lock_irqsave(&phba->port_list_lock, flags);
6541 list_for_each_entry(vport, &phba->port_list, listentry) {
6542 if (vport->vpi == i) {
6543 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6547 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6551 struct lpfc_nodelist *
6552 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6554 struct lpfc_nodelist *ndlp;
6555 int rpi = LPFC_RPI_ALLOC_ERROR;
6557 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6558 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6559 if (rpi == LPFC_RPI_ALLOC_ERROR)
6563 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6565 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6566 lpfc_sli4_free_rpi(vport->phba, rpi);
6570 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6572 spin_lock_init(&ndlp->lock);
6574 lpfc_initialize_node(vport, ndlp, did);
6575 INIT_LIST_HEAD(&ndlp->nlp_listp);
6576 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6577 ndlp->nlp_rpi = rpi;
6578 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6579 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6580 "flg:x%x refcnt:%d\n",
6581 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6582 ndlp->nlp_flag, kref_read(&ndlp->kref));
6584 ndlp->active_rrqs_xri_bitmap =
6585 mempool_alloc(vport->phba->active_rrq_pool,
6587 if (ndlp->active_rrqs_xri_bitmap)
6588 memset(ndlp->active_rrqs_xri_bitmap, 0,
6589 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6594 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6595 "node init: did:x%x",
6596 ndlp->nlp_DID, 0, 0);
6601 /* This routine releases all resources associated with a specifc NPort's ndlp
6602 * and mempool_free's the nodelist.
6605 lpfc_nlp_release(struct kref *kref)
6607 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6609 struct lpfc_vport *vport = ndlp->vport;
6611 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6612 "node release: did:x%x flg:x%x type:x%x",
6613 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6615 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6616 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
6617 __func__, ndlp, ndlp->nlp_DID,
6618 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6620 /* remove ndlp from action. */
6621 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6622 lpfc_cleanup_node(vport, ndlp);
6624 /* Not all ELS transactions have registered the RPI with the port.
6625 * In these cases the rpi usage is temporary and the node is
6626 * released when the WQE is completed. Catch this case to free the
6627 * RPI to the pool. Because this node is in the release path, a lock
6628 * is unnecessary. All references are gone and the node has been
6631 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6632 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6633 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6634 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6635 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6639 /* The node is not freed back to memory, it is released to a pool so
6640 * the node fields need to be cleaned up.
6643 ndlp->nlp_state = NLP_STE_FREED_NODE;
6645 ndlp->fc4_xpt_flags = 0;
6647 /* free ndlp memory for final ndlp release */
6648 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6649 mempool_free(ndlp->active_rrqs_xri_bitmap,
6650 ndlp->phba->active_rrq_pool);
6651 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6654 /* This routine bumps the reference count for a ndlp structure to ensure
6655 * that one discovery thread won't free a ndlp while another discovery thread
6658 struct lpfc_nodelist *
6659 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6661 unsigned long flags;
6664 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6665 "node get: did:x%x flg:x%x refcnt:x%x",
6666 ndlp->nlp_DID, ndlp->nlp_flag,
6667 kref_read(&ndlp->kref));
6669 /* The check of ndlp usage to prevent incrementing the
6670 * ndlp reference count that is in the process of being
6673 spin_lock_irqsave(&ndlp->lock, flags);
6674 if (!kref_get_unless_zero(&ndlp->kref)) {
6675 spin_unlock_irqrestore(&ndlp->lock, flags);
6676 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6677 "0276 %s: ndlp:x%px refcnt:%d\n",
6678 __func__, (void *)ndlp, kref_read(&ndlp->kref));
6681 spin_unlock_irqrestore(&ndlp->lock, flags);
6683 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
6689 /* This routine decrements the reference count for a ndlp structure. If the
6690 * count goes to 0, this indicates the associated nodelist should be freed.
6693 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6696 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6697 "node put: did:x%x flg:x%x refcnt:x%x",
6698 ndlp->nlp_DID, ndlp->nlp_flag,
6699 kref_read(&ndlp->kref));
6701 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
6704 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
6707 /* This routine free's the specified nodelist if it is not in use
6708 * by any other discovery thread. This routine returns 1 if the
6709 * ndlp has been freed. A return value of 0 indicates the ndlp is
6710 * not yet been released.
6713 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6715 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6716 "node not used: did:x%x flg:x%x refcnt:x%x",
6717 ndlp->nlp_DID, ndlp->nlp_flag,
6718 kref_read(&ndlp->kref));
6720 if (kref_read(&ndlp->kref) == 1)
6721 if (lpfc_nlp_put(ndlp))
6727 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6728 * @phba: Pointer to hba context object.
6730 * This function iterate through all FC nodes associated
6731 * will all vports to check if there is any node with
6732 * fc_rports associated with it. If there is an fc_rport
6733 * associated with the node, then the node is either in
6734 * discovered state or its devloss_timer is pending.
6737 lpfc_fcf_inuse(struct lpfc_hba *phba)
6739 struct lpfc_vport **vports;
6741 struct lpfc_nodelist *ndlp;
6742 struct Scsi_Host *shost;
6744 vports = lpfc_create_vport_work_array(phba);
6746 /* If driver cannot allocate memory, indicate fcf is in use */
6750 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6751 shost = lpfc_shost_from_vport(vports[i]);
6752 spin_lock_irq(shost->host_lock);
6754 * IF the CVL_RCVD bit is not set then we have sent the
6756 * If dev_loss fires while we are waiting we do not want to
6759 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6760 spin_unlock_irq(shost->host_lock);
6764 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6766 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6768 spin_unlock_irq(shost->host_lock);
6770 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6772 lpfc_printf_log(phba, KERN_INFO,
6773 LOG_NODE | LOG_DISCOVERY,
6774 "2624 RPI %x DID %x flag %x "
6775 "still logged in\n",
6776 ndlp->nlp_rpi, ndlp->nlp_DID,
6780 spin_unlock_irq(shost->host_lock);
6783 lpfc_destroy_vport_work_array(phba, vports);
6788 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6789 * @phba: Pointer to hba context object.
6790 * @mboxq: Pointer to mailbox object.
6792 * This function frees memory associated with the mailbox command.
6795 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6797 struct lpfc_vport *vport = mboxq->vport;
6798 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6800 if (mboxq->u.mb.mbxStatus) {
6801 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6802 "2555 UNREG_VFI mbxStatus error x%x "
6804 mboxq->u.mb.mbxStatus, vport->port_state);
6806 spin_lock_irq(shost->host_lock);
6807 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6808 spin_unlock_irq(shost->host_lock);
6809 mempool_free(mboxq, phba->mbox_mem_pool);
6814 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6815 * @phba: Pointer to hba context object.
6816 * @mboxq: Pointer to mailbox object.
6818 * This function frees memory associated with the mailbox command.
6821 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6823 struct lpfc_vport *vport = mboxq->vport;
6825 if (mboxq->u.mb.mbxStatus) {
6826 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6827 "2550 UNREG_FCFI mbxStatus error x%x "
6829 mboxq->u.mb.mbxStatus, vport->port_state);
6831 mempool_free(mboxq, phba->mbox_mem_pool);
6836 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6837 * @phba: Pointer to hba context object.
6839 * This function prepare the HBA for unregistering the currently registered
6840 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6844 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6846 struct lpfc_vport **vports;
6847 struct lpfc_nodelist *ndlp;
6848 struct Scsi_Host *shost;
6851 /* Unregister RPIs */
6852 if (lpfc_fcf_inuse(phba))
6853 lpfc_unreg_hba_rpis(phba);
6855 /* At this point, all discovery is aborted */
6856 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6858 /* Unregister VPIs */
6859 vports = lpfc_create_vport_work_array(phba);
6860 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6861 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6862 /* Stop FLOGI/FDISC retries */
6863 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6865 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6866 lpfc_cleanup_pending_mbox(vports[i]);
6867 if (phba->sli_rev == LPFC_SLI_REV4)
6868 lpfc_sli4_unreg_all_rpis(vports[i]);
6869 lpfc_mbx_unreg_vpi(vports[i]);
6870 shost = lpfc_shost_from_vport(vports[i]);
6871 spin_lock_irq(shost->host_lock);
6872 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6873 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6874 spin_unlock_irq(shost->host_lock);
6876 lpfc_destroy_vport_work_array(phba, vports);
6877 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6878 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6880 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6881 lpfc_cleanup_pending_mbox(phba->pport);
6882 if (phba->sli_rev == LPFC_SLI_REV4)
6883 lpfc_sli4_unreg_all_rpis(phba->pport);
6884 lpfc_mbx_unreg_vpi(phba->pport);
6885 shost = lpfc_shost_from_vport(phba->pport);
6886 spin_lock_irq(shost->host_lock);
6887 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6888 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6889 spin_unlock_irq(shost->host_lock);
6892 /* Cleanup any outstanding ELS commands */
6893 lpfc_els_flush_all_cmd(phba);
6895 /* Unregister the physical port VFI */
6896 rc = lpfc_issue_unreg_vfi(phba->pport);
6901 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6902 * @phba: Pointer to hba context object.
6904 * This function issues synchronous unregister FCF mailbox command to HBA to
6905 * unregister the currently registered FCF record. The driver does not reset
6906 * the driver FCF usage state flags.
6908 * Return 0 if successfully issued, none-zero otherwise.
6911 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6916 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6918 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6919 "2551 UNREG_FCFI mbox allocation failed"
6920 "HBA state x%x\n", phba->pport->port_state);
6923 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6924 mbox->vport = phba->pport;
6925 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6926 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6928 if (rc == MBX_NOT_FINISHED) {
6929 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6930 "2552 Unregister FCFI command failed rc x%x "
6932 rc, phba->pport->port_state);
6939 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6940 * @phba: Pointer to hba context object.
6942 * This function unregisters the currently reigstered FCF. This function
6943 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6946 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6950 /* Preparation for unregistering fcf */
6951 rc = lpfc_unregister_fcf_prep(phba);
6953 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6954 "2748 Failed to prepare for unregistering "
6955 "HBA's FCF record: rc=%d\n", rc);
6959 /* Now, unregister FCF record and reset HBA FCF state */
6960 rc = lpfc_sli4_unregister_fcf(phba);
6963 /* Reset HBA FCF states after successful unregister FCF */
6964 phba->fcf.fcf_flag = 0;
6965 phba->fcf.current_rec.flag = 0;
6968 * If driver is not unloading, check if there is any other
6969 * FCF record that can be used for discovery.
6971 if ((phba->pport->load_flag & FC_UNLOADING) ||
6972 (phba->link_state < LPFC_LINK_UP))
6975 /* This is considered as the initial FCF discovery scan */
6976 spin_lock_irq(&phba->hbalock);
6977 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6978 spin_unlock_irq(&phba->hbalock);
6980 /* Reset FCF roundrobin bmask for new discovery */
6981 lpfc_sli4_clear_fcf_rr_bmask(phba);
6983 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6986 spin_lock_irq(&phba->hbalock);
6987 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6988 spin_unlock_irq(&phba->hbalock);
6989 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6990 "2553 lpfc_unregister_unused_fcf failed "
6991 "to read FCF record HBA state x%x\n",
6992 phba->pport->port_state);
6997 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6998 * @phba: Pointer to hba context object.
7000 * This function just unregisters the currently reigstered FCF. It does not
7001 * try to find another FCF for discovery.
7004 lpfc_unregister_fcf(struct lpfc_hba *phba)
7008 /* Preparation for unregistering fcf */
7009 rc = lpfc_unregister_fcf_prep(phba);
7011 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7012 "2749 Failed to prepare for unregistering "
7013 "HBA's FCF record: rc=%d\n", rc);
7017 /* Now, unregister FCF record and reset HBA FCF state */
7018 rc = lpfc_sli4_unregister_fcf(phba);
7021 /* Set proper HBA FCF states after successful unregister FCF */
7022 spin_lock_irq(&phba->hbalock);
7023 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
7024 spin_unlock_irq(&phba->hbalock);
7028 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
7029 * @phba: Pointer to hba context object.
7031 * This function check if there are any connected remote port for the FCF and
7032 * if all the devices are disconnected, this function unregister FCFI.
7033 * This function also tries to use another FCF for discovery.
7036 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
7039 * If HBA is not running in FIP mode, if HBA does not support
7040 * FCoE, if FCF discovery is ongoing, or if FCF has not been
7041 * registered, do nothing.
7043 spin_lock_irq(&phba->hbalock);
7044 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
7045 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
7046 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
7047 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
7048 (phba->pport->port_state == LPFC_FLOGI)) {
7049 spin_unlock_irq(&phba->hbalock);
7052 spin_unlock_irq(&phba->hbalock);
7054 if (lpfc_fcf_inuse(phba))
7057 lpfc_unregister_fcf_rescan(phba);
7061 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
7062 * @phba: Pointer to hba context object.
7063 * @buff: Buffer containing the FCF connection table as in the config
7065 * This function create driver data structure for the FCF connection
7066 * record table read from config region 23.
7069 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
7072 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
7073 struct lpfc_fcf_conn_hdr *conn_hdr;
7074 struct lpfc_fcf_conn_rec *conn_rec;
7075 uint32_t record_count;
7078 /* Free the current connect table */
7079 list_for_each_entry_safe(conn_entry, next_conn_entry,
7080 &phba->fcf_conn_rec_list, list) {
7081 list_del_init(&conn_entry->list);
7085 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
7086 record_count = conn_hdr->length * sizeof(uint32_t)/
7087 sizeof(struct lpfc_fcf_conn_rec);
7089 conn_rec = (struct lpfc_fcf_conn_rec *)
7090 (buff + sizeof(struct lpfc_fcf_conn_hdr));
7092 for (i = 0; i < record_count; i++) {
7093 if (!(conn_rec[i].flags & FCFCNCT_VALID))
7095 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
7098 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7099 "2566 Failed to allocate connection"
7104 memcpy(&conn_entry->conn_rec, &conn_rec[i],
7105 sizeof(struct lpfc_fcf_conn_rec));
7106 list_add_tail(&conn_entry->list,
7107 &phba->fcf_conn_rec_list);
7110 if (!list_empty(&phba->fcf_conn_rec_list)) {
7112 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
7114 conn_rec = &conn_entry->conn_rec;
7115 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7116 "3345 FCF connection list rec[%02d]: "
7117 "flags:x%04x, vtag:x%04x, "
7118 "fabric_name:x%02x:%02x:%02x:%02x:"
7119 "%02x:%02x:%02x:%02x, "
7120 "switch_name:x%02x:%02x:%02x:%02x:"
7121 "%02x:%02x:%02x:%02x\n", i++,
7122 conn_rec->flags, conn_rec->vlan_tag,
7123 conn_rec->fabric_name[0],
7124 conn_rec->fabric_name[1],
7125 conn_rec->fabric_name[2],
7126 conn_rec->fabric_name[3],
7127 conn_rec->fabric_name[4],
7128 conn_rec->fabric_name[5],
7129 conn_rec->fabric_name[6],
7130 conn_rec->fabric_name[7],
7131 conn_rec->switch_name[0],
7132 conn_rec->switch_name[1],
7133 conn_rec->switch_name[2],
7134 conn_rec->switch_name[3],
7135 conn_rec->switch_name[4],
7136 conn_rec->switch_name[5],
7137 conn_rec->switch_name[6],
7138 conn_rec->switch_name[7]);
7144 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
7145 * @phba: Pointer to hba context object.
7146 * @buff: Buffer containing the FCoE parameter data structure.
7148 * This function update driver data structure with config
7149 * parameters read from config region 23.
7152 lpfc_read_fcoe_param(struct lpfc_hba *phba,
7155 struct lpfc_fip_param_hdr *fcoe_param_hdr;
7156 struct lpfc_fcoe_params *fcoe_param;
7158 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
7160 fcoe_param = (struct lpfc_fcoe_params *)
7161 (buff + sizeof(struct lpfc_fip_param_hdr));
7163 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
7164 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
7167 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
7168 phba->valid_vlan = 1;
7169 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
7173 phba->fc_map[0] = fcoe_param->fc_map[0];
7174 phba->fc_map[1] = fcoe_param->fc_map[1];
7175 phba->fc_map[2] = fcoe_param->fc_map[2];
7180 * lpfc_get_rec_conf23 - Get a record type in config region data.
7181 * @buff: Buffer containing config region 23 data.
7182 * @size: Size of the data buffer.
7183 * @rec_type: Record type to be searched.
7185 * This function searches config region data to find the beginning
7186 * of the record specified by record_type. If record found, this
7187 * function return pointer to the record else return NULL.
7190 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
7192 uint32_t offset = 0, rec_length;
7194 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
7195 (size < sizeof(uint32_t)))
7198 rec_length = buff[offset + 1];
7201 * One TLV record has one word header and number of data words
7202 * specified in the rec_length field of the record header.
7204 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
7206 if (buff[offset] == rec_type)
7207 return &buff[offset];
7209 if (buff[offset] == LPFC_REGION23_LAST_REC)
7212 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
7213 rec_length = buff[offset + 1];
7219 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
7220 * @phba: Pointer to lpfc_hba data structure.
7221 * @buff: Buffer containing config region 23 data.
7222 * @size: Size of the data buffer.
7224 * This function parses the FCoE config parameters in config region 23 and
7225 * populate driver data structure with the parameters.
7228 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
7232 uint32_t offset = 0;
7236 * If data size is less than 2 words signature and version cannot be
7239 if (size < 2*sizeof(uint32_t))
7242 /* Check the region signature first */
7243 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
7244 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7245 "2567 Config region 23 has bad signature\n");
7251 /* Check the data structure version */
7252 if (buff[offset] != LPFC_REGION23_VERSION) {
7253 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7254 "2568 Config region 23 has bad version\n");
7259 /* Read FCoE param record */
7260 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7261 size - offset, FCOE_PARAM_TYPE);
7263 lpfc_read_fcoe_param(phba, rec_ptr);
7265 /* Read FCF connection table */
7266 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7267 size - offset, FCOE_CONN_TBL_TYPE);
7269 lpfc_read_fcf_conn_tbl(phba, rec_ptr);