1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2022 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 spin_lock_irqsave(&ndlp->lock, iflags);
430 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
431 spin_unlock_irqrestore(&ndlp->lock, iflags);
433 if (phba->sli_rev == LPFC_SLI_REV4)
434 fcf_inuse = lpfc_fcf_inuse(phba);
436 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
437 "rport devlosstmo:did:x%x type:x%x id:x%x",
438 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
440 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
441 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
442 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
443 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
445 /* If the driver is recovering the rport, ignore devloss. */
446 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
447 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
448 "0284 Devloss timeout Ignored on "
449 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
451 *name, *(name+1), *(name+2), *(name+3),
452 *(name+4), *(name+5), *(name+6), *(name+7),
457 /* Fabric nodes are done. */
458 if (ndlp->nlp_type & NLP_FABRIC) {
459 spin_lock_irqsave(&ndlp->lock, iflags);
460 /* In massive vport configuration settings, it's possible
461 * dev_loss_tmo fired during node recovery. So, check if
462 * fabric nodes are in discovery states outstanding.
464 switch (ndlp->nlp_DID) {
466 fc_vport = vport->fc_vport;
468 fc_vport->vport_state == FC_VPORT_INITIALIZING)
471 case Fabric_Cntl_DID:
472 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
478 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
479 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE)
483 spin_unlock_irqrestore(&ndlp->lock, iflags);
485 /* Mark an NLP_IN_RECOV_POST_DEV_LOSS flag to know if reversing
486 * the following lpfc_nlp_put is necessary after fabric node is
490 lpfc_printf_vlog(vport, KERN_INFO,
491 LOG_DISCOVERY | LOG_NODE,
492 "8436 Devloss timeout marked on "
493 "DID x%x refcnt %d ndlp %p "
494 "flag x%x port_state = x%x\n",
495 ndlp->nlp_DID, kref_read(&ndlp->kref),
496 ndlp, ndlp->nlp_flag,
498 spin_lock_irqsave(&ndlp->lock, iflags);
499 ndlp->save_flags |= NLP_IN_RECOV_POST_DEV_LOSS;
500 spin_unlock_irqrestore(&ndlp->lock, iflags);
501 } else if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
502 /* Fabric node fully recovered before this dev_loss_tmo
503 * queue work is processed. Thus, ignore the
504 * dev_loss_tmo event.
506 lpfc_printf_vlog(vport, KERN_INFO,
507 LOG_DISCOVERY | LOG_NODE,
508 "8437 Devloss timeout ignored on "
509 "DID x%x refcnt %d ndlp %p "
510 "flag x%x port_state = x%x\n",
511 ndlp->nlp_DID, kref_read(&ndlp->kref),
512 ndlp, ndlp->nlp_flag,
521 if (ndlp->nlp_sid != NLP_NO_SID) {
523 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
527 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
528 "0203 Devloss timeout on "
529 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
530 "NPort x%06x Data: x%x x%x x%x refcnt %d\n",
531 *name, *(name+1), *(name+2), *(name+3),
532 *(name+4), *(name+5), *(name+6), *(name+7),
533 ndlp->nlp_DID, ndlp->nlp_flag,
534 ndlp->nlp_state, ndlp->nlp_rpi,
535 kref_read(&ndlp->kref));
537 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
538 "0204 Devloss timeout on "
539 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
540 "NPort x%06x Data: x%x x%x x%x\n",
541 *name, *(name+1), *(name+2), *(name+3),
542 *(name+4), *(name+5), *(name+6), *(name+7),
543 ndlp->nlp_DID, ndlp->nlp_flag,
544 ndlp->nlp_state, ndlp->nlp_rpi);
547 /* If we are devloss, but we are in the process of rediscovering the
548 * ndlp, don't issue a NLP_EVT_DEVICE_RM event.
550 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
551 ndlp->nlp_state <= NLP_STE_PRLI_ISSUE) {
555 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
556 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
561 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba)
563 struct lpfc_vport *vport;
564 struct lpfc_vport **vports;
567 vports = lpfc_create_vport_work_array(phba);
571 for (i = 0; i <= phba->max_vports; i++) {
572 if ((!vports[i]) && (i == 0))
579 if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) {
580 if (!lpfc_issue_els_qfpa(vport))
581 vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA;
584 lpfc_destroy_vport_work_array(phba, vports);
588 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
589 * @phba: Pointer to hba context object.
590 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
591 * @nlp_did: remote node identifer with devloss timeout.
593 * This function is called from the worker thread after invoking devloss
594 * timeout handler and releasing the reference count for the ndlp with
595 * which the devloss timeout was handled for SLI4 host. For the devloss
596 * timeout of the last remote node which had been in use of FCF, when this
597 * routine is invoked, it shall be guaranteed that none of the remote are
598 * in-use of FCF. When devloss timeout to the last remote using the FCF,
599 * if the FIP engine is neither in FCF table scan process nor roundrobin
600 * failover process, the in-use FCF shall be unregistered. If the FIP
601 * engine is in FCF discovery process, the devloss timeout state shall
602 * be set for either the FCF table scan process or roundrobin failover
603 * process to unregister the in-use FCF.
606 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
609 /* If devloss timeout happened to a remote node when FCF had no
610 * longer been in-use, do nothing.
615 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
616 spin_lock_irq(&phba->hbalock);
617 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
618 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
619 spin_unlock_irq(&phba->hbalock);
622 phba->hba_flag |= HBA_DEVLOSS_TMO;
623 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
624 "2847 Last remote node (x%x) using "
625 "FCF devloss tmo\n", nlp_did);
627 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
628 spin_unlock_irq(&phba->hbalock);
629 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
630 "2868 Devloss tmo to FCF rediscovery "
634 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
635 spin_unlock_irq(&phba->hbalock);
636 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
637 "2869 Devloss tmo to idle FIP engine, "
638 "unreg in-use FCF and rescan.\n");
639 /* Unregister in-use FCF and rescan */
640 lpfc_unregister_fcf_rescan(phba);
643 spin_unlock_irq(&phba->hbalock);
644 if (phba->hba_flag & FCF_TS_INPROG)
645 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
646 "2870 FCF table scan in progress\n");
647 if (phba->hba_flag & FCF_RR_INPROG)
648 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
649 "2871 FLOGI roundrobin FCF failover "
652 lpfc_unregister_unused_fcf(phba);
656 * lpfc_alloc_fast_evt - Allocates data structure for posting event
657 * @phba: Pointer to hba context object.
659 * This function is called from the functions which need to post
660 * events from interrupt context. This function allocates data
661 * structure required for posting event. It also keeps track of
662 * number of events pending and prevent event storm when there are
665 struct lpfc_fast_path_event *
666 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
667 struct lpfc_fast_path_event *ret;
669 /* If there are lot of fast event do not exhaust memory due to this */
670 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
673 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
676 atomic_inc(&phba->fast_event_count);
677 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
678 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
684 * lpfc_free_fast_evt - Frees event data structure
685 * @phba: Pointer to hba context object.
686 * @evt: Event object which need to be freed.
688 * This function frees the data structure required for posting
692 lpfc_free_fast_evt(struct lpfc_hba *phba,
693 struct lpfc_fast_path_event *evt) {
695 atomic_dec(&phba->fast_event_count);
700 * lpfc_send_fastpath_evt - Posts events generated from fast path
701 * @phba: Pointer to hba context object.
702 * @evtp: Event data structure.
704 * This function is called from worker thread, when the interrupt
705 * context need to post an event. This function posts the event
706 * to fc transport netlink interface.
709 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
710 struct lpfc_work_evt *evtp)
712 unsigned long evt_category, evt_sub_category;
713 struct lpfc_fast_path_event *fast_evt_data;
715 uint32_t evt_data_size;
716 struct Scsi_Host *shost;
718 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
721 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
722 evt_sub_category = (unsigned long) fast_evt_data->un.
723 fabric_evt.subcategory;
724 shost = lpfc_shost_from_vport(fast_evt_data->vport);
725 if (evt_category == FC_REG_FABRIC_EVENT) {
726 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
727 evt_data = (char *) &fast_evt_data->un.read_check_error;
728 evt_data_size = sizeof(fast_evt_data->un.
730 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
731 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
732 evt_data = (char *) &fast_evt_data->un.fabric_evt;
733 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
735 lpfc_free_fast_evt(phba, fast_evt_data);
738 } else if (evt_category == FC_REG_SCSI_EVENT) {
739 switch (evt_sub_category) {
740 case LPFC_EVENT_QFULL:
741 case LPFC_EVENT_DEVBSY:
742 evt_data = (char *) &fast_evt_data->un.scsi_evt;
743 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
745 case LPFC_EVENT_CHECK_COND:
746 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
747 evt_data_size = sizeof(fast_evt_data->un.
750 case LPFC_EVENT_VARQUEDEPTH:
751 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
752 evt_data_size = sizeof(fast_evt_data->un.
756 lpfc_free_fast_evt(phba, fast_evt_data);
760 lpfc_free_fast_evt(phba, fast_evt_data);
764 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
765 fc_host_post_vendor_event(shost,
766 fc_get_event_number(),
771 lpfc_free_fast_evt(phba, fast_evt_data);
776 lpfc_work_list_done(struct lpfc_hba *phba)
778 struct lpfc_work_evt *evtp = NULL;
779 struct lpfc_nodelist *ndlp;
785 spin_lock_irq(&phba->hbalock);
786 while (!list_empty(&phba->work_list)) {
787 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
789 spin_unlock_irq(&phba->hbalock);
790 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
793 case LPFC_EVT_ELS_RETRY:
794 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
796 lpfc_els_retry_delay_handler(ndlp);
797 free_evt = 0; /* evt is part of ndlp */
799 /* decrement the node reference count held
800 * for this queued work
804 case LPFC_EVT_DEV_LOSS:
805 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
806 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
808 /* decrement the node reference count held for
811 nlp_did = ndlp->nlp_DID;
813 if (phba->sli_rev == LPFC_SLI_REV4)
814 lpfc_sli4_post_dev_loss_tmo_handler(phba,
818 case LPFC_EVT_RECOVER_PORT:
819 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
821 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
824 /* decrement the node reference count held for
829 case LPFC_EVT_ONLINE:
830 if (phba->link_state < LPFC_LINK_DOWN)
831 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
833 *(int *) (evtp->evt_arg1) = 0;
834 complete((struct completion *)(evtp->evt_arg2));
836 case LPFC_EVT_OFFLINE_PREP:
837 if (phba->link_state >= LPFC_LINK_DOWN)
838 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
839 *(int *)(evtp->evt_arg1) = 0;
840 complete((struct completion *)(evtp->evt_arg2));
842 case LPFC_EVT_OFFLINE:
844 lpfc_sli_brdrestart(phba);
845 *(int *)(evtp->evt_arg1) =
846 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
847 lpfc_unblock_mgmt_io(phba);
848 complete((struct completion *)(evtp->evt_arg2));
850 case LPFC_EVT_WARM_START:
852 lpfc_reset_barrier(phba);
853 lpfc_sli_brdreset(phba);
854 lpfc_hba_down_post(phba);
855 *(int *)(evtp->evt_arg1) =
856 lpfc_sli_brdready(phba, HS_MBRDY);
857 lpfc_unblock_mgmt_io(phba);
858 complete((struct completion *)(evtp->evt_arg2));
862 *(int *)(evtp->evt_arg1)
863 = (phba->pport->stopped)
864 ? 0 : lpfc_sli_brdkill(phba);
865 lpfc_unblock_mgmt_io(phba);
866 complete((struct completion *)(evtp->evt_arg2));
868 case LPFC_EVT_FASTPATH_MGMT_EVT:
869 lpfc_send_fastpath_evt(phba, evtp);
872 case LPFC_EVT_RESET_HBA:
873 if (!(phba->pport->load_flag & FC_UNLOADING))
874 lpfc_reset_hba(phba);
879 spin_lock_irq(&phba->hbalock);
881 spin_unlock_irq(&phba->hbalock);
886 lpfc_work_done(struct lpfc_hba *phba)
888 struct lpfc_sli_ring *pring;
889 uint32_t ha_copy, status, control, work_port_events;
890 struct lpfc_vport **vports;
891 struct lpfc_vport *vport;
895 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
896 spin_lock_irq(&phba->hbalock);
897 ha_copy = phba->work_ha;
899 spin_unlock_irq(&phba->hbalock);
903 /* First, try to post the next mailbox command to SLI4 device */
904 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC && !hba_pci_err)
905 lpfc_sli4_post_async_mbox(phba);
907 if (ha_copy & HA_ERATT) {
908 /* Handle the error attention event */
909 lpfc_handle_eratt(phba);
911 if (phba->fw_dump_cmpl) {
912 complete(phba->fw_dump_cmpl);
913 phba->fw_dump_cmpl = NULL;
917 if (ha_copy & HA_MBATT)
918 lpfc_sli_handle_mb_event(phba);
920 if (ha_copy & HA_LATT)
921 lpfc_handle_latt(phba);
923 /* Handle VMID Events */
924 if (lpfc_is_vmid_enabled(phba) && !hba_pci_err) {
925 if (phba->pport->work_port_events &
926 WORKER_CHECK_VMID_ISSUE_QFPA) {
927 lpfc_check_vmid_qfpa_issue(phba);
928 phba->pport->work_port_events &=
929 ~WORKER_CHECK_VMID_ISSUE_QFPA;
931 if (phba->pport->work_port_events &
932 WORKER_CHECK_INACTIVE_VMID) {
933 lpfc_check_inactive_vmid(phba);
934 phba->pport->work_port_events &=
935 ~WORKER_CHECK_INACTIVE_VMID;
939 /* Process SLI4 events */
940 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
941 if (phba->hba_flag & HBA_RRQ_ACTIVE)
942 lpfc_handle_rrq_active(phba);
943 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
944 lpfc_sli4_els_xri_abort_event_proc(phba);
945 if (phba->hba_flag & ASYNC_EVENT)
946 lpfc_sli4_async_event_proc(phba);
947 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
948 spin_lock_irq(&phba->hbalock);
949 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
950 spin_unlock_irq(&phba->hbalock);
951 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
953 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
954 lpfc_sli4_fcf_redisc_event_proc(phba);
957 vports = lpfc_create_vport_work_array(phba);
959 for (i = 0; i <= phba->max_vports; i++) {
961 * We could have no vports in array if unloading, so if
962 * this happens then just use the pport
964 if (vports[i] == NULL && i == 0)
970 spin_lock_irq(&vport->work_port_lock);
971 work_port_events = vport->work_port_events;
972 vport->work_port_events &= ~work_port_events;
973 spin_unlock_irq(&vport->work_port_lock);
976 if (work_port_events & WORKER_DISC_TMO)
977 lpfc_disc_timeout_handler(vport);
978 if (work_port_events & WORKER_ELS_TMO)
979 lpfc_els_timeout_handler(vport);
980 if (work_port_events & WORKER_HB_TMO)
981 lpfc_hb_timeout_handler(phba);
982 if (work_port_events & WORKER_MBOX_TMO)
983 lpfc_mbox_timeout_handler(phba);
984 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
985 lpfc_unblock_fabric_iocbs(phba);
986 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
987 lpfc_ramp_down_queue_handler(phba);
988 if (work_port_events & WORKER_DELAYED_DISC_TMO)
989 lpfc_delayed_disc_timeout_handler(vport);
991 lpfc_destroy_vport_work_array(phba, vports);
993 pring = lpfc_phba_elsring(phba);
994 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
995 status >>= (4*LPFC_ELS_RING);
996 if (pring && (status & HA_RXMASK ||
997 pring->flag & LPFC_DEFERRED_RING_EVENT ||
998 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
999 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
1000 pring->flag |= LPFC_DEFERRED_RING_EVENT;
1001 /* Preserve legacy behavior. */
1002 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
1003 set_bit(LPFC_DATA_READY, &phba->data_flags);
1005 /* Driver could have abort request completed in queue
1006 * when link goes down. Allow for this transition.
1008 if (phba->link_state >= LPFC_LINK_DOWN ||
1009 phba->link_flag & LS_MDS_LOOPBACK) {
1010 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
1011 lpfc_sli_handle_slow_ring_event(phba, pring,
1016 if (phba->sli_rev == LPFC_SLI_REV4)
1017 lpfc_drain_txq(phba);
1019 * Turn on Ring interrupts
1021 if (phba->sli_rev <= LPFC_SLI_REV3) {
1022 spin_lock_irq(&phba->hbalock);
1023 control = readl(phba->HCregaddr);
1024 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
1025 lpfc_debugfs_slow_ring_trc(phba,
1026 "WRK Enable ring: cntl:x%x hacopy:x%x",
1027 control, ha_copy, 0);
1029 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
1030 writel(control, phba->HCregaddr);
1031 readl(phba->HCregaddr); /* flush */
1033 lpfc_debugfs_slow_ring_trc(phba,
1034 "WRK Ring ok: cntl:x%x hacopy:x%x",
1035 control, ha_copy, 0);
1037 spin_unlock_irq(&phba->hbalock);
1040 lpfc_work_list_done(phba);
1044 lpfc_do_work(void *p)
1046 struct lpfc_hba *phba = p;
1049 set_user_nice(current, MIN_NICE);
1050 current->flags |= PF_NOFREEZE;
1051 phba->data_flags = 0;
1053 while (!kthread_should_stop()) {
1054 /* wait and check worker queue activities */
1055 rc = wait_event_interruptible(phba->work_waitq,
1056 (test_and_clear_bit(LPFC_DATA_READY,
1058 || kthread_should_stop()));
1059 /* Signal wakeup shall terminate the worker thread */
1061 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1062 "0433 Wakeup on signal: rc=x%x\n", rc);
1066 /* Attend pending lpfc data processing */
1067 lpfc_work_done(phba);
1069 phba->worker_thread = NULL;
1070 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1071 "0432 Worker thread stopped.\n");
1076 * This is only called to handle FC worker events. Since this a rare
1077 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
1078 * embedding it in the IOCB.
1081 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
1084 struct lpfc_work_evt *evtp;
1085 unsigned long flags;
1088 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
1089 * be queued to worker thread for processing
1091 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
1095 evtp->evt_arg1 = arg1;
1096 evtp->evt_arg2 = arg2;
1099 spin_lock_irqsave(&phba->hbalock, flags);
1100 list_add_tail(&evtp->evt_listp, &phba->work_list);
1101 spin_unlock_irqrestore(&phba->hbalock, flags);
1103 lpfc_worker_wake_up(phba);
1109 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
1111 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1112 struct lpfc_hba *phba = vport->phba;
1113 struct lpfc_nodelist *ndlp, *next_ndlp;
1115 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1116 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
1117 /* It's possible the FLOGI to the fabric node never
1118 * successfully completed and never registered with the
1119 * transport. In this case there is no way to clean up
1122 if (ndlp->nlp_DID == Fabric_DID) {
1123 if (ndlp->nlp_prev_state ==
1124 NLP_STE_UNUSED_NODE &&
1125 !ndlp->fc4_xpt_flags)
1131 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
1132 ((vport->port_type == LPFC_NPIV_PORT) &&
1133 ((ndlp->nlp_DID == NameServer_DID) ||
1134 (ndlp->nlp_DID == FDMI_DID) ||
1135 (ndlp->nlp_DID == Fabric_Cntl_DID))))
1136 lpfc_unreg_rpi(vport, ndlp);
1138 /* Leave Fabric nodes alone on link down */
1139 if ((phba->sli_rev < LPFC_SLI_REV4) &&
1140 (!remove && ndlp->nlp_type & NLP_FABRIC))
1143 /* Notify transport of connectivity loss to trigger cleanup. */
1144 if (phba->nvmet_support &&
1145 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
1146 lpfc_nvmet_invalidate_host(phba, ndlp);
1148 lpfc_disc_state_machine(vport, ndlp, NULL,
1151 : NLP_EVT_DEVICE_RECOVERY);
1153 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
1154 if (phba->sli_rev == LPFC_SLI_REV4)
1155 lpfc_sli4_unreg_all_rpis(vport);
1156 lpfc_mbx_unreg_vpi(vport);
1157 spin_lock_irq(shost->host_lock);
1158 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1159 spin_unlock_irq(shost->host_lock);
1164 lpfc_port_link_failure(struct lpfc_vport *vport)
1166 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
1168 /* Cleanup any outstanding received buffers */
1169 lpfc_cleanup_rcv_buffers(vport);
1171 /* Cleanup any outstanding RSCN activity */
1172 lpfc_els_flush_rscn(vport);
1174 /* Cleanup any outstanding ELS commands */
1175 lpfc_els_flush_cmd(vport);
1177 lpfc_cleanup_rpis(vport, 0);
1179 /* Turn off discovery timer if its running */
1180 lpfc_can_disctmo(vport);
1184 lpfc_linkdown_port(struct lpfc_vport *vport)
1186 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1188 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1189 fc_host_post_event(shost, fc_get_event_number(),
1190 FCH_EVT_LINKDOWN, 0);
1192 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1193 "Link Down: state:x%x rtry:x%x flg:x%x",
1194 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1196 lpfc_port_link_failure(vport);
1198 /* Stop delayed Nport discovery */
1199 spin_lock_irq(shost->host_lock);
1200 vport->fc_flag &= ~FC_DISC_DELAYED;
1201 spin_unlock_irq(shost->host_lock);
1202 del_timer_sync(&vport->delayed_disc_tmo);
1206 lpfc_linkdown(struct lpfc_hba *phba)
1208 struct lpfc_vport *vport = phba->pport;
1209 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1210 struct lpfc_vport **vports;
1215 if (phba->link_state == LPFC_LINK_DOWN)
1218 /* Block all SCSI stack I/Os */
1219 lpfc_scsi_dev_block(phba);
1220 offline = pci_channel_offline(phba->pcidev);
1222 phba->defer_flogi_acc_flag = false;
1224 spin_lock_irq(&phba->hbalock);
1225 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1226 spin_unlock_irq(&phba->hbalock);
1227 if (phba->link_state > LPFC_LINK_DOWN) {
1228 phba->link_state = LPFC_LINK_DOWN;
1229 if (phba->sli4_hba.conf_trunk) {
1230 phba->trunk_link.link0.state = 0;
1231 phba->trunk_link.link1.state = 0;
1232 phba->trunk_link.link2.state = 0;
1233 phba->trunk_link.link3.state = 0;
1234 phba->sli4_hba.link_state.logical_speed =
1235 LPFC_LINK_SPEED_UNKNOWN;
1237 spin_lock_irq(shost->host_lock);
1238 phba->pport->fc_flag &= ~FC_LBIT;
1239 spin_unlock_irq(shost->host_lock);
1241 vports = lpfc_create_vport_work_array(phba);
1242 if (vports != NULL) {
1243 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1244 /* Issue a LINK DOWN event to all nodes */
1245 lpfc_linkdown_port(vports[i]);
1247 vports[i]->fc_myDID = 0;
1249 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1250 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1251 if (phba->nvmet_support)
1252 lpfc_nvmet_update_targetport(phba);
1254 lpfc_nvme_update_localport(vports[i]);
1258 lpfc_destroy_vport_work_array(phba, vports);
1260 /* Clean up any SLI3 firmware default rpi's */
1261 if (phba->sli_rev > LPFC_SLI_REV3 || offline)
1262 goto skip_unreg_did;
1264 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1266 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
1268 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1269 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1270 == MBX_NOT_FINISHED) {
1271 mempool_free(mb, phba->mbox_mem_pool);
1276 /* Setup myDID for link up if we are in pt2pt mode */
1277 if (phba->pport->fc_flag & FC_PT2PT) {
1278 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1280 lpfc_config_link(phba, mb);
1281 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);
1288 spin_lock_irq(shost->host_lock);
1289 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
1290 phba->pport->rcv_flogi_cnt = 0;
1291 spin_unlock_irq(shost->host_lock);
1297 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
1299 struct lpfc_nodelist *ndlp;
1301 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1302 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
1304 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1306 if (ndlp->nlp_type & NLP_FABRIC) {
1307 /* On Linkup its safe to clean up the ndlp
1308 * from Fabric connections.
1310 if (ndlp->nlp_DID != Fabric_DID)
1311 lpfc_unreg_rpi(vport, ndlp);
1312 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1313 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
1314 /* Fail outstanding IO now since device is
1317 lpfc_unreg_rpi(vport, ndlp);
1323 lpfc_linkup_port(struct lpfc_vport *vport)
1325 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1326 struct lpfc_hba *phba = vport->phba;
1328 if ((vport->load_flag & FC_UNLOADING) != 0)
1331 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1332 "Link Up: top:x%x speed:x%x flg:x%x",
1333 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1335 /* If NPIV is not enabled, only bring the physical port up */
1336 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1337 (vport != phba->pport))
1340 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1341 fc_host_post_event(shost, fc_get_event_number(),
1344 spin_lock_irq(shost->host_lock);
1345 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
1346 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
1347 vport->fc_flag |= FC_NDISC_ACTIVE;
1348 vport->fc_ns_retry = 0;
1349 spin_unlock_irq(shost->host_lock);
1351 lpfc_linkup_cleanup_nodes(vport);
1355 lpfc_linkup(struct lpfc_hba *phba)
1357 struct lpfc_vport **vports;
1359 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1361 phba->link_state = LPFC_LINK_UP;
1363 /* Unblock fabric iocbs if they are blocked */
1364 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1365 del_timer_sync(&phba->fabric_block_timer);
1367 vports = lpfc_create_vport_work_array(phba);
1369 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1370 lpfc_linkup_port(vports[i]);
1371 lpfc_destroy_vport_work_array(phba, vports);
1373 /* Clear the pport flogi counter in case the link down was
1374 * absorbed without an ACQE. No lock here - in worker thread
1375 * and discovery is synchronized.
1377 spin_lock_irq(shost->host_lock);
1378 phba->pport->rcv_flogi_cnt = 0;
1379 spin_unlock_irq(shost->host_lock);
1381 /* reinitialize initial FLOGI flag */
1382 phba->hba_flag &= ~(HBA_FLOGI_ISSUED);
1383 phba->defer_flogi_acc_flag = false;
1389 * This routine handles processing a CLEAR_LA mailbox
1390 * command upon completion. It is setup in the LPFC_MBOXQ
1391 * as the completion routine when the command is
1392 * handed off to the SLI layer. SLI3 only.
1395 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1397 struct lpfc_vport *vport = pmb->vport;
1398 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1399 struct lpfc_sli *psli = &phba->sli;
1400 MAILBOX_t *mb = &pmb->u.mb;
1403 /* Since we don't do discovery right now, turn these off here */
1404 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1405 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1407 /* Check for error */
1408 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1409 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1410 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1411 "0320 CLEAR_LA mbxStatus error x%x hba "
1413 mb->mbxStatus, vport->port_state);
1414 phba->link_state = LPFC_HBA_ERROR;
1418 if (vport->port_type == LPFC_PHYSICAL_PORT)
1419 phba->link_state = LPFC_HBA_READY;
1421 spin_lock_irq(&phba->hbalock);
1422 psli->sli_flag |= LPFC_PROCESS_LA;
1423 control = readl(phba->HCregaddr);
1424 control |= HC_LAINT_ENA;
1425 writel(control, phba->HCregaddr);
1426 readl(phba->HCregaddr); /* flush */
1427 spin_unlock_irq(&phba->hbalock);
1428 mempool_free(pmb, phba->mbox_mem_pool);
1432 /* Device Discovery completes */
1433 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1434 "0225 Device Discovery completes\n");
1435 mempool_free(pmb, phba->mbox_mem_pool);
1437 spin_lock_irq(shost->host_lock);
1438 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1439 spin_unlock_irq(shost->host_lock);
1441 lpfc_can_disctmo(vport);
1443 /* turn on Link Attention interrupts */
1445 spin_lock_irq(&phba->hbalock);
1446 psli->sli_flag |= LPFC_PROCESS_LA;
1447 control = readl(phba->HCregaddr);
1448 control |= HC_LAINT_ENA;
1449 writel(control, phba->HCregaddr);
1450 readl(phba->HCregaddr); /* flush */
1451 spin_unlock_irq(&phba->hbalock);
1457 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1459 struct lpfc_vport *vport = pmb->vport;
1460 LPFC_MBOXQ_t *sparam_mb;
1461 struct lpfc_dmabuf *sparam_mp;
1462 u16 status = pmb->u.mb.mbxStatus;
1465 mempool_free(pmb, phba->mbox_mem_pool);
1470 /* don't perform discovery for SLI4 loopback diagnostic test */
1471 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1472 !(phba->hba_flag & HBA_FCOE_MODE) &&
1473 (phba->link_flag & LS_LOOPBACK_MODE))
1476 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1477 vport->fc_flag & FC_PUBLIC_LOOP &&
1478 !(vport->fc_flag & FC_LBIT)) {
1479 /* Need to wait for FAN - use discovery timer
1480 * for timeout. port_state is identically
1481 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1483 lpfc_set_disctmo(vport);
1487 /* Start discovery by sending a FLOGI. port_state is identically
1488 * LPFC_FLOGI while waiting for FLOGI cmpl.
1490 if (vport->port_state != LPFC_FLOGI) {
1491 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1492 * bb-credit recovery is in place.
1494 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1495 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1496 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1501 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1503 mempool_free(sparam_mb, phba->mbox_mem_pool);
1506 sparam_mb->vport = vport;
1507 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1508 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1509 if (rc == MBX_NOT_FINISHED) {
1510 sparam_mp = (struct lpfc_dmabuf *)
1512 lpfc_mbuf_free(phba, sparam_mp->virt,
1515 sparam_mb->ctx_buf = NULL;
1516 mempool_free(sparam_mb, phba->mbox_mem_pool);
1520 phba->hba_flag |= HBA_DEFER_FLOGI;
1522 lpfc_initial_flogi(vport);
1525 if (vport->fc_flag & FC_PT2PT)
1526 lpfc_disc_start(vport);
1531 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1532 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1533 status, vport->port_state);
1536 lpfc_linkdown(phba);
1538 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1539 "0200 CONFIG_LINK bad hba state x%x\n",
1542 lpfc_issue_clear_la(phba, vport);
1547 * lpfc_sli4_clear_fcf_rr_bmask
1548 * @phba: pointer to the struct lpfc_hba for this port.
1549 * This fucnction resets the round robin bit mask and clears the
1550 * fcf priority list. The list deletions are done while holding the
1551 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1552 * from the lpfc_fcf_pri record.
1555 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1557 struct lpfc_fcf_pri *fcf_pri;
1558 struct lpfc_fcf_pri *next_fcf_pri;
1559 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1560 spin_lock_irq(&phba->hbalock);
1561 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1562 &phba->fcf.fcf_pri_list, list) {
1563 list_del_init(&fcf_pri->list);
1564 fcf_pri->fcf_rec.flag = 0;
1566 spin_unlock_irq(&phba->hbalock);
1569 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1571 struct lpfc_vport *vport = mboxq->vport;
1573 if (mboxq->u.mb.mbxStatus) {
1574 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1575 "2017 REG_FCFI mbxStatus error x%x "
1576 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1581 /* Start FCoE discovery by sending a FLOGI. */
1582 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1583 /* Set the FCFI registered flag */
1584 spin_lock_irq(&phba->hbalock);
1585 phba->fcf.fcf_flag |= FCF_REGISTERED;
1586 spin_unlock_irq(&phba->hbalock);
1588 /* If there is a pending FCoE event, restart FCF table scan. */
1589 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1590 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1593 /* Mark successful completion of FCF table scan */
1594 spin_lock_irq(&phba->hbalock);
1595 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1596 phba->hba_flag &= ~FCF_TS_INPROG;
1597 if (vport->port_state != LPFC_FLOGI) {
1598 phba->hba_flag |= FCF_RR_INPROG;
1599 spin_unlock_irq(&phba->hbalock);
1600 lpfc_issue_init_vfi(vport);
1603 spin_unlock_irq(&phba->hbalock);
1607 spin_lock_irq(&phba->hbalock);
1608 phba->hba_flag &= ~FCF_RR_INPROG;
1609 spin_unlock_irq(&phba->hbalock);
1611 mempool_free(mboxq, phba->mbox_mem_pool);
1615 * lpfc_fab_name_match - Check if the fcf fabric name match.
1616 * @fab_name: pointer to fabric name.
1617 * @new_fcf_record: pointer to fcf record.
1619 * This routine compare the fcf record's fabric name with provided
1620 * fabric name. If the fabric name are identical this function
1621 * returns 1 else return 0.
1624 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1626 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1628 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1630 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1632 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1634 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1636 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1638 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1640 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1646 * lpfc_sw_name_match - Check if the fcf switch name match.
1647 * @sw_name: pointer to switch name.
1648 * @new_fcf_record: pointer to fcf record.
1650 * This routine compare the fcf record's switch name with provided
1651 * switch name. If the switch name are identical this function
1652 * returns 1 else return 0.
1655 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1657 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1659 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1661 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1663 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1665 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1667 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1669 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1671 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1677 * lpfc_mac_addr_match - Check if the fcf mac address match.
1678 * @mac_addr: pointer to mac address.
1679 * @new_fcf_record: pointer to fcf record.
1681 * This routine compare the fcf record's mac address with HBA's
1682 * FCF mac address. If the mac addresses are identical this function
1683 * returns 1 else return 0.
1686 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1688 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1690 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1692 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1694 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1696 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1698 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1704 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1706 return (curr_vlan_id == new_vlan_id);
1710 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1711 * @phba: pointer to lpfc hba data structure.
1712 * @fcf_index: Index for the lpfc_fcf_record.
1713 * @new_fcf_record: pointer to hba fcf record.
1715 * This routine updates the driver FCF priority record from the new HBA FCF
1716 * record. The hbalock is asserted held in the code path calling this
1720 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1721 struct fcf_record *new_fcf_record
1724 struct lpfc_fcf_pri *fcf_pri;
1726 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1727 fcf_pri->fcf_rec.fcf_index = fcf_index;
1728 /* FCF record priority */
1729 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1734 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1735 * @fcf_rec: pointer to driver fcf record.
1736 * @new_fcf_record: pointer to fcf record.
1738 * This routine copies the FCF information from the FCF
1739 * record to lpfc_hba data structure.
1742 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1743 struct fcf_record *new_fcf_record)
1746 fcf_rec->fabric_name[0] =
1747 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1748 fcf_rec->fabric_name[1] =
1749 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1750 fcf_rec->fabric_name[2] =
1751 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1752 fcf_rec->fabric_name[3] =
1753 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1754 fcf_rec->fabric_name[4] =
1755 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1756 fcf_rec->fabric_name[5] =
1757 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1758 fcf_rec->fabric_name[6] =
1759 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1760 fcf_rec->fabric_name[7] =
1761 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1763 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1764 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1765 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1766 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1767 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1768 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1769 /* FCF record index */
1770 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1771 /* FCF record priority */
1772 fcf_rec->priority = new_fcf_record->fip_priority;
1774 fcf_rec->switch_name[0] =
1775 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1776 fcf_rec->switch_name[1] =
1777 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1778 fcf_rec->switch_name[2] =
1779 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1780 fcf_rec->switch_name[3] =
1781 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1782 fcf_rec->switch_name[4] =
1783 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1784 fcf_rec->switch_name[5] =
1785 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1786 fcf_rec->switch_name[6] =
1787 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1788 fcf_rec->switch_name[7] =
1789 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1793 * __lpfc_update_fcf_record - Update driver fcf record
1794 * @phba: pointer to lpfc hba data structure.
1795 * @fcf_rec: pointer to driver fcf record.
1796 * @new_fcf_record: pointer to hba fcf record.
1797 * @addr_mode: address mode to be set to the driver fcf record.
1798 * @vlan_id: vlan tag to be set to the driver fcf record.
1799 * @flag: flag bits to be set to the driver fcf record.
1801 * This routine updates the driver FCF record from the new HBA FCF record
1802 * together with the address mode, vlan_id, and other informations. This
1803 * routine is called with the hbalock held.
1806 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1807 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1808 uint16_t vlan_id, uint32_t flag)
1810 lockdep_assert_held(&phba->hbalock);
1812 /* Copy the fields from the HBA's FCF record */
1813 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1814 /* Update other fields of driver FCF record */
1815 fcf_rec->addr_mode = addr_mode;
1816 fcf_rec->vlan_id = vlan_id;
1817 fcf_rec->flag |= (flag | RECORD_VALID);
1818 __lpfc_update_fcf_record_pri(phba,
1819 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1824 * lpfc_register_fcf - Register the FCF with hba.
1825 * @phba: pointer to lpfc hba data structure.
1827 * This routine issues a register fcfi mailbox command to register
1831 lpfc_register_fcf(struct lpfc_hba *phba)
1833 LPFC_MBOXQ_t *fcf_mbxq;
1836 spin_lock_irq(&phba->hbalock);
1837 /* If the FCF is not available do nothing. */
1838 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1839 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1840 spin_unlock_irq(&phba->hbalock);
1844 /* The FCF is already registered, start discovery */
1845 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1846 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1847 phba->hba_flag &= ~FCF_TS_INPROG;
1848 if (phba->pport->port_state != LPFC_FLOGI &&
1849 phba->pport->fc_flag & FC_FABRIC) {
1850 phba->hba_flag |= FCF_RR_INPROG;
1851 spin_unlock_irq(&phba->hbalock);
1852 lpfc_initial_flogi(phba->pport);
1855 spin_unlock_irq(&phba->hbalock);
1858 spin_unlock_irq(&phba->hbalock);
1860 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1862 spin_lock_irq(&phba->hbalock);
1863 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1864 spin_unlock_irq(&phba->hbalock);
1868 lpfc_reg_fcfi(phba, fcf_mbxq);
1869 fcf_mbxq->vport = phba->pport;
1870 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1871 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1872 if (rc == MBX_NOT_FINISHED) {
1873 spin_lock_irq(&phba->hbalock);
1874 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1875 spin_unlock_irq(&phba->hbalock);
1876 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1883 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1884 * @phba: pointer to lpfc hba data structure.
1885 * @new_fcf_record: pointer to fcf record.
1886 * @boot_flag: Indicates if this record used by boot bios.
1887 * @addr_mode: The address mode to be used by this FCF
1888 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1890 * This routine compare the fcf record with connect list obtained from the
1891 * config region to decide if this FCF can be used for SAN discovery. It returns
1892 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1893 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1894 * is used by boot bios and addr_mode will indicate the addressing mode to be
1895 * used for this FCF when the function returns.
1896 * If the FCF record need to be used with a particular vlan id, the vlan is
1897 * set in the vlan_id on return of the function. If not VLAN tagging need to
1898 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1901 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1902 struct fcf_record *new_fcf_record,
1903 uint32_t *boot_flag, uint32_t *addr_mode,
1906 struct lpfc_fcf_conn_entry *conn_entry;
1907 int i, j, fcf_vlan_id = 0;
1909 /* Find the lowest VLAN id in the FCF record */
1910 for (i = 0; i < 512; i++) {
1911 if (new_fcf_record->vlan_bitmap[i]) {
1912 fcf_vlan_id = i * 8;
1914 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1922 /* FCF not valid/available or solicitation in progress */
1923 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1924 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1925 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1928 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1930 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1932 if (phba->valid_vlan)
1933 *vlan_id = phba->vlan_id;
1935 *vlan_id = LPFC_FCOE_NULL_VID;
1940 * If there are no FCF connection table entry, driver connect to all
1943 if (list_empty(&phba->fcf_conn_rec_list)) {
1945 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1949 * When there are no FCF connect entries, use driver's default
1950 * addressing mode - FPMA.
1952 if (*addr_mode & LPFC_FCF_FPMA)
1953 *addr_mode = LPFC_FCF_FPMA;
1955 /* If FCF record report a vlan id use that vlan id */
1957 *vlan_id = fcf_vlan_id;
1959 *vlan_id = LPFC_FCOE_NULL_VID;
1963 list_for_each_entry(conn_entry,
1964 &phba->fcf_conn_rec_list, list) {
1965 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1968 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1969 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1972 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1973 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1976 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1978 * If the vlan bit map does not have the bit set for the
1979 * vlan id to be used, then it is not a match.
1981 if (!(new_fcf_record->vlan_bitmap
1982 [conn_entry->conn_rec.vlan_tag / 8] &
1983 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1988 * If connection record does not support any addressing mode,
1989 * skip the FCF record.
1991 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1992 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1996 * Check if the connection record specifies a required
1999 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2000 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
2003 * If SPMA required but FCF not support this continue.
2005 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2006 !(bf_get(lpfc_fcf_record_mac_addr_prov,
2007 new_fcf_record) & LPFC_FCF_SPMA))
2011 * If FPMA required but FCF not support this continue.
2013 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2014 !(bf_get(lpfc_fcf_record_mac_addr_prov,
2015 new_fcf_record) & LPFC_FCF_FPMA))
2020 * This fcf record matches filtering criteria.
2022 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
2028 * If user did not specify any addressing mode, or if the
2029 * preferred addressing mode specified by user is not supported
2030 * by FCF, allow fabric to pick the addressing mode.
2032 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
2035 * If the user specified a required address mode, assign that
2038 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2039 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
2040 *addr_mode = (conn_entry->conn_rec.flags &
2042 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
2044 * If the user specified a preferred address mode, use the
2045 * addr mode only if FCF support the addr_mode.
2047 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2048 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2049 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2050 (*addr_mode & LPFC_FCF_SPMA))
2051 *addr_mode = LPFC_FCF_SPMA;
2052 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2053 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2054 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2055 (*addr_mode & LPFC_FCF_FPMA))
2056 *addr_mode = LPFC_FCF_FPMA;
2058 /* If matching connect list has a vlan id, use it */
2059 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
2060 *vlan_id = conn_entry->conn_rec.vlan_tag;
2062 * If no vlan id is specified in connect list, use the vlan id
2065 else if (fcf_vlan_id)
2066 *vlan_id = fcf_vlan_id;
2068 *vlan_id = LPFC_FCOE_NULL_VID;
2077 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
2078 * @phba: pointer to lpfc hba data structure.
2079 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
2081 * This function check if there is any fcoe event pending while driver
2082 * scan FCF entries. If there is any pending event, it will restart the
2083 * FCF saning and return 1 else return 0.
2086 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
2089 * If the Link is up and no FCoE events while in the
2090 * FCF discovery, no need to restart FCF discovery.
2092 if ((phba->link_state >= LPFC_LINK_UP) &&
2093 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
2096 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2097 "2768 Pending link or FCF event during current "
2098 "handling of the previous event: link_state:x%x, "
2099 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
2100 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
2101 phba->fcoe_eventtag);
2103 spin_lock_irq(&phba->hbalock);
2104 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
2105 spin_unlock_irq(&phba->hbalock);
2107 if (phba->link_state >= LPFC_LINK_UP) {
2108 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2109 "2780 Restart FCF table scan due to "
2110 "pending FCF event:evt_tag_at_scan:x%x, "
2111 "evt_tag_current:x%x\n",
2112 phba->fcoe_eventtag_at_fcf_scan,
2113 phba->fcoe_eventtag);
2114 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
2117 * Do not continue FCF discovery and clear FCF_TS_INPROG
2120 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2121 "2833 Stop FCF discovery process due to link "
2122 "state change (x%x)\n", phba->link_state);
2123 spin_lock_irq(&phba->hbalock);
2124 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
2125 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
2126 spin_unlock_irq(&phba->hbalock);
2129 /* Unregister the currently registered FCF if required */
2131 spin_lock_irq(&phba->hbalock);
2132 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
2133 spin_unlock_irq(&phba->hbalock);
2134 lpfc_sli4_unregister_fcf(phba);
2140 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
2141 * @phba: pointer to lpfc hba data structure.
2142 * @fcf_cnt: number of eligible fcf record seen so far.
2144 * This function makes an running random selection decision on FCF record to
2145 * use through a sequence of @fcf_cnt eligible FCF records with equal
2146 * probability. To perform integer manunipulation of random numbers with
2147 * size unit32_t, the lower 16 bits of the 32-bit random number returned
2148 * from prandom_u32() are taken as the random random number generated.
2150 * Returns true when outcome is for the newly read FCF record should be
2151 * chosen; otherwise, return false when outcome is for keeping the previously
2152 * chosen FCF record.
2155 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
2159 /* Get 16-bit uniform random number */
2160 rand_num = 0xFFFF & prandom_u32();
2162 /* Decision with probability 1/fcf_cnt */
2163 if ((fcf_cnt * rand_num) < 0xFFFF)
2170 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
2171 * @phba: pointer to lpfc hba data structure.
2172 * @mboxq: pointer to mailbox object.
2173 * @next_fcf_index: pointer to holder of next fcf index.
2175 * This routine parses the non-embedded fcf mailbox command by performing the
2176 * necessarily error checking, non-embedded read FCF record mailbox command
2177 * SGE parsing, and endianness swapping.
2179 * Returns the pointer to the new FCF record in the non-embedded mailbox
2180 * command DMA memory if successfully, other NULL.
2182 static struct fcf_record *
2183 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
2184 uint16_t *next_fcf_index)
2187 struct lpfc_mbx_sge sge;
2188 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2189 uint32_t shdr_status, shdr_add_status, if_type;
2190 union lpfc_sli4_cfg_shdr *shdr;
2191 struct fcf_record *new_fcf_record;
2193 /* Get the first SGE entry from the non-embedded DMA memory. This
2194 * routine only uses a single SGE.
2196 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2197 if (unlikely(!mboxq->sge_array)) {
2198 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2199 "2524 Failed to get the non-embedded SGE "
2200 "virtual address\n");
2203 virt_addr = mboxq->sge_array->addr[0];
2205 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
2206 lpfc_sli_pcimem_bcopy(shdr, shdr,
2207 sizeof(union lpfc_sli4_cfg_shdr));
2208 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2209 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2210 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2211 if (shdr_status || shdr_add_status) {
2212 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
2213 if_type == LPFC_SLI_INTF_IF_TYPE_2)
2214 lpfc_printf_log(phba, KERN_ERR,
2216 "2726 READ_FCF_RECORD Indicates empty "
2219 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2220 "2521 READ_FCF_RECORD mailbox failed "
2221 "with status x%x add_status x%x, "
2222 "mbx\n", shdr_status, shdr_add_status);
2226 /* Interpreting the returned information of the FCF record */
2227 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2228 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
2229 sizeof(struct lpfc_mbx_read_fcf_tbl));
2230 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
2231 new_fcf_record = (struct fcf_record *)(virt_addr +
2232 sizeof(struct lpfc_mbx_read_fcf_tbl));
2233 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
2234 offsetof(struct fcf_record, vlan_bitmap));
2235 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
2236 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
2238 return new_fcf_record;
2242 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
2243 * @phba: pointer to lpfc hba data structure.
2244 * @fcf_record: pointer to the fcf record.
2245 * @vlan_id: the lowest vlan identifier associated to this fcf record.
2246 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
2248 * This routine logs the detailed FCF record if the LOG_FIP loggin is
2252 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
2253 struct fcf_record *fcf_record,
2255 uint16_t next_fcf_index)
2257 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2258 "2764 READ_FCF_RECORD:\n"
2259 "\tFCF_Index : x%x\n"
2260 "\tFCF_Avail : x%x\n"
2261 "\tFCF_Valid : x%x\n"
2263 "\tFIP_Priority : x%x\n"
2264 "\tMAC_Provider : x%x\n"
2265 "\tLowest VLANID : x%x\n"
2266 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
2267 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2268 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2269 "\tNext_FCF_Index: x%x\n",
2270 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
2271 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
2272 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
2273 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
2274 fcf_record->fip_priority,
2275 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
2277 bf_get(lpfc_fcf_record_mac_0, fcf_record),
2278 bf_get(lpfc_fcf_record_mac_1, fcf_record),
2279 bf_get(lpfc_fcf_record_mac_2, fcf_record),
2280 bf_get(lpfc_fcf_record_mac_3, fcf_record),
2281 bf_get(lpfc_fcf_record_mac_4, fcf_record),
2282 bf_get(lpfc_fcf_record_mac_5, fcf_record),
2283 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
2284 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
2285 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
2286 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
2287 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
2288 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
2289 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
2290 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
2291 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
2292 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
2293 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
2294 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
2295 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
2296 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
2297 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
2298 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
2303 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
2304 * @phba: pointer to lpfc hba data structure.
2305 * @fcf_rec: pointer to an existing FCF record.
2306 * @new_fcf_record: pointer to a new FCF record.
2307 * @new_vlan_id: vlan id from the new FCF record.
2309 * This function performs matching test of a new FCF record against an existing
2310 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2311 * will not be used as part of the FCF record matching criteria.
2313 * Returns true if all the fields matching, otherwise returns false.
2316 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2317 struct lpfc_fcf_rec *fcf_rec,
2318 struct fcf_record *new_fcf_record,
2319 uint16_t new_vlan_id)
2321 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2322 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2324 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2326 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2328 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2330 if (fcf_rec->priority != new_fcf_record->fip_priority)
2336 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2337 * @vport: Pointer to vport object.
2338 * @fcf_index: index to next fcf.
2340 * This function processing the roundrobin fcf failover to next fcf index.
2341 * When this function is invoked, there will be a current fcf registered
2343 * Return: 0 for continue retrying flogi on currently registered fcf;
2344 * 1 for stop flogi on currently registered fcf;
2346 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2348 struct lpfc_hba *phba = vport->phba;
2351 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2352 spin_lock_irq(&phba->hbalock);
2353 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2354 spin_unlock_irq(&phba->hbalock);
2355 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2356 "2872 Devloss tmo with no eligible "
2357 "FCF, unregister in-use FCF (x%x) "
2358 "and rescan FCF table\n",
2359 phba->fcf.current_rec.fcf_indx);
2360 lpfc_unregister_fcf_rescan(phba);
2361 goto stop_flogi_current_fcf;
2363 /* Mark the end to FLOGI roundrobin failover */
2364 phba->hba_flag &= ~FCF_RR_INPROG;
2365 /* Allow action to new fcf asynchronous event */
2366 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2367 spin_unlock_irq(&phba->hbalock);
2368 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2369 "2865 No FCF available, stop roundrobin FCF "
2370 "failover and change port state:x%x/x%x\n",
2371 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2372 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2374 if (!phba->fcf.fcf_redisc_attempted) {
2375 lpfc_unregister_fcf(phba);
2377 rc = lpfc_sli4_redisc_fcf_table(phba);
2379 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2380 "3195 Rediscover FCF table\n");
2381 phba->fcf.fcf_redisc_attempted = 1;
2382 lpfc_sli4_clear_fcf_rr_bmask(phba);
2384 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2385 "3196 Rediscover FCF table "
2386 "failed. Status:x%x\n", rc);
2389 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2390 "3197 Already rediscover FCF table "
2391 "attempted. No more retry\n");
2393 goto stop_flogi_current_fcf;
2395 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2396 "2794 Try FLOGI roundrobin FCF failover to "
2397 "(x%x)\n", fcf_index);
2398 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2400 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2401 "2761 FLOGI roundrobin FCF failover "
2402 "failed (rc:x%x) to read FCF (x%x)\n",
2403 rc, phba->fcf.current_rec.fcf_indx);
2405 goto stop_flogi_current_fcf;
2409 stop_flogi_current_fcf:
2410 lpfc_can_disctmo(vport);
2415 * lpfc_sli4_fcf_pri_list_del
2416 * @phba: pointer to lpfc hba data structure.
2417 * @fcf_index: the index of the fcf record to delete
2418 * This routine checks the on list flag of the fcf_index to be deleted.
2419 * If it is one the list then it is removed from the list, and the flag
2420 * is cleared. This routine grab the hbalock before removing the fcf
2421 * record from the list.
2423 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2426 struct lpfc_fcf_pri *new_fcf_pri;
2428 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2429 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2430 "3058 deleting idx x%x pri x%x flg x%x\n",
2431 fcf_index, new_fcf_pri->fcf_rec.priority,
2432 new_fcf_pri->fcf_rec.flag);
2433 spin_lock_irq(&phba->hbalock);
2434 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2435 if (phba->fcf.current_rec.priority ==
2436 new_fcf_pri->fcf_rec.priority)
2437 phba->fcf.eligible_fcf_cnt--;
2438 list_del_init(&new_fcf_pri->list);
2439 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2441 spin_unlock_irq(&phba->hbalock);
2445 * lpfc_sli4_set_fcf_flogi_fail
2446 * @phba: pointer to lpfc hba data structure.
2447 * @fcf_index: the index of the fcf record to update
2448 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2449 * flag so the the round robin slection for the particular priority level
2450 * will try a different fcf record that does not have this bit set.
2451 * If the fcf record is re-read for any reason this flag is cleared brfore
2452 * adding it to the priority list.
2455 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2457 struct lpfc_fcf_pri *new_fcf_pri;
2458 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2459 spin_lock_irq(&phba->hbalock);
2460 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2461 spin_unlock_irq(&phba->hbalock);
2465 * lpfc_sli4_fcf_pri_list_add
2466 * @phba: pointer to lpfc hba data structure.
2467 * @fcf_index: the index of the fcf record to add
2468 * @new_fcf_record: pointer to a new FCF record.
2469 * This routine checks the priority of the fcf_index to be added.
2470 * If it is a lower priority than the current head of the fcf_pri list
2471 * then it is added to the list in the right order.
2472 * If it is the same priority as the current head of the list then it
2473 * is added to the head of the list and its bit in the rr_bmask is set.
2474 * If the fcf_index to be added is of a higher priority than the current
2475 * head of the list then the rr_bmask is cleared, its bit is set in the
2476 * rr_bmask and it is added to the head of the list.
2478 * 0=success 1=failure
2480 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2482 struct fcf_record *new_fcf_record)
2484 uint16_t current_fcf_pri;
2485 uint16_t last_index;
2486 struct lpfc_fcf_pri *fcf_pri;
2487 struct lpfc_fcf_pri *next_fcf_pri;
2488 struct lpfc_fcf_pri *new_fcf_pri;
2491 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2492 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2493 "3059 adding idx x%x pri x%x flg x%x\n",
2494 fcf_index, new_fcf_record->fip_priority,
2495 new_fcf_pri->fcf_rec.flag);
2496 spin_lock_irq(&phba->hbalock);
2497 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2498 list_del_init(&new_fcf_pri->list);
2499 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2500 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2501 if (list_empty(&phba->fcf.fcf_pri_list)) {
2502 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2503 ret = lpfc_sli4_fcf_rr_index_set(phba,
2504 new_fcf_pri->fcf_rec.fcf_index);
2508 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2509 LPFC_SLI4_FCF_TBL_INDX_MAX);
2510 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2511 ret = 0; /* Empty rr list */
2514 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2515 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2516 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2517 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2518 memset(phba->fcf.fcf_rr_bmask, 0,
2519 sizeof(*phba->fcf.fcf_rr_bmask));
2520 /* fcfs_at_this_priority_level = 1; */
2521 phba->fcf.eligible_fcf_cnt = 1;
2523 /* fcfs_at_this_priority_level++; */
2524 phba->fcf.eligible_fcf_cnt++;
2525 ret = lpfc_sli4_fcf_rr_index_set(phba,
2526 new_fcf_pri->fcf_rec.fcf_index);
2530 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2531 &phba->fcf.fcf_pri_list, list) {
2532 if (new_fcf_pri->fcf_rec.priority <=
2533 fcf_pri->fcf_rec.priority) {
2534 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2535 list_add(&new_fcf_pri->list,
2536 &phba->fcf.fcf_pri_list);
2538 list_add(&new_fcf_pri->list,
2539 &((struct lpfc_fcf_pri *)
2540 fcf_pri->list.prev)->list);
2543 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2544 || new_fcf_pri->fcf_rec.priority <
2545 next_fcf_pri->fcf_rec.priority) {
2546 list_add(&new_fcf_pri->list, &fcf_pri->list);
2550 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2556 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2557 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2558 spin_unlock_irq(&phba->hbalock);
2563 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2564 * @phba: pointer to lpfc hba data structure.
2565 * @mboxq: pointer to mailbox object.
2567 * This function iterates through all the fcf records available in
2568 * HBA and chooses the optimal FCF record for discovery. After finding
2569 * the FCF for discovery it registers the FCF record and kicks start
2571 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2572 * use an FCF record which matches fabric name and mac address of the
2573 * currently used FCF record.
2574 * If the driver supports only one FCF, it will try to use the FCF record
2575 * used by BOOT_BIOS.
2578 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2580 struct fcf_record *new_fcf_record;
2581 uint32_t boot_flag, addr_mode;
2582 uint16_t fcf_index, next_fcf_index;
2583 struct lpfc_fcf_rec *fcf_rec = NULL;
2584 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2585 bool select_new_fcf;
2588 /* If there is pending FCoE event restart FCF table scan */
2589 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2590 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2594 /* Parse the FCF record from the non-embedded mailbox command */
2595 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2597 if (!new_fcf_record) {
2598 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2599 "2765 Mailbox command READ_FCF_RECORD "
2600 "failed to retrieve a FCF record.\n");
2601 /* Let next new FCF event trigger fast failover */
2602 spin_lock_irq(&phba->hbalock);
2603 phba->hba_flag &= ~FCF_TS_INPROG;
2604 spin_unlock_irq(&phba->hbalock);
2605 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2609 /* Check the FCF record against the connection list */
2610 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2611 &addr_mode, &vlan_id);
2613 /* Log the FCF record information if turned on */
2614 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2618 * If the fcf record does not match with connect list entries
2619 * read the next entry; otherwise, this is an eligible FCF
2620 * record for roundrobin FCF failover.
2623 lpfc_sli4_fcf_pri_list_del(phba,
2624 bf_get(lpfc_fcf_record_fcf_index,
2626 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2627 "2781 FCF (x%x) failed connection "
2628 "list check: (x%x/x%x/%x)\n",
2629 bf_get(lpfc_fcf_record_fcf_index,
2631 bf_get(lpfc_fcf_record_fcf_avail,
2633 bf_get(lpfc_fcf_record_fcf_valid,
2635 bf_get(lpfc_fcf_record_fcf_sol,
2637 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2638 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2639 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2640 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2641 phba->fcf.current_rec.fcf_indx) {
2642 lpfc_printf_log(phba, KERN_ERR,
2644 "2862 FCF (x%x) matches property "
2645 "of in-use FCF (x%x)\n",
2646 bf_get(lpfc_fcf_record_fcf_index,
2648 phba->fcf.current_rec.fcf_indx);
2652 * In case the current in-use FCF record becomes
2653 * invalid/unavailable during FCF discovery that
2654 * was not triggered by fast FCF failover process,
2655 * treat it as fast FCF failover.
2657 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2658 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2659 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2660 "2835 Invalid in-use FCF "
2661 "(x%x), enter FCF failover "
2663 phba->fcf.current_rec.fcf_indx);
2664 spin_lock_irq(&phba->hbalock);
2665 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2666 spin_unlock_irq(&phba->hbalock);
2667 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2668 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2669 LPFC_FCOE_FCF_GET_FIRST);
2675 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2676 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2683 * If this is not the first FCF discovery of the HBA, use last
2684 * FCF record for the discovery. The condition that a rescan
2685 * matches the in-use FCF record: fabric name, switch name, mac
2686 * address, and vlan_id.
2688 spin_lock_irq(&phba->hbalock);
2689 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2690 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2691 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2692 new_fcf_record, vlan_id)) {
2693 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2694 phba->fcf.current_rec.fcf_indx) {
2695 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2696 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2697 /* Stop FCF redisc wait timer */
2698 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2700 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2701 /* Fast failover, mark completed */
2702 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2703 spin_unlock_irq(&phba->hbalock);
2704 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2705 "2836 New FCF matches in-use "
2706 "FCF (x%x), port_state:x%x, "
2708 phba->fcf.current_rec.fcf_indx,
2709 phba->pport->port_state,
2710 phba->pport->fc_flag);
2713 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2714 "2863 New FCF (x%x) matches "
2715 "property of in-use FCF (x%x)\n",
2716 bf_get(lpfc_fcf_record_fcf_index,
2718 phba->fcf.current_rec.fcf_indx);
2721 * Read next FCF record from HBA searching for the matching
2722 * with in-use record only if not during the fast failover
2723 * period. In case of fast failover period, it shall try to
2724 * determine whether the FCF record just read should be the
2727 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2728 spin_unlock_irq(&phba->hbalock);
2733 * Update on failover FCF record only if it's in FCF fast-failover
2734 * period; otherwise, update on current FCF record.
2736 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2737 fcf_rec = &phba->fcf.failover_rec;
2739 fcf_rec = &phba->fcf.current_rec;
2741 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2743 * If the driver FCF record does not have boot flag
2744 * set and new hba fcf record has boot flag set, use
2745 * the new hba fcf record.
2747 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2748 /* Choose this FCF record */
2749 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2750 "2837 Update current FCF record "
2751 "(x%x) with new FCF record (x%x)\n",
2753 bf_get(lpfc_fcf_record_fcf_index,
2755 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2756 addr_mode, vlan_id, BOOT_ENABLE);
2757 spin_unlock_irq(&phba->hbalock);
2761 * If the driver FCF record has boot flag set and the
2762 * new hba FCF record does not have boot flag, read
2763 * the next FCF record.
2765 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2766 spin_unlock_irq(&phba->hbalock);
2770 * If the new hba FCF record has lower priority value
2771 * than the driver FCF record, use the new record.
2773 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2774 /* Choose the new FCF record with lower priority */
2775 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2776 "2838 Update current FCF record "
2777 "(x%x) with new FCF record (x%x)\n",
2779 bf_get(lpfc_fcf_record_fcf_index,
2781 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2782 addr_mode, vlan_id, 0);
2783 /* Reset running random FCF selection count */
2784 phba->fcf.eligible_fcf_cnt = 1;
2785 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2786 /* Update running random FCF selection count */
2787 phba->fcf.eligible_fcf_cnt++;
2788 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2789 phba->fcf.eligible_fcf_cnt);
2790 if (select_new_fcf) {
2791 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2792 "2839 Update current FCF record "
2793 "(x%x) with new FCF record (x%x)\n",
2795 bf_get(lpfc_fcf_record_fcf_index,
2797 /* Choose the new FCF by random selection */
2798 __lpfc_update_fcf_record(phba, fcf_rec,
2800 addr_mode, vlan_id, 0);
2803 spin_unlock_irq(&phba->hbalock);
2807 * This is the first suitable FCF record, choose this record for
2808 * initial best-fit FCF.
2811 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2812 "2840 Update initial FCF candidate "
2814 bf_get(lpfc_fcf_record_fcf_index,
2816 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2817 addr_mode, vlan_id, (boot_flag ?
2819 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2820 /* Setup initial running random FCF selection count */
2821 phba->fcf.eligible_fcf_cnt = 1;
2823 spin_unlock_irq(&phba->hbalock);
2827 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2828 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2829 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2831 * Case of FCF fast failover scan
2835 * It has not found any suitable FCF record, cancel
2836 * FCF scan inprogress, and do nothing
2838 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2839 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2840 "2782 No suitable FCF found: "
2842 phba->fcoe_eventtag_at_fcf_scan,
2843 bf_get(lpfc_fcf_record_fcf_index,
2845 spin_lock_irq(&phba->hbalock);
2846 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2847 phba->hba_flag &= ~FCF_TS_INPROG;
2848 spin_unlock_irq(&phba->hbalock);
2849 /* Unregister in-use FCF and rescan */
2850 lpfc_printf_log(phba, KERN_INFO,
2852 "2864 On devloss tmo "
2853 "unreg in-use FCF and "
2854 "rescan FCF table\n");
2855 lpfc_unregister_fcf_rescan(phba);
2859 * Let next new FCF event trigger fast failover
2861 phba->hba_flag &= ~FCF_TS_INPROG;
2862 spin_unlock_irq(&phba->hbalock);
2866 * It has found a suitable FCF record that is not
2867 * the same as in-use FCF record, unregister the
2868 * in-use FCF record, replace the in-use FCF record
2869 * with the new FCF record, mark FCF fast failover
2870 * completed, and then start register the new FCF
2874 /* Unregister the current in-use FCF record */
2875 lpfc_unregister_fcf(phba);
2877 /* Replace in-use record with the new record */
2878 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2879 "2842 Replace in-use FCF (x%x) "
2880 "with failover FCF (x%x)\n",
2881 phba->fcf.current_rec.fcf_indx,
2882 phba->fcf.failover_rec.fcf_indx);
2883 memcpy(&phba->fcf.current_rec,
2884 &phba->fcf.failover_rec,
2885 sizeof(struct lpfc_fcf_rec));
2887 * Mark the fast FCF failover rediscovery completed
2888 * and the start of the first round of the roundrobin
2891 spin_lock_irq(&phba->hbalock);
2892 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2893 spin_unlock_irq(&phba->hbalock);
2894 /* Register to the new FCF record */
2895 lpfc_register_fcf(phba);
2898 * In case of transaction period to fast FCF failover,
2899 * do nothing when search to the end of the FCF table.
2901 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2902 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2905 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2906 phba->fcf.fcf_flag & FCF_IN_USE) {
2908 * In case the current in-use FCF record no
2909 * longer existed during FCF discovery that
2910 * was not triggered by fast FCF failover
2911 * process, treat it as fast FCF failover.
2913 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2914 "2841 In-use FCF record (x%x) "
2915 "not reported, entering fast "
2916 "FCF failover mode scanning.\n",
2917 phba->fcf.current_rec.fcf_indx);
2918 spin_lock_irq(&phba->hbalock);
2919 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2920 spin_unlock_irq(&phba->hbalock);
2921 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2922 LPFC_FCOE_FCF_GET_FIRST);
2925 /* Register to the new FCF record */
2926 lpfc_register_fcf(phba);
2929 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2933 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2934 lpfc_register_fcf(phba);
2940 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2941 * @phba: pointer to lpfc hba data structure.
2942 * @mboxq: pointer to mailbox object.
2944 * This is the callback function for FLOGI failure roundrobin FCF failover
2945 * read FCF record mailbox command from the eligible FCF record bmask for
2946 * performing the failover. If the FCF read back is not valid/available, it
2947 * fails through to retrying FLOGI to the currently registered FCF again.
2948 * Otherwise, if the FCF read back is valid and available, it will set the
2949 * newly read FCF record to the failover FCF record, unregister currently
2950 * registered FCF record, copy the failover FCF record to the current
2951 * FCF record, and then register the current FCF record before proceeding
2952 * to trying FLOGI on the new failover FCF.
2955 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2957 struct fcf_record *new_fcf_record;
2958 uint32_t boot_flag, addr_mode;
2959 uint16_t next_fcf_index, fcf_index;
2960 uint16_t current_fcf_index;
2964 /* If link state is not up, stop the roundrobin failover process */
2965 if (phba->link_state < LPFC_LINK_UP) {
2966 spin_lock_irq(&phba->hbalock);
2967 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2968 phba->hba_flag &= ~FCF_RR_INPROG;
2969 spin_unlock_irq(&phba->hbalock);
2973 /* Parse the FCF record from the non-embedded mailbox command */
2974 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2976 if (!new_fcf_record) {
2977 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2978 "2766 Mailbox command READ_FCF_RECORD "
2979 "failed to retrieve a FCF record. "
2980 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
2981 phba->fcf.fcf_flag);
2982 lpfc_unregister_fcf_rescan(phba);
2986 /* Get the needed parameters from FCF record */
2987 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2988 &addr_mode, &vlan_id);
2990 /* Log the FCF record information if turned on */
2991 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2994 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2996 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2997 "2848 Remove ineligible FCF (x%x) from "
2998 "from roundrobin bmask\n", fcf_index);
2999 /* Clear roundrobin bmask bit for ineligible FCF */
3000 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
3001 /* Perform next round of roundrobin FCF failover */
3002 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
3003 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
3009 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
3010 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3011 "2760 Perform FLOGI roundrobin FCF failover: "
3012 "FCF (x%x) back to FCF (x%x)\n",
3013 phba->fcf.current_rec.fcf_indx, fcf_index);
3014 /* Wait 500 ms before retrying FLOGI to current FCF */
3016 lpfc_issue_init_vfi(phba->pport);
3020 /* Upload new FCF record to the failover FCF record */
3021 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3022 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
3023 phba->fcf.failover_rec.fcf_indx, fcf_index);
3024 spin_lock_irq(&phba->hbalock);
3025 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
3026 new_fcf_record, addr_mode, vlan_id,
3027 (boot_flag ? BOOT_ENABLE : 0));
3028 spin_unlock_irq(&phba->hbalock);
3030 current_fcf_index = phba->fcf.current_rec.fcf_indx;
3032 /* Unregister the current in-use FCF record */
3033 lpfc_unregister_fcf(phba);
3035 /* Replace in-use record with the new record */
3036 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
3037 sizeof(struct lpfc_fcf_rec));
3039 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3040 "2783 Perform FLOGI roundrobin FCF failover: FCF "
3041 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
3044 lpfc_register_fcf(phba);
3046 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3050 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
3051 * @phba: pointer to lpfc hba data structure.
3052 * @mboxq: pointer to mailbox object.
3054 * This is the callback function of read FCF record mailbox command for
3055 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
3056 * failover when a new FCF event happened. If the FCF read back is
3057 * valid/available and it passes the connection list check, it updates
3058 * the bmask for the eligible FCF record for roundrobin failover.
3061 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3063 struct fcf_record *new_fcf_record;
3064 uint32_t boot_flag, addr_mode;
3065 uint16_t fcf_index, next_fcf_index;
3069 /* If link state is not up, no need to proceed */
3070 if (phba->link_state < LPFC_LINK_UP)
3073 /* If FCF discovery period is over, no need to proceed */
3074 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
3077 /* Parse the FCF record from the non-embedded mailbox command */
3078 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
3080 if (!new_fcf_record) {
3081 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3082 "2767 Mailbox command READ_FCF_RECORD "
3083 "failed to retrieve a FCF record.\n");
3087 /* Check the connection list for eligibility */
3088 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3089 &addr_mode, &vlan_id);
3091 /* Log the FCF record information if turned on */
3092 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3098 /* Update the eligible FCF record index bmask */
3099 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
3101 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
3104 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3108 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
3109 * @phba: pointer to lpfc hba data structure.
3110 * @mboxq: pointer to mailbox data structure.
3112 * This function handles completion of init vfi mailbox command.
3115 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3117 struct lpfc_vport *vport = mboxq->vport;
3120 * VFI not supported on interface type 0, just do the flogi
3121 * Also continue if the VFI is in use - just use the same one.
3123 if (mboxq->u.mb.mbxStatus &&
3124 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3125 LPFC_SLI_INTF_IF_TYPE_0) &&
3126 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3127 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3128 "2891 Init VFI mailbox failed 0x%x\n",
3129 mboxq->u.mb.mbxStatus);
3130 mempool_free(mboxq, phba->mbox_mem_pool);
3131 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3135 lpfc_initial_flogi(vport);
3136 mempool_free(mboxq, phba->mbox_mem_pool);
3141 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
3142 * @vport: pointer to lpfc_vport data structure.
3144 * This function issue a init_vfi mailbox command to initialize the VFI and
3145 * VPI for the physical port.
3148 lpfc_issue_init_vfi(struct lpfc_vport *vport)
3150 LPFC_MBOXQ_t *mboxq;
3152 struct lpfc_hba *phba = vport->phba;
3154 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3156 lpfc_printf_vlog(vport, KERN_ERR,
3157 LOG_TRACE_EVENT, "2892 Failed to allocate "
3158 "init_vfi mailbox\n");
3161 lpfc_init_vfi(mboxq, vport);
3162 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
3163 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
3164 if (rc == MBX_NOT_FINISHED) {
3165 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3166 "2893 Failed to issue init_vfi mailbox\n");
3167 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3172 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
3173 * @phba: pointer to lpfc hba data structure.
3174 * @mboxq: pointer to mailbox data structure.
3176 * This function handles completion of init vpi mailbox command.
3179 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3181 struct lpfc_vport *vport = mboxq->vport;
3182 struct lpfc_nodelist *ndlp;
3183 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3185 if (mboxq->u.mb.mbxStatus) {
3186 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3187 "2609 Init VPI mailbox failed 0x%x\n",
3188 mboxq->u.mb.mbxStatus);
3189 mempool_free(mboxq, phba->mbox_mem_pool);
3190 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3193 spin_lock_irq(shost->host_lock);
3194 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3195 spin_unlock_irq(shost->host_lock);
3197 /* If this port is physical port or FDISC is done, do reg_vpi */
3198 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
3199 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3201 lpfc_printf_vlog(vport, KERN_ERR,
3203 "2731 Cannot find fabric "
3204 "controller node\n");
3206 lpfc_register_new_vport(phba, vport, ndlp);
3207 mempool_free(mboxq, phba->mbox_mem_pool);
3211 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3212 lpfc_initial_fdisc(vport);
3214 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
3215 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3216 "2606 No NPIV Fabric support\n");
3218 mempool_free(mboxq, phba->mbox_mem_pool);
3223 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
3224 * @vport: pointer to lpfc_vport data structure.
3226 * This function issue a init_vpi mailbox command to initialize
3227 * VPI for the vport.
3230 lpfc_issue_init_vpi(struct lpfc_vport *vport)
3232 LPFC_MBOXQ_t *mboxq;
3235 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
3236 vpi = lpfc_alloc_vpi(vport->phba);
3238 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3239 "3303 Failed to obtain vport vpi\n");
3240 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3246 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
3248 lpfc_printf_vlog(vport, KERN_ERR,
3249 LOG_TRACE_EVENT, "2607 Failed to allocate "
3250 "init_vpi mailbox\n");
3253 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
3254 mboxq->vport = vport;
3255 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
3256 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
3257 if (rc == MBX_NOT_FINISHED) {
3258 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3259 "2608 Failed to issue init_vpi mailbox\n");
3260 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3265 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
3266 * @phba: pointer to lpfc hba data structure.
3268 * This function loops through the list of vports on the @phba and issues an
3269 * FDISC if possible.
3272 lpfc_start_fdiscs(struct lpfc_hba *phba)
3274 struct lpfc_vport **vports;
3277 vports = lpfc_create_vport_work_array(phba);
3278 if (vports != NULL) {
3279 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3280 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
3282 /* There are no vpi for this vport */
3283 if (vports[i]->vpi > phba->max_vpi) {
3284 lpfc_vport_set_state(vports[i],
3288 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3289 lpfc_vport_set_state(vports[i],
3293 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
3294 lpfc_issue_init_vpi(vports[i]);
3297 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3298 lpfc_initial_fdisc(vports[i]);
3300 lpfc_vport_set_state(vports[i],
3301 FC_VPORT_NO_FABRIC_SUPP);
3302 lpfc_printf_vlog(vports[i], KERN_ERR,
3305 "Fabric support\n");
3309 lpfc_destroy_vport_work_array(phba, vports);
3313 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3315 struct lpfc_dmabuf *dmabuf = mboxq->ctx_buf;
3316 struct lpfc_vport *vport = mboxq->vport;
3317 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3320 * VFI not supported for interface type 0, so ignore any mailbox
3321 * error (except VFI in use) and continue with the discovery.
3323 if (mboxq->u.mb.mbxStatus &&
3324 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3325 LPFC_SLI_INTF_IF_TYPE_0) &&
3326 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3327 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3328 "2018 REG_VFI mbxStatus error x%x "
3330 mboxq->u.mb.mbxStatus, vport->port_state);
3331 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3332 /* FLOGI failed, use loop map to make discovery list */
3333 lpfc_disc_list_loopmap(vport);
3334 /* Start discovery */
3335 lpfc_disc_start(vport);
3338 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3342 /* If the VFI is already registered, there is nothing else to do
3343 * Unless this was a VFI update and we are in PT2PT mode, then
3344 * we should drop through to set the port state to ready.
3346 if (vport->fc_flag & FC_VFI_REGISTERED)
3347 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3348 vport->fc_flag & FC_PT2PT))
3351 /* The VPI is implicitly registered when the VFI is registered */
3352 spin_lock_irq(shost->host_lock);
3353 vport->vpi_state |= LPFC_VPI_REGISTERED;
3354 vport->fc_flag |= FC_VFI_REGISTERED;
3355 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3356 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3357 spin_unlock_irq(shost->host_lock);
3359 /* In case SLI4 FC loopback test, we are ready */
3360 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3361 (phba->link_flag & LS_LOOPBACK_MODE)) {
3362 phba->link_state = LPFC_HBA_READY;
3366 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3367 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3368 "alpacnt:%d LinkState:%x topology:%x\n",
3369 vport->port_state, vport->fc_flag, vport->fc_myDID,
3370 vport->phba->alpa_map[0],
3371 phba->link_state, phba->fc_topology);
3373 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3375 * For private loop or for NPort pt2pt,
3376 * just start discovery and we are done.
3378 if ((vport->fc_flag & FC_PT2PT) ||
3379 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3380 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3382 /* Use loop map to make discovery list */
3383 lpfc_disc_list_loopmap(vport);
3384 /* Start discovery */
3385 if (vport->fc_flag & FC_PT2PT)
3386 vport->port_state = LPFC_VPORT_READY;
3388 lpfc_disc_start(vport);
3390 lpfc_start_fdiscs(phba);
3391 lpfc_do_scr_ns_plogi(phba, vport);
3396 mempool_free(mboxq, phba->mbox_mem_pool);
3398 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
3405 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3407 MAILBOX_t *mb = &pmb->u.mb;
3408 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3409 struct lpfc_vport *vport = pmb->vport;
3410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3411 struct serv_parm *sp = &vport->fc_sparam;
3414 /* Check for error */
3415 if (mb->mbxStatus) {
3416 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3417 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3418 "0319 READ_SPARAM mbxStatus error x%x "
3420 mb->mbxStatus, vport->port_state);
3421 lpfc_linkdown(phba);
3425 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3426 sizeof (struct serv_parm));
3428 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3429 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3430 ed_tov = (ed_tov + 999999) / 1000000;
3432 phba->fc_edtov = ed_tov;
3433 phba->fc_ratov = (2 * ed_tov) / 1000;
3434 if (phba->fc_ratov < FF_DEF_RATOV) {
3435 /* RA_TOV should be atleast 10sec for initial flogi */
3436 phba->fc_ratov = FF_DEF_RATOV;
3439 lpfc_update_vport_wwn(vport);
3440 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3441 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3442 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3443 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3446 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3448 mempool_free(pmb, phba->mbox_mem_pool);
3450 /* Check if sending the FLOGI is being deferred to after we get
3451 * up to date CSPs from MBX_READ_SPARAM.
3453 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3454 lpfc_initial_flogi(vport);
3455 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3460 pmb->ctx_buf = NULL;
3461 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3463 lpfc_issue_clear_la(phba, vport);
3464 mempool_free(pmb, phba->mbox_mem_pool);
3469 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3471 struct lpfc_vport *vport = phba->pport;
3472 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3473 struct Scsi_Host *shost;
3475 struct lpfc_dmabuf *mp;
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 mp = (struct lpfc_dmabuf *)sparam_mbox->ctx_buf;
3604 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3606 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3610 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3611 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3614 vport->port_state = LPFC_LOCAL_CFG_LINK;
3615 lpfc_config_link(phba, cfglink_mbox);
3616 cfglink_mbox->vport = vport;
3617 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3618 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3619 if (rc == MBX_NOT_FINISHED) {
3620 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3624 vport->port_state = LPFC_VPORT_UNKNOWN;
3626 * Add the driver's default FCF record at FCF index 0 now. This
3627 * is phase 1 implementation that support FCF index 0 and driver
3630 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3631 fcf_record = kzalloc(sizeof(struct fcf_record),
3633 if (unlikely(!fcf_record)) {
3634 lpfc_printf_log(phba, KERN_ERR,
3636 "2554 Could not allocate memory for "
3642 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3643 LPFC_FCOE_FCF_DEF_INDEX);
3644 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3646 lpfc_printf_log(phba, KERN_ERR,
3648 "2013 Could not manually add FCF "
3649 "record 0, status %d\n", rc);
3657 * The driver is expected to do FIP/FCF. Call the port
3658 * and get the FCF Table.
3660 spin_lock_irqsave(&phba->hbalock, iflags);
3661 if (phba->hba_flag & FCF_TS_INPROG) {
3662 spin_unlock_irqrestore(&phba->hbalock, iflags);
3665 /* This is the initial FCF discovery scan */
3666 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3667 spin_unlock_irqrestore(&phba->hbalock, iflags);
3668 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3669 "2778 Start FCF table scan at linkup\n");
3670 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3671 LPFC_FCOE_FCF_GET_FIRST);
3673 spin_lock_irqsave(&phba->hbalock, iflags);
3674 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3675 spin_unlock_irqrestore(&phba->hbalock, iflags);
3678 /* Reset FCF roundrobin bmask for new discovery */
3679 lpfc_sli4_clear_fcf_rr_bmask(phba);
3682 /* Prepare for LINK up registrations */
3683 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3684 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3685 init_utsname()->nodename);
3688 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3689 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3690 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3691 vport->port_state, sparam_mbox, cfglink_mbox);
3692 lpfc_issue_clear_la(phba, vport);
3697 lpfc_enable_la(struct lpfc_hba *phba)
3700 struct lpfc_sli *psli = &phba->sli;
3701 spin_lock_irq(&phba->hbalock);
3702 psli->sli_flag |= LPFC_PROCESS_LA;
3703 if (phba->sli_rev <= LPFC_SLI_REV3) {
3704 control = readl(phba->HCregaddr);
3705 control |= HC_LAINT_ENA;
3706 writel(control, phba->HCregaddr);
3707 readl(phba->HCregaddr); /* flush */
3709 spin_unlock_irq(&phba->hbalock);
3713 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3715 lpfc_linkdown(phba);
3716 lpfc_enable_la(phba);
3717 lpfc_unregister_unused_fcf(phba);
3718 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3723 * This routine handles processing a READ_TOPOLOGY mailbox
3724 * command upon completion. It is setup in the LPFC_MBOXQ
3725 * as the completion routine when the command is
3726 * handed off to the SLI layer. SLI4 only.
3729 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3731 struct lpfc_vport *vport = pmb->vport;
3732 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3733 struct lpfc_mbx_read_top *la;
3734 struct lpfc_sli_ring *pring;
3735 MAILBOX_t *mb = &pmb->u.mb;
3736 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3738 unsigned long iflags;
3740 /* Unblock ELS traffic */
3741 pring = lpfc_phba_elsring(phba);
3743 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3745 /* Check for error */
3746 if (mb->mbxStatus) {
3747 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3748 "1307 READ_LA mbox error x%x state x%x\n",
3749 mb->mbxStatus, vport->port_state);
3750 lpfc_mbx_issue_link_down(phba);
3751 phba->link_state = LPFC_HBA_ERROR;
3752 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3755 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3756 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3758 memcpy(&phba->alpa_map[0], mp->virt, 128);
3760 spin_lock_irqsave(shost->host_lock, iflags);
3761 if (bf_get(lpfc_mbx_read_top_pb, la))
3762 vport->fc_flag |= FC_BYPASSED_MODE;
3764 vport->fc_flag &= ~FC_BYPASSED_MODE;
3765 spin_unlock_irqrestore(shost->host_lock, iflags);
3767 if (phba->fc_eventTag <= la->eventTag) {
3768 phba->fc_stat.LinkMultiEvent++;
3769 if (attn_type == LPFC_ATT_LINK_UP)
3770 if (phba->fc_eventTag != 0)
3771 lpfc_linkdown(phba);
3774 phba->fc_eventTag = la->eventTag;
3775 if (phba->sli_rev < LPFC_SLI_REV4) {
3776 spin_lock_irqsave(&phba->hbalock, iflags);
3777 if (bf_get(lpfc_mbx_read_top_mm, la))
3778 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
3780 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
3781 spin_unlock_irqrestore(&phba->hbalock, iflags);
3784 phba->link_events++;
3785 if ((attn_type == LPFC_ATT_LINK_UP) &&
3786 !(phba->sli.sli_flag & LPFC_MENLO_MAINT)) {
3787 phba->fc_stat.LinkUp++;
3788 if (phba->link_flag & LS_LOOPBACK_MODE) {
3789 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3790 "1306 Link Up Event in loop back mode "
3791 "x%x received Data: x%x x%x x%x x%x\n",
3792 la->eventTag, phba->fc_eventTag,
3793 bf_get(lpfc_mbx_read_top_alpa_granted,
3795 bf_get(lpfc_mbx_read_top_link_spd, la),
3798 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3799 "1303 Link Up Event x%x received "
3800 "Data: x%x x%x x%x x%x x%x x%x %d\n",
3801 la->eventTag, phba->fc_eventTag,
3802 bf_get(lpfc_mbx_read_top_alpa_granted,
3804 bf_get(lpfc_mbx_read_top_link_spd, la),
3806 bf_get(lpfc_mbx_read_top_mm, la),
3807 bf_get(lpfc_mbx_read_top_fa, la),
3808 phba->wait_4_mlo_maint_flg);
3810 lpfc_mbx_process_link_up(phba, la);
3812 if (phba->cmf_active_mode != LPFC_CFG_OFF)
3813 lpfc_cmf_signal_init(phba);
3815 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3816 attn_type == LPFC_ATT_UNEXP_WWPN) {
3817 phba->fc_stat.LinkDown++;
3818 if (phba->link_flag & LS_LOOPBACK_MODE)
3819 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3820 "1308 Link Down Event in loop back mode "
3822 "Data: x%x x%x x%x\n",
3823 la->eventTag, phba->fc_eventTag,
3824 phba->pport->port_state, vport->fc_flag);
3825 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3826 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3827 "1313 Link Down Unexpected FA WWPN Event x%x "
3828 "received Data: x%x x%x x%x x%x x%x\n",
3829 la->eventTag, phba->fc_eventTag,
3830 phba->pport->port_state, vport->fc_flag,
3831 bf_get(lpfc_mbx_read_top_mm, la),
3832 bf_get(lpfc_mbx_read_top_fa, la));
3834 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3835 "1305 Link Down Event x%x received "
3836 "Data: x%x x%x x%x x%x x%x\n",
3837 la->eventTag, phba->fc_eventTag,
3838 phba->pport->port_state, vport->fc_flag,
3839 bf_get(lpfc_mbx_read_top_mm, la),
3840 bf_get(lpfc_mbx_read_top_fa, la));
3841 lpfc_mbx_issue_link_down(phba);
3843 if (phba->sli.sli_flag & LPFC_MENLO_MAINT &&
3844 attn_type == LPFC_ATT_LINK_UP) {
3845 if (phba->link_state != LPFC_LINK_DOWN) {
3846 phba->fc_stat.LinkDown++;
3847 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3848 "1312 Link Down Event x%x received "
3849 "Data: x%x x%x x%x\n",
3850 la->eventTag, phba->fc_eventTag,
3851 phba->pport->port_state, vport->fc_flag);
3852 lpfc_mbx_issue_link_down(phba);
3854 lpfc_enable_la(phba);
3856 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3857 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3858 "Data: x%x x%x x%x\n",
3859 la->eventTag, phba->fc_eventTag,
3860 phba->pport->port_state, vport->fc_flag);
3862 * The cmnd that triggered this will be waiting for this
3865 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3866 if (phba->wait_4_mlo_maint_flg) {
3867 phba->wait_4_mlo_maint_flg = 0;
3868 wake_up_interruptible(&phba->wait_4_mlo_m_q);
3872 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3873 bf_get(lpfc_mbx_read_top_fa, la)) {
3874 if (phba->sli.sli_flag & LPFC_MENLO_MAINT)
3875 lpfc_issue_clear_la(phba, vport);
3876 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3878 bf_get(lpfc_mbx_read_top_fa, la));
3881 lpfc_mbx_cmpl_read_topology_free_mbuf:
3882 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3884 mempool_free(pmb, phba->mbox_mem_pool);
3889 * This routine handles processing a REG_LOGIN mailbox
3890 * command upon completion. It is setup in the LPFC_MBOXQ
3891 * as the completion routine when the command is
3892 * handed off to the SLI layer.
3895 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3897 struct lpfc_vport *vport = pmb->vport;
3898 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3899 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3901 pmb->ctx_buf = NULL;
3902 pmb->ctx_ndlp = NULL;
3904 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
3905 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3906 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3907 kref_read(&ndlp->kref),
3909 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3910 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3912 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3913 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3914 /* We rcvd a rscn after issuing this
3915 * mbox reg login, we may have cycled
3916 * back through the state and be
3917 * back at reg login state so this
3918 * mbox needs to be ignored becase
3919 * there is another reg login in
3922 spin_lock_irq(&ndlp->lock);
3923 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3924 spin_unlock_irq(&ndlp->lock);
3927 * We cannot leave the RPI registered because
3928 * if we go thru discovery again for this ndlp
3929 * a subsequent REG_RPI will fail.
3931 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3932 lpfc_unreg_rpi(vport, ndlp);
3935 /* Call state machine */
3936 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3938 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3940 mempool_free(pmb, phba->mbox_mem_pool);
3941 /* decrement the node reference count held for this callback
3950 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3952 MAILBOX_t *mb = &pmb->u.mb;
3953 struct lpfc_vport *vport = pmb->vport;
3954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3956 switch (mb->mbxStatus) {
3959 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3960 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3963 /* If VPI is busy, reset the HBA */
3965 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3966 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3967 vport->vpi, mb->mbxStatus);
3968 if (!(phba->pport->load_flag & FC_UNLOADING))
3969 lpfc_workq_post_event(phba, NULL, NULL,
3970 LPFC_EVT_RESET_HBA);
3972 spin_lock_irq(shost->host_lock);
3973 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3974 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3975 spin_unlock_irq(shost->host_lock);
3976 mempool_free(pmb, phba->mbox_mem_pool);
3977 lpfc_cleanup_vports_rrqs(vport, NULL);
3979 * This shost reference might have been taken at the beginning of
3980 * lpfc_vport_delete()
3982 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3983 scsi_host_put(shost);
3987 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3989 struct lpfc_hba *phba = vport->phba;
3993 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3997 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3998 mbox->vport = vport;
3999 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
4000 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4001 if (rc == MBX_NOT_FINISHED) {
4002 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4003 "1800 Could not issue unreg_vpi\n");
4004 mempool_free(mbox, phba->mbox_mem_pool);
4011 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4013 struct lpfc_vport *vport = pmb->vport;
4014 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4015 MAILBOX_t *mb = &pmb->u.mb;
4017 switch (mb->mbxStatus) {
4021 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4022 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
4024 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4025 spin_lock_irq(shost->host_lock);
4026 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4027 spin_unlock_irq(shost->host_lock);
4028 vport->fc_myDID = 0;
4030 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4031 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4032 if (phba->nvmet_support)
4033 lpfc_nvmet_update_targetport(phba);
4035 lpfc_nvme_update_localport(vport);
4040 spin_lock_irq(shost->host_lock);
4041 vport->vpi_state |= LPFC_VPI_REGISTERED;
4042 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4043 spin_unlock_irq(shost->host_lock);
4044 vport->num_disc_nodes = 0;
4045 /* go thru NPR list and issue ELS PLOGIs */
4046 if (vport->fc_npr_cnt)
4047 lpfc_els_disc_plogi(vport);
4049 if (!vport->num_disc_nodes) {
4050 spin_lock_irq(shost->host_lock);
4051 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4052 spin_unlock_irq(shost->host_lock);
4053 lpfc_can_disctmo(vport);
4055 vport->port_state = LPFC_VPORT_READY;
4058 mempool_free(pmb, phba->mbox_mem_pool);
4063 * lpfc_create_static_vport - Read HBA config region to create static vports.
4064 * @phba: pointer to lpfc hba data structure.
4066 * This routine issue a DUMP mailbox command for config region 22 to get
4067 * the list of static vports to be created. The function create vports
4068 * based on the information returned from the HBA.
4071 lpfc_create_static_vport(struct lpfc_hba *phba)
4073 LPFC_MBOXQ_t *pmb = NULL;
4075 struct static_vport_info *vport_info;
4076 int mbx_wait_rc = 0, i;
4077 struct fc_vport_identifiers vport_id;
4078 struct fc_vport *new_fc_vport;
4079 struct Scsi_Host *shost;
4080 struct lpfc_vport *vport;
4081 uint16_t offset = 0;
4082 uint8_t *vport_buff;
4083 struct lpfc_dmabuf *mp;
4084 uint32_t byte_count = 0;
4086 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4088 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4089 "0542 lpfc_create_static_vport failed to"
4090 " allocate mailbox memory\n");
4093 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
4096 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
4098 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4099 "0543 lpfc_create_static_vport failed to"
4100 " allocate vport_info\n");
4101 mempool_free(pmb, phba->mbox_mem_pool);
4105 vport_buff = (uint8_t *) vport_info;
4107 /* free dma buffer from previous round */
4109 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4110 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4113 if (lpfc_dump_static_vport(phba, pmb, offset))
4116 pmb->vport = phba->pport;
4117 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
4120 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
4121 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4122 "0544 lpfc_create_static_vport failed to"
4123 " issue dump mailbox command ret 0x%x "
4125 mbx_wait_rc, mb->mbxStatus);
4129 if (phba->sli_rev == LPFC_SLI_REV4) {
4130 byte_count = pmb->u.mqe.un.mb_words[5];
4131 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4132 if (byte_count > sizeof(struct static_vport_info) -
4134 byte_count = sizeof(struct static_vport_info)
4136 memcpy(vport_buff + offset, mp->virt, byte_count);
4137 offset += byte_count;
4139 if (mb->un.varDmp.word_cnt >
4140 sizeof(struct static_vport_info) - offset)
4141 mb->un.varDmp.word_cnt =
4142 sizeof(struct static_vport_info)
4144 byte_count = mb->un.varDmp.word_cnt;
4145 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
4146 vport_buff + offset,
4149 offset += byte_count;
4152 } while (byte_count &&
4153 offset < sizeof(struct static_vport_info));
4156 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
4157 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
4158 != VPORT_INFO_REV)) {
4159 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4160 "0545 lpfc_create_static_vport bad"
4161 " information header 0x%x 0x%x\n",
4162 le32_to_cpu(vport_info->signature),
4163 le32_to_cpu(vport_info->rev) &
4164 VPORT_INFO_REV_MASK);
4169 shost = lpfc_shost_from_vport(phba->pport);
4171 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
4172 memset(&vport_id, 0, sizeof(vport_id));
4173 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
4174 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
4175 if (!vport_id.port_name || !vport_id.node_name)
4178 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
4179 vport_id.vport_type = FC_PORTTYPE_NPIV;
4180 vport_id.disable = false;
4181 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
4183 if (!new_fc_vport) {
4184 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4185 "0546 lpfc_create_static_vport failed to"
4190 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
4191 vport->vport_flag |= STATIC_VPORT;
4196 if (mbx_wait_rc != MBX_TIMEOUT) {
4198 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4199 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4202 mempool_free(pmb, phba->mbox_mem_pool);
4209 * This routine handles processing a Fabric REG_LOGIN mailbox
4210 * command upon completion. It is setup in the LPFC_MBOXQ
4211 * as the completion routine when the command is
4212 * handed off to the SLI layer.
4215 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4217 struct lpfc_vport *vport = pmb->vport;
4218 MAILBOX_t *mb = &pmb->u.mb;
4219 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4220 struct lpfc_nodelist *ndlp;
4221 struct Scsi_Host *shost;
4223 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4224 pmb->ctx_ndlp = NULL;
4225 pmb->ctx_buf = NULL;
4227 if (mb->mbxStatus) {
4228 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4229 "0258 Register Fabric login error: 0x%x\n",
4231 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4233 mempool_free(pmb, phba->mbox_mem_pool);
4235 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4236 /* FLOGI failed, use loop map to make discovery list */
4237 lpfc_disc_list_loopmap(vport);
4239 /* Start discovery */
4240 lpfc_disc_start(vport);
4241 /* Decrement the reference count to ndlp after the
4242 * reference to the ndlp are done.
4248 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4249 /* Decrement the reference count to ndlp after the reference
4250 * to the ndlp are done.
4256 if (phba->sli_rev < LPFC_SLI_REV4)
4257 ndlp->nlp_rpi = mb->un.varWords[0];
4258 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4259 ndlp->nlp_type |= NLP_FABRIC;
4260 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4262 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
4263 /* when physical port receive logo donot start
4264 * vport discovery */
4265 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
4266 lpfc_start_fdiscs(phba);
4268 shost = lpfc_shost_from_vport(vport);
4269 spin_lock_irq(shost->host_lock);
4270 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
4271 spin_unlock_irq(shost->host_lock);
4273 lpfc_do_scr_ns_plogi(phba, vport);
4276 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4278 mempool_free(pmb, phba->mbox_mem_pool);
4280 /* Drop the reference count from the mbox at the end after
4281 * all the current reference to the ndlp have been done.
4288 * This routine will issue a GID_FT for each FC4 Type supported
4289 * by the driver. ALL GID_FTs must complete before discovery is started.
4292 lpfc_issue_gidft(struct lpfc_vport *vport)
4294 /* Good status, issue CT Request to NameServer */
4295 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4296 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
4297 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
4298 /* Cannot issue NameServer FCP Query, so finish up
4301 lpfc_printf_vlog(vport, KERN_ERR,
4303 "0604 %s FC TYPE %x %s\n",
4304 "Failed to issue GID_FT to ",
4306 "Finishing discovery.");
4312 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4313 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4314 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4315 /* Cannot issue NameServer NVME Query, so finish up
4318 lpfc_printf_vlog(vport, KERN_ERR,
4320 "0605 %s FC_TYPE %x %s %d\n",
4321 "Failed to issue GID_FT to ",
4323 "Finishing discovery: gidftinp ",
4325 if (vport->gidft_inp == 0)
4330 return vport->gidft_inp;
4334 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4335 * @vport: The virtual port for which this call is being executed.
4337 * This routine will issue a GID_PT to get a list of all N_Ports
4340 * 0 - Failure to issue a GID_PT
4344 lpfc_issue_gidpt(struct lpfc_vport *vport)
4346 /* Good status, issue CT Request to NameServer */
4347 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4348 /* Cannot issue NameServer FCP Query, so finish up
4351 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4352 "0606 %s Port TYPE %x %s\n",
4353 "Failed to issue GID_PT to ",
4355 "Finishing discovery.");
4363 * This routine handles processing a NameServer REG_LOGIN mailbox
4364 * command upon completion. It is setup in the LPFC_MBOXQ
4365 * as the completion routine when the command is
4366 * handed off to the SLI layer.
4369 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4371 MAILBOX_t *mb = &pmb->u.mb;
4372 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4373 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4374 struct lpfc_vport *vport = pmb->vport;
4377 pmb->ctx_buf = NULL;
4378 pmb->ctx_ndlp = NULL;
4379 vport->gidft_inp = 0;
4381 if (mb->mbxStatus) {
4382 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4383 "0260 Register NameServer error: 0x%x\n",
4387 /* decrement the node reference count held for this
4388 * callback function.
4391 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4393 mempool_free(pmb, phba->mbox_mem_pool);
4395 /* If the node is not registered with the scsi or nvme
4396 * transport, remove the fabric node. The failed reg_login
4399 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4400 spin_lock_irq(&ndlp->lock);
4401 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4402 spin_unlock_irq(&ndlp->lock);
4403 lpfc_nlp_not_used(ndlp);
4406 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4408 * RegLogin failed, use loop map to make discovery
4411 lpfc_disc_list_loopmap(vport);
4413 /* Start discovery */
4414 lpfc_disc_start(vport);
4417 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4421 if (phba->sli_rev < LPFC_SLI_REV4)
4422 ndlp->nlp_rpi = mb->un.varWords[0];
4423 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4424 ndlp->nlp_type |= NLP_FABRIC;
4425 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4426 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4427 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4428 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4429 kref_read(&ndlp->kref),
4432 if (vport->port_state < LPFC_VPORT_READY) {
4433 /* Link up discovery requires Fabric registration. */
4434 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4435 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4436 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4437 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4439 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4440 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4441 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4443 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4444 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4445 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4448 /* Issue SCR just before NameServer GID_FT Query */
4449 lpfc_issue_els_scr(vport, 0);
4451 /* Link was bounced or a Fabric LOGO occurred. Start EDC
4452 * with initial FW values provided the congestion mode is
4453 * not off. Note that signals may or may not be supported
4454 * by the adapter but FPIN is provided by default for 1
4455 * or both missing signals support.
4457 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
4458 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
4459 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
4460 rc = lpfc_issue_els_edc(vport, 0);
4461 lpfc_printf_log(phba, KERN_INFO,
4462 LOG_INIT | LOG_ELS | LOG_DISCOVERY,
4463 "4220 EDC issue error x%x, Data: x%x\n",
4464 rc, phba->cgn_init_reg_signal);
4466 lpfc_issue_els_rdf(vport, 0);
4470 vport->fc_ns_retry = 0;
4471 if (lpfc_issue_gidft(vport) == 0)
4475 * At this point in time we may need to wait for multiple
4476 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4478 * decrement the node reference count held for this
4479 * callback function.
4482 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4484 mempool_free(pmb, phba->mbox_mem_pool);
4490 * This routine handles processing a Fabric Controller REG_LOGIN mailbox
4491 * command upon completion. It is setup in the LPFC_MBOXQ
4492 * as the completion routine when the command is handed off to the SLI layer.
4495 lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4497 struct lpfc_vport *vport = pmb->vport;
4498 MAILBOX_t *mb = &pmb->u.mb;
4499 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4500 struct lpfc_nodelist *ndlp;
4502 ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4503 pmb->ctx_ndlp = NULL;
4504 pmb->ctx_buf = NULL;
4506 if (mb->mbxStatus) {
4507 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4508 "0933 %s: Register FC login error: 0x%x\n",
4509 __func__, mb->mbxStatus);
4513 lpfc_check_nlp_post_devloss(vport, ndlp);
4515 if (phba->sli_rev < LPFC_SLI_REV4)
4516 ndlp->nlp_rpi = mb->un.varWords[0];
4518 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4519 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4520 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4523 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4524 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4525 ndlp->nlp_type |= NLP_FABRIC;
4526 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4529 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4531 mempool_free(pmb, phba->mbox_mem_pool);
4533 /* Drop the reference count from the mbox at the end after
4534 * all the current reference to the ndlp have been done.
4540 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4543 struct fc_rport *rport;
4544 struct lpfc_rport_data *rdata;
4545 struct fc_rport_identifiers rport_ids;
4546 struct lpfc_hba *phba = vport->phba;
4547 unsigned long flags;
4549 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4552 /* Remote port has reappeared. Re-register w/ FC transport */
4553 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4554 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4555 rport_ids.port_id = ndlp->nlp_DID;
4556 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4560 "rport add: did:x%x flg:x%x type x%x",
4561 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4563 /* Don't add the remote port if unloading. */
4564 if (vport->load_flag & FC_UNLOADING)
4568 * Disassociate any older association between this ndlp and rport
4571 rdata = ndlp->rport->dd_data;
4572 rdata->pnode = NULL;
4575 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4577 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4578 "Warning: fc_remote_port_add failed\n");
4582 /* Successful port add. Complete initializing node data */
4583 rport->maxframe_size = ndlp->nlp_maxframe;
4584 rport->supported_classes = ndlp->nlp_class_sup;
4585 rdata = rport->dd_data;
4586 rdata->pnode = lpfc_nlp_get(ndlp);
4587 if (!rdata->pnode) {
4588 dev_warn(&phba->pcidev->dev,
4589 "Warning - node ref failed. Unreg rport\n");
4590 fc_remote_port_delete(rport);
4595 spin_lock_irqsave(&ndlp->lock, flags);
4596 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4597 spin_unlock_irqrestore(&ndlp->lock, flags);
4599 if (ndlp->nlp_type & NLP_FCP_TARGET)
4600 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4601 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4602 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4603 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4604 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4605 if (ndlp->nlp_type & NLP_NVME_TARGET)
4606 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4607 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4608 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4610 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4611 fc_remote_port_rolechg(rport, rport_ids.roles);
4613 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4614 "3183 %s rport x%px DID x%x, role x%x refcnt %d\n",
4615 __func__, rport, rport->port_id, rport->roles,
4616 kref_read(&ndlp->kref));
4618 if ((rport->scsi_target_id != -1) &&
4619 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4620 ndlp->nlp_sid = rport->scsi_target_id;
4627 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4629 struct fc_rport *rport = ndlp->rport;
4630 struct lpfc_vport *vport = ndlp->vport;
4632 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4635 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4636 "rport delete: did:x%x flg:x%x type x%x",
4637 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4639 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4640 "3184 rport unregister x%06x, rport x%px "
4641 "xptflg x%x refcnt %d\n",
4642 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags,
4643 kref_read(&ndlp->kref));
4645 fc_remote_port_delete(rport);
4650 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4653 unsigned long iflags;
4655 spin_lock_irqsave(shost->host_lock, iflags);
4657 case NLP_STE_UNUSED_NODE:
4658 vport->fc_unused_cnt += count;
4660 case NLP_STE_PLOGI_ISSUE:
4661 vport->fc_plogi_cnt += count;
4663 case NLP_STE_ADISC_ISSUE:
4664 vport->fc_adisc_cnt += count;
4666 case NLP_STE_REG_LOGIN_ISSUE:
4667 vport->fc_reglogin_cnt += count;
4669 case NLP_STE_PRLI_ISSUE:
4670 vport->fc_prli_cnt += count;
4672 case NLP_STE_UNMAPPED_NODE:
4673 vport->fc_unmap_cnt += count;
4675 case NLP_STE_MAPPED_NODE:
4676 vport->fc_map_cnt += count;
4678 case NLP_STE_NPR_NODE:
4679 if (vport->fc_npr_cnt == 0 && count == -1)
4680 vport->fc_npr_cnt = 0;
4682 vport->fc_npr_cnt += count;
4685 spin_unlock_irqrestore(shost->host_lock, iflags);
4688 /* Register a node with backend if not already done */
4690 lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4692 unsigned long iflags;
4694 lpfc_check_nlp_post_devloss(vport, ndlp);
4696 spin_lock_irqsave(&ndlp->lock, iflags);
4697 if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) {
4698 /* Already registered with backend, trigger rescan */
4699 spin_unlock_irqrestore(&ndlp->lock, iflags);
4701 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD &&
4702 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) {
4703 lpfc_nvme_rescan_port(vport, ndlp);
4708 ndlp->fc4_xpt_flags |= NLP_XPT_REGD;
4709 spin_unlock_irqrestore(&ndlp->lock, iflags);
4711 if (lpfc_valid_xpt_node(ndlp)) {
4712 vport->phba->nport_event_cnt++;
4714 * Tell the fc transport about the port, if we haven't
4715 * already. If we have, and it's a scsi entity, be
4717 lpfc_register_remote_port(vport, ndlp);
4720 /* We are done if we do not have any NVME remote node */
4721 if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME))
4724 /* Notify the NVME transport of this new rport. */
4725 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4726 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4727 if (vport->phba->nvmet_support == 0) {
4728 /* Register this rport with the transport.
4729 * Only NVME Target Rports are registered with
4732 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4733 vport->phba->nport_event_cnt++;
4734 lpfc_nvme_register_port(vport, ndlp);
4737 /* Just take an NDLP ref count since the
4738 * target does not register rports.
4745 /* Unregister a node with backend if not already done */
4747 lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4749 unsigned long iflags;
4751 spin_lock_irqsave(&ndlp->lock, iflags);
4752 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) {
4753 spin_unlock_irqrestore(&ndlp->lock, iflags);
4754 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4755 "0999 %s Not regd: ndlp x%px rport x%px DID "
4756 "x%x FLG x%x XPT x%x\n",
4757 __func__, ndlp, ndlp->rport, ndlp->nlp_DID,
4758 ndlp->nlp_flag, ndlp->fc4_xpt_flags);
4762 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
4763 spin_unlock_irqrestore(&ndlp->lock, iflags);
4766 ndlp->fc4_xpt_flags & SCSI_XPT_REGD) {
4767 vport->phba->nport_event_cnt++;
4768 lpfc_unregister_remote_port(ndlp);
4769 } else if (!ndlp->rport) {
4770 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4771 "1999 %s NDLP in devloss x%px DID x%x FLG x%x"
4772 " XPT x%x refcnt %d\n",
4773 __func__, ndlp, ndlp->nlp_DID, ndlp->nlp_flag,
4774 ndlp->fc4_xpt_flags,
4775 kref_read(&ndlp->kref));
4778 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) {
4779 vport->phba->nport_event_cnt++;
4780 if (vport->phba->nvmet_support == 0) {
4781 /* Start devloss if target. */
4782 if (ndlp->nlp_type & NLP_NVME_TARGET)
4783 lpfc_nvme_unregister_port(vport, ndlp);
4785 /* NVMET has no upcall. */
4793 * Adisc state change handling
4796 lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4799 switch (new_state) {
4801 * Any state to ADISC_ISSUE
4802 * Do nothing, adisc cmpl handling will trigger state changes
4804 case NLP_STE_ADISC_ISSUE:
4808 * ADISC_ISSUE to mapped states
4809 * Trigger a registration with backend, it will be nop if
4810 * already registered
4812 case NLP_STE_UNMAPPED_NODE:
4813 ndlp->nlp_type |= NLP_FC_NODE;
4815 case NLP_STE_MAPPED_NODE:
4816 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4817 lpfc_nlp_reg_node(vport, ndlp);
4821 * ADISC_ISSUE to non-mapped states
4822 * We are moving from ADISC_ISSUE to a non-mapped state because
4823 * ADISC failed, we would have skipped unregistering with
4824 * backend, attempt it now
4826 case NLP_STE_NPR_NODE:
4827 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4830 lpfc_nlp_unreg_node(vport, ndlp);
4837 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4838 int old_state, int new_state)
4840 /* Trap ADISC changes here */
4841 if (new_state == NLP_STE_ADISC_ISSUE ||
4842 old_state == NLP_STE_ADISC_ISSUE) {
4843 lpfc_handle_adisc_state(vport, ndlp, new_state);
4847 if (new_state == NLP_STE_UNMAPPED_NODE) {
4848 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4849 ndlp->nlp_type |= NLP_FC_NODE;
4851 if (new_state == NLP_STE_MAPPED_NODE)
4852 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4853 if (new_state == NLP_STE_NPR_NODE)
4854 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4856 /* Reg/Unreg for FCP and NVME Transport interface */
4857 if ((old_state == NLP_STE_MAPPED_NODE ||
4858 old_state == NLP_STE_UNMAPPED_NODE)) {
4859 /* For nodes marked for ADISC, Handle unreg in ADISC cmpl
4860 * if linkup. In linkdown do unreg_node
4862 if (!(ndlp->nlp_flag & NLP_NPR_ADISC) ||
4863 !lpfc_is_link_up(vport->phba))
4864 lpfc_nlp_unreg_node(vport, ndlp);
4867 if (new_state == NLP_STE_MAPPED_NODE ||
4868 new_state == NLP_STE_UNMAPPED_NODE)
4869 lpfc_nlp_reg_node(vport, ndlp);
4871 if ((new_state == NLP_STE_MAPPED_NODE) &&
4872 (vport->stat_data_enabled)) {
4874 * A new target is discovered, if there is no buffer for
4875 * statistical data collection allocate buffer.
4877 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
4878 sizeof(struct lpfc_scsicmd_bkt),
4881 if (!ndlp->lat_data)
4882 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4883 "0286 lpfc_nlp_state_cleanup failed to "
4884 "allocate statistical data buffer DID "
4885 "0x%x\n", ndlp->nlp_DID);
4888 * If the node just added to Mapped list was an FCP target,
4889 * but the remote port registration failed or assigned a target
4890 * id outside the presentable range - move the node to the
4893 if ((new_state == NLP_STE_MAPPED_NODE) &&
4894 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4896 ndlp->rport->scsi_target_id == -1 ||
4897 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4898 spin_lock_irq(&ndlp->lock);
4899 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4900 spin_unlock_irq(&ndlp->lock);
4901 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4906 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4908 static char *states[] = {
4909 [NLP_STE_UNUSED_NODE] = "UNUSED",
4910 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4911 [NLP_STE_ADISC_ISSUE] = "ADISC",
4912 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4913 [NLP_STE_PRLI_ISSUE] = "PRLI",
4914 [NLP_STE_LOGO_ISSUE] = "LOGO",
4915 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4916 [NLP_STE_MAPPED_NODE] = "MAPPED",
4917 [NLP_STE_NPR_NODE] = "NPR",
4920 if (state < NLP_STE_MAX_STATE && states[state])
4921 strlcpy(buffer, states[state], size);
4923 snprintf(buffer, size, "unknown (%d)", state);
4928 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4931 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4932 int old_state = ndlp->nlp_state;
4933 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
4934 char name1[16], name2[16];
4936 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4937 "0904 NPort state transition x%06x, %s -> %s\n",
4939 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4940 lpfc_nlp_state_name(name2, sizeof(name2), state));
4942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4943 "node statechg did:x%x old:%d ste:%d",
4944 ndlp->nlp_DID, old_state, state);
4946 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4947 state != NLP_STE_UNUSED_NODE) {
4948 ndlp->nlp_flag &= ~NLP_DROPPED;
4952 if (old_state == NLP_STE_NPR_NODE &&
4953 state != NLP_STE_NPR_NODE)
4954 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4955 if (old_state == NLP_STE_UNMAPPED_NODE) {
4956 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4957 ndlp->nlp_type &= ~NLP_FC_NODE;
4960 if (list_empty(&ndlp->nlp_listp)) {
4961 spin_lock_irq(shost->host_lock);
4962 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4963 spin_unlock_irq(shost->host_lock);
4964 } else if (old_state)
4965 lpfc_nlp_counters(vport, old_state, -1);
4967 ndlp->nlp_state = state;
4968 lpfc_nlp_counters(vport, state, 1);
4969 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4973 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4975 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4977 if (list_empty(&ndlp->nlp_listp)) {
4978 spin_lock_irq(shost->host_lock);
4979 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4980 spin_unlock_irq(shost->host_lock);
4985 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4987 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4989 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4990 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4991 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4992 spin_lock_irq(shost->host_lock);
4993 list_del_init(&ndlp->nlp_listp);
4994 spin_unlock_irq(shost->host_lock);
4995 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4996 NLP_STE_UNUSED_NODE);
5000 * lpfc_initialize_node - Initialize all fields of node object
5001 * @vport: Pointer to Virtual Port object.
5002 * @ndlp: Pointer to FC node object.
5003 * @did: FC_ID of the node.
5005 * This function is always called when node object need to be initialized.
5006 * It initializes all the fields of the node object. Although the reference
5007 * to phba from @ndlp can be obtained indirectly through it's reference to
5008 * @vport, a direct reference to phba is taken here by @ndlp. This is due
5009 * to the life-span of the @ndlp might go beyond the existence of @vport as
5010 * the final release of ndlp is determined by its reference count. And, the
5011 * operation on @ndlp needs the reference to phba.
5014 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5017 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
5018 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
5019 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
5020 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
5022 ndlp->nlp_DID = did;
5023 ndlp->vport = vport;
5024 ndlp->phba = vport->phba;
5025 ndlp->nlp_sid = NLP_NO_SID;
5026 ndlp->nlp_fc4_type = NLP_FC4_NONE;
5027 kref_init(&ndlp->kref);
5028 atomic_set(&ndlp->cmd_pending, 0);
5029 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
5030 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5034 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5037 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
5038 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
5039 * the ndlp from the vport. The ndlp marked as UNUSED on the list
5040 * until ALL other outstanding threads have completed. We check
5041 * that the ndlp not already in the UNUSED state before we proceed.
5043 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
5045 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
5046 ndlp->nlp_flag |= NLP_DROPPED;
5047 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
5048 lpfc_cleanup_vports_rrqs(vport, ndlp);
5049 lpfc_unreg_rpi(vport, ndlp);
5057 * Start / ReStart rescue timer for Discovery / RSCN handling
5060 lpfc_set_disctmo(struct lpfc_vport *vport)
5062 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5063 struct lpfc_hba *phba = vport->phba;
5066 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
5067 /* For FAN, timeout should be greater than edtov */
5068 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
5070 /* Normal discovery timeout should be > than ELS/CT timeout
5071 * FC spec states we need 3 * ratov for CT requests
5073 tmo = ((phba->fc_ratov * 3) + 3);
5077 if (!timer_pending(&vport->fc_disctmo)) {
5078 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5079 "set disc timer: tmo:x%x state:x%x flg:x%x",
5080 tmo, vport->port_state, vport->fc_flag);
5083 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
5084 spin_lock_irq(shost->host_lock);
5085 vport->fc_flag |= FC_DISC_TMO;
5086 spin_unlock_irq(shost->host_lock);
5088 /* Start Discovery Timer state <hba_state> */
5089 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5090 "0247 Start Discovery Timer state x%x "
5091 "Data: x%x x%lx x%x x%x\n",
5092 vport->port_state, tmo,
5093 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
5094 vport->fc_adisc_cnt);
5100 * Cancel rescue timer for Discovery / RSCN handling
5103 lpfc_can_disctmo(struct lpfc_vport *vport)
5105 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5106 unsigned long iflags;
5108 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5109 "can disc timer: state:x%x rtry:x%x flg:x%x",
5110 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5112 /* Turn off discovery timer if its running */
5113 if (vport->fc_flag & FC_DISC_TMO ||
5114 timer_pending(&vport->fc_disctmo)) {
5115 spin_lock_irqsave(shost->host_lock, iflags);
5116 vport->fc_flag &= ~FC_DISC_TMO;
5117 spin_unlock_irqrestore(shost->host_lock, iflags);
5118 del_timer_sync(&vport->fc_disctmo);
5119 spin_lock_irqsave(&vport->work_port_lock, iflags);
5120 vport->work_port_events &= ~WORKER_DISC_TMO;
5121 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
5124 /* Cancel Discovery Timer state <hba_state> */
5125 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5126 "0248 Cancel Discovery Timer state x%x "
5127 "Data: x%x x%x x%x\n",
5128 vport->port_state, vport->fc_flag,
5129 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
5134 * Check specified ring for outstanding IOCB on the SLI queue
5135 * Return true if iocb matches the specified nport
5138 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
5139 struct lpfc_sli_ring *pring,
5140 struct lpfc_iocbq *iocb,
5141 struct lpfc_nodelist *ndlp)
5143 struct lpfc_vport *vport = ndlp->vport;
5148 if (iocb->vport != vport)
5151 ulp_command = get_job_cmnd(phba, iocb);
5152 ulp_context = get_job_ulpcontext(phba, iocb);
5153 remote_id = get_job_els_rsp64_did(phba, iocb);
5155 if (pring->ringno == LPFC_ELS_RING) {
5156 switch (ulp_command) {
5157 case CMD_GEN_REQUEST64_CR:
5158 if (iocb->context_un.ndlp == ndlp)
5161 case CMD_ELS_REQUEST64_CR:
5162 if (remote_id == ndlp->nlp_DID)
5165 case CMD_XMIT_ELS_RSP64_CX:
5166 if (iocb->context1 == (uint8_t *) ndlp)
5169 } else if (pring->ringno == LPFC_FCP_RING) {
5170 /* Skip match check if waiting to relogin to FCP target */
5171 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5172 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
5175 if (ulp_context == ndlp->nlp_rpi)
5182 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
5183 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
5184 struct list_head *dequeue_list)
5186 struct lpfc_iocbq *iocb, *next_iocb;
5188 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5189 /* Check to see if iocb matches the nport */
5190 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
5191 /* match, dequeue */
5192 list_move_tail(&iocb->list, dequeue_list);
5197 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
5198 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5200 struct lpfc_sli *psli = &phba->sli;
5203 spin_lock_irq(&phba->hbalock);
5204 for (i = 0; i < psli->num_rings; i++)
5205 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
5207 spin_unlock_irq(&phba->hbalock);
5211 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
5212 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5214 struct lpfc_sli_ring *pring;
5215 struct lpfc_queue *qp = NULL;
5217 spin_lock_irq(&phba->hbalock);
5218 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
5222 spin_lock(&pring->ring_lock);
5223 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
5224 spin_unlock(&pring->ring_lock);
5226 spin_unlock_irq(&phba->hbalock);
5230 * Free resources / clean up outstanding I/Os
5231 * associated with nlp_rpi in the LPFC_NODELIST entry.
5234 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5236 LIST_HEAD(completions);
5238 lpfc_fabric_abort_nport(ndlp);
5241 * Everything that matches on txcmplq will be returned
5242 * by firmware with a no rpi error.
5244 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5245 if (phba->sli_rev != LPFC_SLI_REV4)
5246 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
5248 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
5251 /* Cancel all the IOCBs from the completions list */
5252 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5259 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
5260 * @phba: Pointer to HBA context object.
5261 * @pmb: Pointer to mailbox object.
5263 * This function will issue an ELS LOGO command after completing
5267 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5269 struct lpfc_vport *vport = pmb->vport;
5270 struct lpfc_nodelist *ndlp;
5272 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
5275 lpfc_issue_els_logo(vport, ndlp, 0);
5276 mempool_free(pmb, phba->mbox_mem_pool);
5278 /* Check to see if there are any deferred events to process */
5279 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
5280 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
5281 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5282 "1434 UNREG cmpl deferred logo x%x "
5283 "on NPort x%x Data: x%x x%px\n",
5284 ndlp->nlp_rpi, ndlp->nlp_DID,
5285 ndlp->nlp_defer_did, ndlp);
5287 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5288 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5289 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5291 /* NLP_RELEASE_RPI is only set for SLI4 ports. */
5292 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5293 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
5294 spin_lock_irq(&ndlp->lock);
5295 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5296 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5297 spin_unlock_irq(&ndlp->lock);
5299 spin_lock_irq(&ndlp->lock);
5300 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5301 spin_unlock_irq(&ndlp->lock);
5306 * Sets the mailbox completion handler to be used for the
5307 * unreg_rpi command. The handler varies based on the state of
5308 * the port and what will be happening to the rpi next.
5311 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
5312 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
5314 unsigned long iflags;
5316 /* Driver always gets a reference on the mailbox job
5317 * in support of async jobs.
5319 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5320 if (!mbox->ctx_ndlp)
5323 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
5324 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
5326 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
5327 (!(vport->load_flag & FC_UNLOADING)) &&
5328 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
5329 LPFC_SLI_INTF_IF_TYPE_2) &&
5330 (kref_read(&ndlp->kref) > 0)) {
5331 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
5333 if (vport->load_flag & FC_UNLOADING) {
5334 if (phba->sli_rev == LPFC_SLI_REV4) {
5335 spin_lock_irqsave(&ndlp->lock, iflags);
5336 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5337 spin_unlock_irqrestore(&ndlp->lock, iflags);
5340 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5345 * Free rpi associated with LPFC_NODELIST entry.
5346 * This routine is called from lpfc_freenode(), when we are removing
5347 * a LPFC_NODELIST entry. It is also called if the driver initiates a
5348 * LOGO that completes successfully, and we are waiting to PLOGI back
5349 * to the remote NPort. In addition, it is called after we receive
5350 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
5351 * we are waiting to PLOGI back to the remote NPort.
5354 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5356 struct lpfc_hba *phba = vport->phba;
5358 int rc, acc_plogi = 1;
5361 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5362 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
5363 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
5364 lpfc_printf_vlog(vport, KERN_INFO,
5365 LOG_NODE | LOG_DISCOVERY,
5366 "3366 RPI x%x needs to be "
5367 "unregistered nlp_flag x%x "
5369 ndlp->nlp_rpi, ndlp->nlp_flag,
5372 /* If there is already an UNREG in progress for this ndlp,
5373 * no need to queue up another one.
5375 if (ndlp->nlp_flag & NLP_UNREG_INP) {
5376 lpfc_printf_vlog(vport, KERN_INFO,
5377 LOG_NODE | LOG_DISCOVERY,
5378 "1436 unreg_rpi SKIP UNREG x%x on "
5379 "NPort x%x deferred x%x flg x%x "
5381 ndlp->nlp_rpi, ndlp->nlp_DID,
5382 ndlp->nlp_defer_did,
5383 ndlp->nlp_flag, ndlp);
5387 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5389 /* SLI4 ports require the physical rpi value. */
5390 rpi = ndlp->nlp_rpi;
5391 if (phba->sli_rev == LPFC_SLI_REV4)
5392 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
5394 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
5395 mbox->vport = vport;
5396 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
5397 if (!mbox->ctx_ndlp) {
5398 mempool_free(mbox, phba->mbox_mem_pool);
5402 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
5404 * accept PLOGIs after unreg_rpi_cmpl
5407 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
5409 (!(vport->fc_flag & FC_OFFLINE_MODE)))
5410 ndlp->nlp_flag |= NLP_UNREG_INP;
5412 lpfc_printf_vlog(vport, KERN_INFO,
5413 LOG_NODE | LOG_DISCOVERY,
5414 "1433 unreg_rpi UNREG x%x on "
5415 "NPort x%x deferred flg x%x "
5417 ndlp->nlp_rpi, ndlp->nlp_DID,
5418 ndlp->nlp_flag, ndlp);
5420 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5421 if (rc == MBX_NOT_FINISHED) {
5422 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5423 mempool_free(mbox, phba->mbox_mem_pool);
5428 lpfc_printf_vlog(vport, KERN_INFO,
5429 LOG_NODE | LOG_DISCOVERY,
5430 "1444 Failed to allocate mempool "
5431 "unreg_rpi UNREG x%x, "
5432 "DID x%x, flag x%x, "
5434 ndlp->nlp_rpi, ndlp->nlp_DID,
5435 ndlp->nlp_flag, ndlp);
5437 /* Because mempool_alloc failed, we
5438 * will issue a LOGO here and keep the rpi alive if
5441 if (!(vport->load_flag & FC_UNLOADING)) {
5442 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5443 lpfc_issue_els_logo(vport, ndlp, 0);
5444 ndlp->nlp_prev_state = ndlp->nlp_state;
5445 lpfc_nlp_set_state(vport, ndlp,
5451 lpfc_no_rpi(phba, ndlp);
5453 if (phba->sli_rev != LPFC_SLI_REV4)
5455 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
5456 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5458 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5461 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5466 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5467 * @phba: pointer to lpfc hba data structure.
5469 * This routine is invoked to unregister all the currently registered RPIs
5473 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5475 struct lpfc_vport **vports;
5476 struct lpfc_nodelist *ndlp;
5477 struct Scsi_Host *shost;
5480 vports = lpfc_create_vport_work_array(phba);
5482 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5483 "2884 Vport array allocation failed \n");
5486 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5487 shost = lpfc_shost_from_vport(vports[i]);
5488 spin_lock_irq(shost->host_lock);
5489 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5490 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5491 /* The mempool_alloc might sleep */
5492 spin_unlock_irq(shost->host_lock);
5493 lpfc_unreg_rpi(vports[i], ndlp);
5494 spin_lock_irq(shost->host_lock);
5497 spin_unlock_irq(shost->host_lock);
5499 lpfc_destroy_vport_work_array(phba, vports);
5503 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5505 struct lpfc_hba *phba = vport->phba;
5509 if (phba->sli_rev == LPFC_SLI_REV4) {
5510 lpfc_sli4_unreg_all_rpis(vport);
5514 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5516 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5518 mbox->vport = vport;
5519 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5520 mbox->ctx_ndlp = NULL;
5521 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5522 if (rc != MBX_TIMEOUT)
5523 mempool_free(mbox, phba->mbox_mem_pool);
5525 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5526 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5527 "1836 Could not issue "
5528 "unreg_login(all_rpis) status %d\n",
5534 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5536 struct lpfc_hba *phba = vport->phba;
5540 /* Unreg DID is an SLI3 operation. */
5541 if (phba->sli_rev > LPFC_SLI_REV3)
5544 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5546 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5548 mbox->vport = vport;
5549 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5550 mbox->ctx_ndlp = NULL;
5551 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5552 if (rc != MBX_TIMEOUT)
5553 mempool_free(mbox, phba->mbox_mem_pool);
5555 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5556 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5557 "1815 Could not issue "
5558 "unreg_did (default rpis) status %d\n",
5564 * Free resources associated with LPFC_NODELIST entry
5565 * so it can be freed.
5568 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5570 struct lpfc_hba *phba = vport->phba;
5571 LPFC_MBOXQ_t *mb, *nextmb;
5572 struct lpfc_dmabuf *mp;
5574 /* Cleanup node for NPort <nlp_DID> */
5575 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5576 "0900 Cleanup node for NPort x%x "
5577 "Data: x%x x%x x%x\n",
5578 ndlp->nlp_DID, ndlp->nlp_flag,
5579 ndlp->nlp_state, ndlp->nlp_rpi);
5580 lpfc_dequeue_node(vport, ndlp);
5582 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5584 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5585 if ((mb = phba->sli.mbox_active)) {
5586 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5587 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5588 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5589 mb->ctx_ndlp = NULL;
5590 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5594 spin_lock_irq(&phba->hbalock);
5595 /* Cleanup REG_LOGIN completions which are not yet processed */
5596 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5597 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5598 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5599 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5602 mb->ctx_ndlp = NULL;
5603 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5606 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5607 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5608 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5609 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5610 mp = (struct lpfc_dmabuf *)(mb->ctx_buf);
5612 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
5615 list_del(&mb->list);
5616 mempool_free(mb, phba->mbox_mem_pool);
5617 /* We shall not invoke the lpfc_nlp_put to decrement
5618 * the ndlp reference count as we are in the process
5619 * of lpfc_nlp_release.
5623 spin_unlock_irq(&phba->hbalock);
5625 lpfc_els_abort(phba, ndlp);
5627 spin_lock_irq(&ndlp->lock);
5628 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5629 spin_unlock_irq(&ndlp->lock);
5631 ndlp->nlp_last_elscmd = 0;
5632 del_timer_sync(&ndlp->nlp_delayfunc);
5634 list_del_init(&ndlp->els_retry_evt.evt_listp);
5635 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5636 list_del_init(&ndlp->recovery_evt.evt_listp);
5637 lpfc_cleanup_vports_rrqs(vport, ndlp);
5639 if (phba->sli_rev == LPFC_SLI_REV4)
5640 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5646 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5649 D_ID mydid, ndlpdid, matchdid;
5651 if (did == Bcast_DID)
5654 /* First check for Direct match */
5655 if (ndlp->nlp_DID == did)
5658 /* Next check for area/domain identically equals 0 match */
5659 mydid.un.word = vport->fc_myDID;
5660 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5664 matchdid.un.word = did;
5665 ndlpdid.un.word = ndlp->nlp_DID;
5666 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5667 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5668 (mydid.un.b.area == matchdid.un.b.area)) {
5669 /* This code is supposed to match the ID
5670 * for a private loop device that is
5671 * connect to fl_port. But we need to
5672 * check that the port did not just go
5673 * from pt2pt to fabric or we could end
5674 * up matching ndlp->nlp_DID 000001 to
5675 * fabric DID 0x20101
5677 if ((ndlpdid.un.b.domain == 0) &&
5678 (ndlpdid.un.b.area == 0)) {
5679 if (ndlpdid.un.b.id &&
5680 vport->phba->fc_topology ==
5687 matchdid.un.word = ndlp->nlp_DID;
5688 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5689 (mydid.un.b.area == ndlpdid.un.b.area)) {
5690 if ((matchdid.un.b.domain == 0) &&
5691 (matchdid.un.b.area == 0)) {
5692 if (matchdid.un.b.id)
5700 /* Search for a nodelist entry */
5701 static struct lpfc_nodelist *
5702 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5704 struct lpfc_nodelist *ndlp;
5707 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5708 if (lpfc_matchdid(vport, ndlp, did)) {
5709 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5710 ((uint32_t)ndlp->nlp_xri << 16) |
5711 ((uint32_t)ndlp->nlp_type << 8)
5713 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5714 "0929 FIND node DID "
5715 "Data: x%px x%x x%x x%x x%x x%px\n",
5716 ndlp, ndlp->nlp_DID,
5717 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5718 ndlp->active_rrqs_xri_bitmap);
5723 /* FIND node did <did> NOT FOUND */
5724 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5725 "0932 FIND node did x%x NOT FOUND.\n", did);
5729 struct lpfc_nodelist *
5730 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5732 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5733 struct lpfc_nodelist *ndlp;
5734 unsigned long iflags;
5736 spin_lock_irqsave(shost->host_lock, iflags);
5737 ndlp = __lpfc_findnode_did(vport, did);
5738 spin_unlock_irqrestore(shost->host_lock, iflags);
5742 struct lpfc_nodelist *
5743 lpfc_findnode_mapped(struct lpfc_vport *vport)
5745 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5746 struct lpfc_nodelist *ndlp;
5748 unsigned long iflags;
5750 spin_lock_irqsave(shost->host_lock, iflags);
5752 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5753 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5754 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5755 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5756 ((uint32_t)ndlp->nlp_xri << 16) |
5757 ((uint32_t)ndlp->nlp_type << 8) |
5758 ((uint32_t)ndlp->nlp_rpi & 0xff));
5759 spin_unlock_irqrestore(shost->host_lock, iflags);
5760 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5761 "2025 FIND node DID "
5762 "Data: x%px x%x x%x x%x x%px\n",
5763 ndlp, ndlp->nlp_DID,
5764 ndlp->nlp_flag, data1,
5765 ndlp->active_rrqs_xri_bitmap);
5769 spin_unlock_irqrestore(shost->host_lock, iflags);
5771 /* FIND node did <did> NOT FOUND */
5772 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5773 "2026 FIND mapped did NOT FOUND.\n");
5777 struct lpfc_nodelist *
5778 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5780 struct lpfc_nodelist *ndlp;
5782 ndlp = lpfc_findnode_did(vport, did);
5784 if (vport->phba->nvmet_support)
5786 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5787 lpfc_rscn_payload_check(vport, did) == 0)
5789 ndlp = lpfc_nlp_init(vport, did);
5792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5794 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5795 "6453 Setup New Node 2B_DISC x%x "
5796 "Data:x%x x%x x%x\n",
5797 ndlp->nlp_DID, ndlp->nlp_flag,
5798 ndlp->nlp_state, vport->fc_flag);
5800 spin_lock_irq(&ndlp->lock);
5801 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5802 spin_unlock_irq(&ndlp->lock);
5806 /* The NVME Target does not want to actively manage an rport.
5807 * The goal is to allow the target to reset its state and clear
5808 * pending IO in preparation for the initiator to recover.
5810 if ((vport->fc_flag & FC_RSCN_MODE) &&
5811 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5812 if (lpfc_rscn_payload_check(vport, did)) {
5814 /* Since this node is marked for discovery,
5815 * delay timeout is not needed.
5817 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5819 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5820 "6455 Setup RSCN Node 2B_DISC x%x "
5821 "Data:x%x x%x x%x\n",
5822 ndlp->nlp_DID, ndlp->nlp_flag,
5823 ndlp->nlp_state, vport->fc_flag);
5825 /* NVME Target mode waits until rport is known to be
5826 * impacted by the RSCN before it transitions. No
5827 * active management - just go to NPR provided the
5828 * node had a valid login.
5830 if (vport->phba->nvmet_support)
5833 /* If we've already received a PLOGI from this NPort
5834 * we don't need to try to discover it again.
5836 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5838 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5841 ndlp->nlp_prev_state = ndlp->nlp_state;
5842 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5844 spin_lock_irq(&ndlp->lock);
5845 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5846 spin_unlock_irq(&ndlp->lock);
5848 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5849 "6456 Skip Setup RSCN Node x%x "
5850 "Data:x%x x%x x%x\n",
5851 ndlp->nlp_DID, ndlp->nlp_flag,
5852 ndlp->nlp_state, vport->fc_flag);
5856 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5857 "6457 Setup Active Node 2B_DISC x%x "
5858 "Data:x%x x%x x%x\n",
5859 ndlp->nlp_DID, ndlp->nlp_flag,
5860 ndlp->nlp_state, vport->fc_flag);
5862 /* If the initiator received a PLOGI from this NPort or if the
5863 * initiator is already in the process of discovery on it,
5864 * there's no need to try to discover it again.
5866 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5867 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5868 (!vport->phba->nvmet_support &&
5869 ndlp->nlp_flag & NLP_RCV_PLOGI))
5872 if (vport->phba->nvmet_support)
5875 /* Moving to NPR state clears unsolicited flags and
5876 * allows for rediscovery
5878 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5880 spin_lock_irq(&ndlp->lock);
5881 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5882 spin_unlock_irq(&ndlp->lock);
5887 /* Build a list of nodes to discover based on the loopmap */
5889 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5891 struct lpfc_hba *phba = vport->phba;
5893 uint32_t alpa, index;
5895 if (!lpfc_is_link_up(phba))
5898 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5901 /* Check for loop map present or not */
5902 if (phba->alpa_map[0]) {
5903 for (j = 1; j <= phba->alpa_map[0]; j++) {
5904 alpa = phba->alpa_map[j];
5905 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5907 lpfc_setup_disc_node(vport, alpa);
5910 /* No alpamap, so try all alpa's */
5911 for (j = 0; j < FC_MAXLOOP; j++) {
5912 /* If cfg_scan_down is set, start from highest
5913 * ALPA (0xef) to lowest (0x1).
5915 if (vport->cfg_scan_down)
5918 index = FC_MAXLOOP - j - 1;
5919 alpa = lpfcAlpaArray[index];
5920 if ((vport->fc_myDID & 0xff) == alpa)
5922 lpfc_setup_disc_node(vport, alpa);
5930 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5933 struct lpfc_sli *psli = &phba->sli;
5934 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5935 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5939 * if it's not a physical port or if we already send
5940 * clear_la then don't send it.
5942 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5943 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5944 (phba->sli_rev == LPFC_SLI_REV4))
5947 /* Link up discovery */
5948 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5949 phba->link_state = LPFC_CLEAR_LA;
5950 lpfc_clear_la(phba, mbox);
5951 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5952 mbox->vport = vport;
5953 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5954 if (rc == MBX_NOT_FINISHED) {
5955 mempool_free(mbox, phba->mbox_mem_pool);
5956 lpfc_disc_flush_list(vport);
5957 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5958 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5959 phba->link_state = LPFC_HBA_ERROR;
5964 /* Reg_vpi to tell firmware to resume normal operations */
5966 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5968 LPFC_MBOXQ_t *regvpimbox;
5970 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5972 lpfc_reg_vpi(vport, regvpimbox);
5973 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5974 regvpimbox->vport = vport;
5975 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5976 == MBX_NOT_FINISHED) {
5977 mempool_free(regvpimbox, phba->mbox_mem_pool);
5982 /* Start Link up / RSCN discovery on NPR nodes */
5984 lpfc_disc_start(struct lpfc_vport *vport)
5986 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5987 struct lpfc_hba *phba = vport->phba;
5989 uint32_t clear_la_pending;
5991 if (!lpfc_is_link_up(phba)) {
5992 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5993 "3315 Link is not up %x\n",
5998 if (phba->link_state == LPFC_CLEAR_LA)
5999 clear_la_pending = 1;
6001 clear_la_pending = 0;
6003 if (vport->port_state < LPFC_VPORT_READY)
6004 vport->port_state = LPFC_DISC_AUTH;
6006 lpfc_set_disctmo(vport);
6008 vport->fc_prevDID = vport->fc_myDID;
6009 vport->num_disc_nodes = 0;
6011 /* Start Discovery state <hba_state> */
6012 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6013 "0202 Start Discovery port state x%x "
6014 "flg x%x Data: x%x x%x x%x\n",
6015 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
6016 vport->fc_adisc_cnt, vport->fc_npr_cnt);
6018 /* First do ADISCs - if any */
6019 num_sent = lpfc_els_disc_adisc(vport);
6024 /* Register the VPI for SLI3, NPIV only. */
6025 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6026 !(vport->fc_flag & FC_PT2PT) &&
6027 !(vport->fc_flag & FC_RSCN_MODE) &&
6028 (phba->sli_rev < LPFC_SLI_REV4)) {
6029 lpfc_issue_clear_la(phba, vport);
6030 lpfc_issue_reg_vpi(phba, vport);
6035 * For SLI2, we need to set port_state to READY and continue
6038 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
6039 /* If we get here, there is nothing to ADISC */
6040 lpfc_issue_clear_la(phba, vport);
6042 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
6043 vport->num_disc_nodes = 0;
6044 /* go thru NPR nodes and issue ELS PLOGIs */
6045 if (vport->fc_npr_cnt)
6046 lpfc_els_disc_plogi(vport);
6048 if (!vport->num_disc_nodes) {
6049 spin_lock_irq(shost->host_lock);
6050 vport->fc_flag &= ~FC_NDISC_ACTIVE;
6051 spin_unlock_irq(shost->host_lock);
6052 lpfc_can_disctmo(vport);
6055 vport->port_state = LPFC_VPORT_READY;
6057 /* Next do PLOGIs - if any */
6058 num_sent = lpfc_els_disc_plogi(vport);
6063 if (vport->fc_flag & FC_RSCN_MODE) {
6064 /* Check to see if more RSCNs came in while we
6065 * were processing this one.
6067 if ((vport->fc_rscn_id_cnt == 0) &&
6068 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
6069 spin_lock_irq(shost->host_lock);
6070 vport->fc_flag &= ~FC_RSCN_MODE;
6071 spin_unlock_irq(shost->host_lock);
6072 lpfc_can_disctmo(vport);
6074 lpfc_els_handle_rscn(vport);
6081 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
6082 * ring the match the sppecified nodelist.
6085 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
6087 LIST_HEAD(completions);
6088 struct lpfc_iocbq *iocb, *next_iocb;
6089 struct lpfc_sli_ring *pring;
6092 pring = lpfc_phba_elsring(phba);
6093 if (unlikely(!pring))
6096 /* Error matching iocb on txq or txcmplq
6097 * First check the txq.
6099 spin_lock_irq(&phba->hbalock);
6100 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6101 if (iocb->context1 != ndlp)
6104 ulp_command = get_job_cmnd(phba, iocb);
6106 if (ulp_command == CMD_ELS_REQUEST64_CR ||
6107 ulp_command == CMD_XMIT_ELS_RSP64_CX) {
6109 list_move_tail(&iocb->list, &completions);
6113 /* Next check the txcmplq */
6114 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
6115 if (iocb->context1 != ndlp)
6118 ulp_command = get_job_cmnd(phba, iocb);
6120 if (ulp_command == CMD_ELS_REQUEST64_CR ||
6121 ulp_command == CMD_XMIT_ELS_RSP64_CX) {
6122 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
6125 spin_unlock_irq(&phba->hbalock);
6127 /* Make sure HBA is alive */
6128 lpfc_issue_hb_tmo(phba);
6130 /* Cancel all the IOCBs from the completions list */
6131 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6136 lpfc_disc_flush_list(struct lpfc_vport *vport)
6138 struct lpfc_nodelist *ndlp, *next_ndlp;
6139 struct lpfc_hba *phba = vport->phba;
6141 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
6142 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6144 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
6145 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
6146 lpfc_free_tx(phba, ndlp);
6153 * lpfc_notify_xport_npr - notifies xport of node disappearance
6154 * @vport: Pointer to Virtual Port object.
6156 * Transitions all ndlps to NPR state. When lpfc_nlp_set_state
6157 * calls lpfc_nlp_state_cleanup, the ndlp->rport is unregistered
6158 * and transport notified that the node is gone.
6163 lpfc_notify_xport_npr(struct lpfc_vport *vport)
6165 struct lpfc_nodelist *ndlp, *next_ndlp;
6167 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6169 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6173 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
6175 lpfc_els_flush_rscn(vport);
6176 lpfc_els_flush_cmd(vport);
6177 lpfc_disc_flush_list(vport);
6178 if (pci_channel_offline(vport->phba->pcidev))
6179 lpfc_notify_xport_npr(vport);
6182 /*****************************************************************************/
6184 * NAME: lpfc_disc_timeout
6186 * FUNCTION: Fibre Channel driver discovery timeout routine.
6188 * EXECUTION ENVIRONMENT: interrupt only
6196 /*****************************************************************************/
6198 lpfc_disc_timeout(struct timer_list *t)
6200 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
6201 struct lpfc_hba *phba = vport->phba;
6202 uint32_t tmo_posted;
6203 unsigned long flags = 0;
6205 if (unlikely(!phba))
6208 spin_lock_irqsave(&vport->work_port_lock, flags);
6209 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
6211 vport->work_port_events |= WORKER_DISC_TMO;
6212 spin_unlock_irqrestore(&vport->work_port_lock, flags);
6215 lpfc_worker_wake_up(phba);
6220 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
6222 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6223 struct lpfc_hba *phba = vport->phba;
6224 struct lpfc_sli *psli = &phba->sli;
6225 struct lpfc_nodelist *ndlp, *next_ndlp;
6226 LPFC_MBOXQ_t *initlinkmbox;
6227 int rc, clrlaerr = 0;
6229 if (!(vport->fc_flag & FC_DISC_TMO))
6232 spin_lock_irq(shost->host_lock);
6233 vport->fc_flag &= ~FC_DISC_TMO;
6234 spin_unlock_irq(shost->host_lock);
6236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6237 "disc timeout: state:x%x rtry:x%x flg:x%x",
6238 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
6240 switch (vport->port_state) {
6242 case LPFC_LOCAL_CFG_LINK:
6244 * port_state is identically LPFC_LOCAL_CFG_LINK while
6245 * waiting for FAN timeout
6247 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
6248 "0221 FAN timeout\n");
6250 /* Start discovery by sending FLOGI, clean up old rpis */
6251 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6253 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
6255 if (ndlp->nlp_type & NLP_FABRIC) {
6256 /* Clean up the ndlp on Fabric connections */
6257 lpfc_drop_node(vport, ndlp);
6259 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
6260 /* Fail outstanding IO now since device
6261 * is marked for PLOGI.
6263 lpfc_unreg_rpi(vport, ndlp);
6266 if (vport->port_state != LPFC_FLOGI) {
6267 if (phba->sli_rev <= LPFC_SLI_REV3)
6268 lpfc_initial_flogi(vport);
6270 lpfc_issue_init_vfi(vport);
6277 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
6278 /* Initial FLOGI timeout */
6279 lpfc_printf_vlog(vport, KERN_ERR,
6281 "0222 Initial %s timeout\n",
6282 vport->vpi ? "FDISC" : "FLOGI");
6284 /* Assume no Fabric and go on with discovery.
6285 * Check for outstanding ELS FLOGI to abort.
6288 /* FLOGI failed, so just use loop map to make discovery list */
6289 lpfc_disc_list_loopmap(vport);
6291 /* Start discovery */
6292 lpfc_disc_start(vport);
6295 case LPFC_FABRIC_CFG_LINK:
6296 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
6298 lpfc_printf_vlog(vport, KERN_ERR,
6300 "0223 Timeout while waiting for "
6301 "NameServer login\n");
6302 /* Next look for NameServer ndlp */
6303 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6305 lpfc_els_abort(phba, ndlp);
6307 /* ReStart discovery */
6311 /* Check for wait for NameServer Rsp timeout */
6312 lpfc_printf_vlog(vport, KERN_ERR,
6314 "0224 NameServer Query timeout "
6316 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6318 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
6319 /* Try it one more time */
6320 vport->fc_ns_retry++;
6321 vport->gidft_inp = 0;
6322 rc = lpfc_issue_gidft(vport);
6326 vport->fc_ns_retry = 0;
6330 * Discovery is over.
6331 * set port_state to PORT_READY if SLI2.
6332 * cmpl_reg_vpi will set port_state to READY for SLI3.
6334 if (phba->sli_rev < LPFC_SLI_REV4) {
6335 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6336 lpfc_issue_reg_vpi(phba, vport);
6338 lpfc_issue_clear_la(phba, vport);
6339 vport->port_state = LPFC_VPORT_READY;
6343 /* Setup and issue mailbox INITIALIZE LINK command */
6344 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6345 if (!initlinkmbox) {
6346 lpfc_printf_vlog(vport, KERN_ERR,
6348 "0206 Device Discovery "
6349 "completion error\n");
6350 phba->link_state = LPFC_HBA_ERROR;
6354 lpfc_linkdown(phba);
6355 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
6356 phba->cfg_link_speed);
6357 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6358 initlinkmbox->vport = vport;
6359 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6360 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
6361 lpfc_set_loopback_flag(phba);
6362 if (rc == MBX_NOT_FINISHED)
6363 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6367 case LPFC_DISC_AUTH:
6368 /* Node Authentication timeout */
6369 lpfc_printf_vlog(vport, KERN_ERR,
6371 "0227 Node Authentication timeout\n");
6372 lpfc_disc_flush_list(vport);
6375 * set port_state to PORT_READY if SLI2.
6376 * cmpl_reg_vpi will set port_state to READY for SLI3.
6378 if (phba->sli_rev < LPFC_SLI_REV4) {
6379 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6380 lpfc_issue_reg_vpi(phba, vport);
6381 else { /* NPIV Not enabled */
6382 lpfc_issue_clear_la(phba, vport);
6383 vport->port_state = LPFC_VPORT_READY;
6388 case LPFC_VPORT_READY:
6389 if (vport->fc_flag & FC_RSCN_MODE) {
6390 lpfc_printf_vlog(vport, KERN_ERR,
6392 "0231 RSCN timeout Data: x%x "
6394 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6396 /* Cleanup any outstanding ELS commands */
6397 lpfc_els_flush_cmd(vport);
6399 lpfc_els_flush_rscn(vport);
6400 lpfc_disc_flush_list(vport);
6405 lpfc_printf_vlog(vport, KERN_ERR,
6407 "0273 Unexpected discovery timeout, "
6408 "vport State x%x\n", vport->port_state);
6412 switch (phba->link_state) {
6414 /* CLEAR LA timeout */
6415 lpfc_printf_vlog(vport, KERN_ERR,
6417 "0228 CLEAR LA timeout\n");
6422 lpfc_issue_clear_la(phba, vport);
6424 case LPFC_LINK_UNKNOWN:
6425 case LPFC_WARM_START:
6426 case LPFC_INIT_START:
6427 case LPFC_INIT_MBX_CMDS:
6428 case LPFC_LINK_DOWN:
6429 case LPFC_HBA_ERROR:
6430 lpfc_printf_vlog(vport, KERN_ERR,
6432 "0230 Unexpected timeout, hba link "
6433 "state x%x\n", phba->link_state);
6437 case LPFC_HBA_READY:
6442 lpfc_disc_flush_list(vport);
6443 if (phba->sli_rev != LPFC_SLI_REV4) {
6444 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6445 ~LPFC_STOP_IOCB_EVENT;
6446 psli->sli3_ring[LPFC_FCP_RING].flag &=
6447 ~LPFC_STOP_IOCB_EVENT;
6449 vport->port_state = LPFC_VPORT_READY;
6455 * This routine handles processing a NameServer REG_LOGIN mailbox
6456 * command upon completion. It is setup in the LPFC_MBOXQ
6457 * as the completion routine when the command is
6458 * handed off to the SLI layer.
6461 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6463 MAILBOX_t *mb = &pmb->u.mb;
6464 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
6465 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6466 struct lpfc_vport *vport = pmb->vport;
6468 pmb->ctx_buf = NULL;
6469 pmb->ctx_ndlp = NULL;
6471 if (phba->sli_rev < LPFC_SLI_REV4)
6472 ndlp->nlp_rpi = mb->un.varWords[0];
6473 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6474 ndlp->nlp_type |= NLP_FABRIC;
6475 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6476 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6477 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
6478 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6479 kref_read(&ndlp->kref),
6482 * Start issuing Fabric-Device Management Interface (FDMI) command to
6483 * 0xfffffa (FDMI well known port).
6484 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6485 * DPRT -> RPRT (vports)
6487 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6488 phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */
6489 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6491 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6495 /* decrement the node reference count held for this callback
6499 lpfc_mbuf_free(phba, mp->virt, mp->phys);
6501 mempool_free(pmb, phba->mbox_mem_pool);
6507 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6509 uint16_t *rpi = param;
6511 return ndlp->nlp_rpi == *rpi;
6515 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6517 return memcmp(&ndlp->nlp_portname, param,
6518 sizeof(ndlp->nlp_portname)) == 0;
6521 static struct lpfc_nodelist *
6522 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6524 struct lpfc_nodelist *ndlp;
6526 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6527 if (filter(ndlp, param)) {
6528 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6529 "3185 FIND node filter %ps DID "
6530 "ndlp x%px did x%x flg x%x st x%x "
6531 "xri x%x type x%x rpi x%x\n",
6532 filter, ndlp, ndlp->nlp_DID,
6533 ndlp->nlp_flag, ndlp->nlp_state,
6534 ndlp->nlp_xri, ndlp->nlp_type,
6539 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6540 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6545 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6546 * returns the node list element pointer else return NULL.
6548 struct lpfc_nodelist *
6549 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6551 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6555 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6556 * returns the node element list pointer else return NULL.
6558 struct lpfc_nodelist *
6559 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6561 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6562 struct lpfc_nodelist *ndlp;
6564 spin_lock_irq(shost->host_lock);
6565 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6566 spin_unlock_irq(shost->host_lock);
6571 * This routine looks up the ndlp lists for the given RPI. If the rpi
6572 * is found, the routine returns the node element list pointer else
6575 struct lpfc_nodelist *
6576 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6578 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6579 struct lpfc_nodelist *ndlp;
6580 unsigned long flags;
6582 spin_lock_irqsave(shost->host_lock, flags);
6583 ndlp = __lpfc_findnode_rpi(vport, rpi);
6584 spin_unlock_irqrestore(shost->host_lock, flags);
6589 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6590 * @phba: pointer to lpfc hba data structure.
6591 * @vpi: the physical host virtual N_Port identifier.
6593 * This routine finds a vport on a HBA (referred by @phba) through a
6594 * @vpi. The function walks the HBA's vport list and returns the address
6595 * of the vport with the matching @vpi.
6598 * NULL - No vport with the matching @vpi found
6599 * Otherwise - Address to the vport with the matching @vpi.
6602 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6604 struct lpfc_vport *vport;
6605 unsigned long flags;
6608 /* The physical ports are always vpi 0 - translate is unnecessary. */
6611 * Translate the physical vpi to the logical vpi. The
6612 * vport stores the logical vpi.
6614 for (i = 0; i <= phba->max_vpi; i++) {
6615 if (vpi == phba->vpi_ids[i])
6619 if (i > phba->max_vpi) {
6620 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6621 "2936 Could not find Vport mapped "
6622 "to vpi %d\n", vpi);
6627 spin_lock_irqsave(&phba->port_list_lock, flags);
6628 list_for_each_entry(vport, &phba->port_list, listentry) {
6629 if (vport->vpi == i) {
6630 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6634 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6638 struct lpfc_nodelist *
6639 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6641 struct lpfc_nodelist *ndlp;
6642 int rpi = LPFC_RPI_ALLOC_ERROR;
6644 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6645 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6646 if (rpi == LPFC_RPI_ALLOC_ERROR)
6650 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6652 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6653 lpfc_sli4_free_rpi(vport->phba, rpi);
6657 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6659 spin_lock_init(&ndlp->lock);
6661 lpfc_initialize_node(vport, ndlp, did);
6662 INIT_LIST_HEAD(&ndlp->nlp_listp);
6663 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6664 ndlp->nlp_rpi = rpi;
6665 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6666 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6667 "flg:x%x refcnt:%d\n",
6668 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6669 ndlp->nlp_flag, kref_read(&ndlp->kref));
6671 ndlp->active_rrqs_xri_bitmap =
6672 mempool_alloc(vport->phba->active_rrq_pool,
6674 if (ndlp->active_rrqs_xri_bitmap)
6675 memset(ndlp->active_rrqs_xri_bitmap, 0,
6676 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6682 "node init: did:x%x",
6683 ndlp->nlp_DID, 0, 0);
6688 /* This routine releases all resources associated with a specifc NPort's ndlp
6689 * and mempool_free's the nodelist.
6692 lpfc_nlp_release(struct kref *kref)
6694 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6696 struct lpfc_vport *vport = ndlp->vport;
6698 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6699 "node release: did:x%x flg:x%x type:x%x",
6700 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6702 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6703 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
6704 __func__, ndlp, ndlp->nlp_DID,
6705 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6707 /* remove ndlp from action. */
6708 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6709 lpfc_cleanup_node(vport, ndlp);
6711 /* Not all ELS transactions have registered the RPI with the port.
6712 * In these cases the rpi usage is temporary and the node is
6713 * released when the WQE is completed. Catch this case to free the
6714 * RPI to the pool. Because this node is in the release path, a lock
6715 * is unnecessary. All references are gone and the node has been
6718 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6719 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6720 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6721 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6722 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6726 /* The node is not freed back to memory, it is released to a pool so
6727 * the node fields need to be cleaned up.
6730 ndlp->nlp_state = NLP_STE_FREED_NODE;
6732 ndlp->fc4_xpt_flags = 0;
6734 /* free ndlp memory for final ndlp release */
6735 kfree(ndlp->lat_data);
6736 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6737 mempool_free(ndlp->active_rrqs_xri_bitmap,
6738 ndlp->phba->active_rrq_pool);
6739 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6742 /* This routine bumps the reference count for a ndlp structure to ensure
6743 * that one discovery thread won't free a ndlp while another discovery thread
6746 struct lpfc_nodelist *
6747 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6749 unsigned long flags;
6752 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6753 "node get: did:x%x flg:x%x refcnt:x%x",
6754 ndlp->nlp_DID, ndlp->nlp_flag,
6755 kref_read(&ndlp->kref));
6757 /* The check of ndlp usage to prevent incrementing the
6758 * ndlp reference count that is in the process of being
6761 spin_lock_irqsave(&ndlp->lock, flags);
6762 if (!kref_get_unless_zero(&ndlp->kref)) {
6763 spin_unlock_irqrestore(&ndlp->lock, flags);
6764 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6765 "0276 %s: ndlp:x%px refcnt:%d\n",
6766 __func__, (void *)ndlp, kref_read(&ndlp->kref));
6769 spin_unlock_irqrestore(&ndlp->lock, flags);
6771 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
6777 /* This routine decrements the reference count for a ndlp structure. If the
6778 * count goes to 0, this indicates the associated nodelist should be freed.
6781 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6784 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6785 "node put: did:x%x flg:x%x refcnt:x%x",
6786 ndlp->nlp_DID, ndlp->nlp_flag,
6787 kref_read(&ndlp->kref));
6789 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
6792 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
6795 /* This routine free's the specified nodelist if it is not in use
6796 * by any other discovery thread. This routine returns 1 if the
6797 * ndlp has been freed. A return value of 0 indicates the ndlp is
6798 * not yet been released.
6801 lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
6803 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6804 "node not used: did:x%x flg:x%x refcnt:x%x",
6805 ndlp->nlp_DID, ndlp->nlp_flag,
6806 kref_read(&ndlp->kref));
6808 if (kref_read(&ndlp->kref) == 1)
6809 if (lpfc_nlp_put(ndlp))
6815 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6816 * @phba: Pointer to hba context object.
6818 * This function iterate through all FC nodes associated
6819 * will all vports to check if there is any node with
6820 * fc_rports associated with it. If there is an fc_rport
6821 * associated with the node, then the node is either in
6822 * discovered state or its devloss_timer is pending.
6825 lpfc_fcf_inuse(struct lpfc_hba *phba)
6827 struct lpfc_vport **vports;
6829 struct lpfc_nodelist *ndlp;
6830 struct Scsi_Host *shost;
6832 vports = lpfc_create_vport_work_array(phba);
6834 /* If driver cannot allocate memory, indicate fcf is in use */
6838 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6839 shost = lpfc_shost_from_vport(vports[i]);
6840 spin_lock_irq(shost->host_lock);
6842 * IF the CVL_RCVD bit is not set then we have sent the
6844 * If dev_loss fires while we are waiting we do not want to
6847 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6848 spin_unlock_irq(shost->host_lock);
6852 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6854 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6856 spin_unlock_irq(shost->host_lock);
6858 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6860 lpfc_printf_log(phba, KERN_INFO,
6861 LOG_NODE | LOG_DISCOVERY,
6862 "2624 RPI %x DID %x flag %x "
6863 "still logged in\n",
6864 ndlp->nlp_rpi, ndlp->nlp_DID,
6868 spin_unlock_irq(shost->host_lock);
6871 lpfc_destroy_vport_work_array(phba, vports);
6876 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6877 * @phba: Pointer to hba context object.
6878 * @mboxq: Pointer to mailbox object.
6880 * This function frees memory associated with the mailbox command.
6883 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6885 struct lpfc_vport *vport = mboxq->vport;
6886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6888 if (mboxq->u.mb.mbxStatus) {
6889 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6890 "2555 UNREG_VFI mbxStatus error x%x "
6892 mboxq->u.mb.mbxStatus, vport->port_state);
6894 spin_lock_irq(shost->host_lock);
6895 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6896 spin_unlock_irq(shost->host_lock);
6897 mempool_free(mboxq, phba->mbox_mem_pool);
6902 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6903 * @phba: Pointer to hba context object.
6904 * @mboxq: Pointer to mailbox object.
6906 * This function frees memory associated with the mailbox command.
6909 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6911 struct lpfc_vport *vport = mboxq->vport;
6913 if (mboxq->u.mb.mbxStatus) {
6914 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6915 "2550 UNREG_FCFI mbxStatus error x%x "
6917 mboxq->u.mb.mbxStatus, vport->port_state);
6919 mempool_free(mboxq, phba->mbox_mem_pool);
6924 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6925 * @phba: Pointer to hba context object.
6927 * This function prepare the HBA for unregistering the currently registered
6928 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6932 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6934 struct lpfc_vport **vports;
6935 struct lpfc_nodelist *ndlp;
6936 struct Scsi_Host *shost;
6939 /* Unregister RPIs */
6940 if (lpfc_fcf_inuse(phba))
6941 lpfc_unreg_hba_rpis(phba);
6943 /* At this point, all discovery is aborted */
6944 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6946 /* Unregister VPIs */
6947 vports = lpfc_create_vport_work_array(phba);
6948 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6949 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6950 /* Stop FLOGI/FDISC retries */
6951 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6953 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6954 lpfc_cleanup_pending_mbox(vports[i]);
6955 if (phba->sli_rev == LPFC_SLI_REV4)
6956 lpfc_sli4_unreg_all_rpis(vports[i]);
6957 lpfc_mbx_unreg_vpi(vports[i]);
6958 shost = lpfc_shost_from_vport(vports[i]);
6959 spin_lock_irq(shost->host_lock);
6960 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6961 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6962 spin_unlock_irq(shost->host_lock);
6964 lpfc_destroy_vport_work_array(phba, vports);
6965 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6966 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6968 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6969 lpfc_cleanup_pending_mbox(phba->pport);
6970 if (phba->sli_rev == LPFC_SLI_REV4)
6971 lpfc_sli4_unreg_all_rpis(phba->pport);
6972 lpfc_mbx_unreg_vpi(phba->pport);
6973 shost = lpfc_shost_from_vport(phba->pport);
6974 spin_lock_irq(shost->host_lock);
6975 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6976 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6977 spin_unlock_irq(shost->host_lock);
6980 /* Cleanup any outstanding ELS commands */
6981 lpfc_els_flush_all_cmd(phba);
6983 /* Unregister the physical port VFI */
6984 rc = lpfc_issue_unreg_vfi(phba->pport);
6989 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6990 * @phba: Pointer to hba context object.
6992 * This function issues synchronous unregister FCF mailbox command to HBA to
6993 * unregister the currently registered FCF record. The driver does not reset
6994 * the driver FCF usage state flags.
6996 * Return 0 if successfully issued, none-zero otherwise.
6999 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
7004 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7006 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7007 "2551 UNREG_FCFI mbox allocation failed"
7008 "HBA state x%x\n", phba->pport->port_state);
7011 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
7012 mbox->vport = phba->pport;
7013 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
7014 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
7016 if (rc == MBX_NOT_FINISHED) {
7017 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7018 "2552 Unregister FCFI command failed rc x%x "
7020 rc, phba->pport->port_state);
7027 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
7028 * @phba: Pointer to hba context object.
7030 * This function unregisters the currently reigstered FCF. This function
7031 * also tries to find another FCF for discovery by rescan the HBA FCF table.
7034 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
7038 /* Preparation for unregistering fcf */
7039 rc = lpfc_unregister_fcf_prep(phba);
7041 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7042 "2748 Failed to prepare for unregistering "
7043 "HBA's FCF record: rc=%d\n", rc);
7047 /* Now, unregister FCF record and reset HBA FCF state */
7048 rc = lpfc_sli4_unregister_fcf(phba);
7051 /* Reset HBA FCF states after successful unregister FCF */
7052 phba->fcf.fcf_flag = 0;
7053 phba->fcf.current_rec.flag = 0;
7056 * If driver is not unloading, check if there is any other
7057 * FCF record that can be used for discovery.
7059 if ((phba->pport->load_flag & FC_UNLOADING) ||
7060 (phba->link_state < LPFC_LINK_UP))
7063 /* This is considered as the initial FCF discovery scan */
7064 spin_lock_irq(&phba->hbalock);
7065 phba->fcf.fcf_flag |= FCF_INIT_DISC;
7066 spin_unlock_irq(&phba->hbalock);
7068 /* Reset FCF roundrobin bmask for new discovery */
7069 lpfc_sli4_clear_fcf_rr_bmask(phba);
7071 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
7074 spin_lock_irq(&phba->hbalock);
7075 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
7076 spin_unlock_irq(&phba->hbalock);
7077 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7078 "2553 lpfc_unregister_unused_fcf failed "
7079 "to read FCF record HBA state x%x\n",
7080 phba->pport->port_state);
7085 * lpfc_unregister_fcf - Unregister the currently registered fcf record
7086 * @phba: Pointer to hba context object.
7088 * This function just unregisters the currently reigstered FCF. It does not
7089 * try to find another FCF for discovery.
7092 lpfc_unregister_fcf(struct lpfc_hba *phba)
7096 /* Preparation for unregistering fcf */
7097 rc = lpfc_unregister_fcf_prep(phba);
7099 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7100 "2749 Failed to prepare for unregistering "
7101 "HBA's FCF record: rc=%d\n", rc);
7105 /* Now, unregister FCF record and reset HBA FCF state */
7106 rc = lpfc_sli4_unregister_fcf(phba);
7109 /* Set proper HBA FCF states after successful unregister FCF */
7110 spin_lock_irq(&phba->hbalock);
7111 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
7112 spin_unlock_irq(&phba->hbalock);
7116 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
7117 * @phba: Pointer to hba context object.
7119 * This function check if there are any connected remote port for the FCF and
7120 * if all the devices are disconnected, this function unregister FCFI.
7121 * This function also tries to use another FCF for discovery.
7124 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
7127 * If HBA is not running in FIP mode, if HBA does not support
7128 * FCoE, if FCF discovery is ongoing, or if FCF has not been
7129 * registered, do nothing.
7131 spin_lock_irq(&phba->hbalock);
7132 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
7133 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
7134 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
7135 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
7136 (phba->pport->port_state == LPFC_FLOGI)) {
7137 spin_unlock_irq(&phba->hbalock);
7140 spin_unlock_irq(&phba->hbalock);
7142 if (lpfc_fcf_inuse(phba))
7145 lpfc_unregister_fcf_rescan(phba);
7149 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
7150 * @phba: Pointer to hba context object.
7151 * @buff: Buffer containing the FCF connection table as in the config
7153 * This function create driver data structure for the FCF connection
7154 * record table read from config region 23.
7157 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
7160 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
7161 struct lpfc_fcf_conn_hdr *conn_hdr;
7162 struct lpfc_fcf_conn_rec *conn_rec;
7163 uint32_t record_count;
7166 /* Free the current connect table */
7167 list_for_each_entry_safe(conn_entry, next_conn_entry,
7168 &phba->fcf_conn_rec_list, list) {
7169 list_del_init(&conn_entry->list);
7173 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
7174 record_count = conn_hdr->length * sizeof(uint32_t)/
7175 sizeof(struct lpfc_fcf_conn_rec);
7177 conn_rec = (struct lpfc_fcf_conn_rec *)
7178 (buff + sizeof(struct lpfc_fcf_conn_hdr));
7180 for (i = 0; i < record_count; i++) {
7181 if (!(conn_rec[i].flags & FCFCNCT_VALID))
7183 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
7186 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7187 "2566 Failed to allocate connection"
7192 memcpy(&conn_entry->conn_rec, &conn_rec[i],
7193 sizeof(struct lpfc_fcf_conn_rec));
7194 list_add_tail(&conn_entry->list,
7195 &phba->fcf_conn_rec_list);
7198 if (!list_empty(&phba->fcf_conn_rec_list)) {
7200 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
7202 conn_rec = &conn_entry->conn_rec;
7203 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7204 "3345 FCF connection list rec[%02d]: "
7205 "flags:x%04x, vtag:x%04x, "
7206 "fabric_name:x%02x:%02x:%02x:%02x:"
7207 "%02x:%02x:%02x:%02x, "
7208 "switch_name:x%02x:%02x:%02x:%02x:"
7209 "%02x:%02x:%02x:%02x\n", i++,
7210 conn_rec->flags, conn_rec->vlan_tag,
7211 conn_rec->fabric_name[0],
7212 conn_rec->fabric_name[1],
7213 conn_rec->fabric_name[2],
7214 conn_rec->fabric_name[3],
7215 conn_rec->fabric_name[4],
7216 conn_rec->fabric_name[5],
7217 conn_rec->fabric_name[6],
7218 conn_rec->fabric_name[7],
7219 conn_rec->switch_name[0],
7220 conn_rec->switch_name[1],
7221 conn_rec->switch_name[2],
7222 conn_rec->switch_name[3],
7223 conn_rec->switch_name[4],
7224 conn_rec->switch_name[5],
7225 conn_rec->switch_name[6],
7226 conn_rec->switch_name[7]);
7232 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
7233 * @phba: Pointer to hba context object.
7234 * @buff: Buffer containing the FCoE parameter data structure.
7236 * This function update driver data structure with config
7237 * parameters read from config region 23.
7240 lpfc_read_fcoe_param(struct lpfc_hba *phba,
7243 struct lpfc_fip_param_hdr *fcoe_param_hdr;
7244 struct lpfc_fcoe_params *fcoe_param;
7246 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
7248 fcoe_param = (struct lpfc_fcoe_params *)
7249 (buff + sizeof(struct lpfc_fip_param_hdr));
7251 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
7252 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
7255 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
7256 phba->valid_vlan = 1;
7257 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
7261 phba->fc_map[0] = fcoe_param->fc_map[0];
7262 phba->fc_map[1] = fcoe_param->fc_map[1];
7263 phba->fc_map[2] = fcoe_param->fc_map[2];
7268 * lpfc_get_rec_conf23 - Get a record type in config region data.
7269 * @buff: Buffer containing config region 23 data.
7270 * @size: Size of the data buffer.
7271 * @rec_type: Record type to be searched.
7273 * This function searches config region data to find the beginning
7274 * of the record specified by record_type. If record found, this
7275 * function return pointer to the record else return NULL.
7278 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
7280 uint32_t offset = 0, rec_length;
7282 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
7283 (size < sizeof(uint32_t)))
7286 rec_length = buff[offset + 1];
7289 * One TLV record has one word header and number of data words
7290 * specified in the rec_length field of the record header.
7292 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
7294 if (buff[offset] == rec_type)
7295 return &buff[offset];
7297 if (buff[offset] == LPFC_REGION23_LAST_REC)
7300 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
7301 rec_length = buff[offset + 1];
7307 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
7308 * @phba: Pointer to lpfc_hba data structure.
7309 * @buff: Buffer containing config region 23 data.
7310 * @size: Size of the data buffer.
7312 * This function parses the FCoE config parameters in config region 23 and
7313 * populate driver data structure with the parameters.
7316 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
7320 uint32_t offset = 0;
7324 * If data size is less than 2 words signature and version cannot be
7327 if (size < 2*sizeof(uint32_t))
7330 /* Check the region signature first */
7331 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
7332 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7333 "2567 Config region 23 has bad signature\n");
7339 /* Check the data structure version */
7340 if (buff[offset] != LPFC_REGION23_VERSION) {
7341 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7342 "2568 Config region 23 has bad version\n");
7347 /* Read FCoE param record */
7348 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7349 size - offset, FCOE_PARAM_TYPE);
7351 lpfc_read_fcoe_param(phba, rec_ptr);
7353 /* Read FCF connection table */
7354 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7355 size - offset, FCOE_CONN_TBL_TYPE);
7357 lpfc_read_fcf_conn_tbl(phba, rec_ptr);