1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2023 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/kthread.h>
29 #include <linux/interrupt.h>
30 #include <linux/lockdep.h>
31 #include <linux/utsname.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/fc/fc_fs.h>
42 #include "lpfc_disc.h"
44 #include "lpfc_sli4.h"
46 #include "lpfc_scsi.h"
47 #include "lpfc_nvme.h"
48 #include "lpfc_logmsg.h"
49 #include "lpfc_crtn.h"
50 #include "lpfc_vport.h"
51 #include "lpfc_debugfs.h"
53 /* AlpaArray for assignment of scsid for scan-down and bind_method */
54 static uint8_t lpfcAlpaArray[] = {
55 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
56 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
57 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
58 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
59 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
60 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
61 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
62 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
63 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
64 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
65 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
66 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
67 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
70 static void lpfc_disc_timeout_handler(struct lpfc_vport *);
71 static void lpfc_disc_flush_list(struct lpfc_vport *vport);
72 static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
73 static int lpfc_fcf_inuse(struct lpfc_hba *);
74 static void lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
75 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba);
76 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba);
79 lpfc_valid_xpt_node(struct lpfc_nodelist *ndlp)
81 if (ndlp->nlp_fc4_type ||
82 ndlp->nlp_type & NLP_FABRIC)
86 /* The source of a terminate rport I/O is either a dev_loss_tmo
87 * event or a call to fc_remove_host. While the rport should be
88 * valid during these downcalls, the transport can call twice
89 * in a single event. This routine provides somoe protection
90 * as the NDLP isn't really free, just released to the pool.
93 lpfc_rport_invalid(struct fc_rport *rport)
95 struct lpfc_rport_data *rdata;
96 struct lpfc_nodelist *ndlp;
99 pr_err("**** %s: NULL rport, exit.\n", __func__);
103 rdata = rport->dd_data;
105 pr_err("**** %s: NULL dd_data on rport x%px SID x%x\n",
106 __func__, rport, rport->scsi_target_id);
112 pr_info("**** %s: NULL ndlp on rport x%px SID x%x\n",
113 __func__, rport, rport->scsi_target_id);
118 pr_err("**** %s: Null vport on ndlp x%px, DID x%x rport x%px "
119 "SID x%x\n", __func__, ndlp, ndlp->nlp_DID, rport,
120 rport->scsi_target_id);
127 lpfc_terminate_rport_io(struct fc_rport *rport)
129 struct lpfc_rport_data *rdata;
130 struct lpfc_nodelist *ndlp;
131 struct lpfc_vport *vport;
133 if (lpfc_rport_invalid(rport))
136 rdata = rport->dd_data;
139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
140 "rport terminate: sid:x%x did:x%x flg:x%x",
141 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
143 if (ndlp->nlp_sid != NLP_NO_SID)
144 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
148 * This function will be called when dev_loss_tmo fire.
151 lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
153 struct lpfc_nodelist *ndlp;
154 struct lpfc_vport *vport;
155 struct lpfc_hba *phba;
156 struct lpfc_work_evt *evtp;
157 unsigned long iflags;
159 ndlp = ((struct lpfc_rport_data *)rport->dd_data)->pnode;
166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
167 "rport devlosscb: sid:x%x did:x%x flg:x%x",
168 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
170 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
171 "3181 dev_loss_callbk x%06x, rport x%px flg x%x "
172 "load_flag x%x refcnt %d state %d xpt x%x\n",
173 ndlp->nlp_DID, ndlp->rport, ndlp->nlp_flag,
174 vport->load_flag, kref_read(&ndlp->kref),
175 ndlp->nlp_state, ndlp->fc4_xpt_flags);
177 /* Don't schedule a worker thread event if the vport is going down.
178 * The teardown process cleans up the node via lpfc_drop_node.
180 if (vport->load_flag & FC_UNLOADING) {
181 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
184 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
185 /* clear the NLP_XPT_REGD if the node is not registered
188 if (ndlp->fc4_xpt_flags == NLP_XPT_REGD)
189 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
191 /* Remove the node reference from remote_port_add now.
192 * The driver will not call remote_port_delete.
198 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
201 if (rport->port_name != wwn_to_u64(ndlp->nlp_portname.u.wwn))
202 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
203 "6789 rport name %llx != node port name %llx",
205 wwn_to_u64(ndlp->nlp_portname.u.wwn));
207 evtp = &ndlp->dev_loss_evt;
209 if (!list_empty(&evtp->evt_listp)) {
210 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
211 "6790 rport name %llx dev_loss_evt pending\n",
216 spin_lock_irqsave(&ndlp->lock, iflags);
217 ndlp->nlp_flag |= NLP_IN_DEV_LOSS;
219 /* If there is a PLOGI in progress, and we are in a
220 * NLP_NPR_2B_DISC state, don't turn off the flag.
222 if (ndlp->nlp_state != NLP_STE_PLOGI_ISSUE)
223 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
226 * The backend does not expect any more calls associated with this
227 * rport. Remove the association between rport and ndlp.
229 ndlp->fc4_xpt_flags &= ~SCSI_XPT_REGD;
230 ((struct lpfc_rport_data *)rport->dd_data)->pnode = NULL;
232 spin_unlock_irqrestore(&ndlp->lock, iflags);
234 if (phba->worker_thread) {
235 /* We need to hold the node by incrementing the reference
236 * count until this queued work is done
238 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
240 spin_lock_irqsave(&phba->hbalock, iflags);
241 if (evtp->evt_arg1) {
242 evtp->evt = LPFC_EVT_DEV_LOSS;
243 list_add_tail(&evtp->evt_listp, &phba->work_list);
244 lpfc_worker_wake_up(phba);
246 spin_unlock_irqrestore(&phba->hbalock, iflags);
248 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
249 "3188 worker thread is stopped %s x%06x, "
250 " rport x%px flg x%x load_flag x%x refcnt "
251 "%d\n", __func__, ndlp->nlp_DID,
252 ndlp->rport, ndlp->nlp_flag,
253 vport->load_flag, kref_read(&ndlp->kref));
254 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD)) {
255 spin_lock_irqsave(&ndlp->lock, iflags);
256 /* Node is in dev loss. No further transaction. */
257 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
258 spin_unlock_irqrestore(&ndlp->lock, iflags);
259 lpfc_disc_state_machine(vport, ndlp, NULL,
269 * lpfc_check_inactive_vmid_one - VMID inactivity checker for a vport
270 * @vport: Pointer to vport context object.
272 * This function checks for idle VMID entries related to a particular vport. If
273 * found unused/idle, free them accordingly.
275 static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport)
278 u32 difftime = 0, r, bucket;
281 struct lpfc_vmid *vmp;
283 write_lock(&vport->vmid_lock);
285 if (!vport->cur_vmid_cnt)
288 /* iterate through the table */
289 hash_for_each(vport->hash_table, bucket, vmp, hnode) {
291 if (vmp->flag & LPFC_VMID_REGISTERED) {
292 /* check if the particular VMID is in use */
293 /* for all available per cpu variable */
294 for_each_possible_cpu(cpu) {
295 /* if last access time is less than timeout */
296 lta = per_cpu_ptr(vmp->last_io_time, cpu);
299 difftime = (jiffies) - (*lta);
300 if ((vport->vmid_inactivity_timeout *
301 JIFFIES_PER_HR) > difftime) {
307 /* if none of the cpus have been used by the vm, */
308 /* remove the entry if already registered */
310 /* mark the entry for deregistration */
311 vmp->flag = LPFC_VMID_DE_REGISTER;
312 write_unlock(&vport->vmid_lock);
313 if (vport->vmid_priority_tagging)
314 r = lpfc_vmid_uvem(vport, vmp, false);
316 r = lpfc_vmid_cmd(vport,
320 /* decrement number of active vms and mark */
321 /* entry in slot as free */
322 write_lock(&vport->vmid_lock);
324 struct lpfc_vmid *ht = vmp;
326 vport->cur_vmid_cnt--;
327 ht->flag = LPFC_VMID_SLOT_FREE;
328 free_percpu(ht->last_io_time);
329 ht->last_io_time = NULL;
330 hash_del(&ht->hnode);
336 write_unlock(&vport->vmid_lock);
340 * lpfc_check_inactive_vmid - VMID inactivity checker
341 * @phba: Pointer to hba context object.
343 * This function is called from the worker thread to determine if an entry in
344 * the VMID table can be released since there was no I/O activity seen from that
345 * particular VM for the specified time. When this happens, the entry in the
346 * table is released and also the resources on the switch cleared.
349 static void lpfc_check_inactive_vmid(struct lpfc_hba *phba)
351 struct lpfc_vport *vport;
352 struct lpfc_vport **vports;
355 vports = lpfc_create_vport_work_array(phba);
359 for (i = 0; i <= phba->max_vports; i++) {
360 if ((!vports[i]) && (i == 0))
367 lpfc_check_inactive_vmid_one(vport);
369 lpfc_destroy_vport_work_array(phba, vports);
373 * lpfc_check_nlp_post_devloss - Check to restore ndlp refcnt after devloss
374 * @vport: Pointer to vport object.
375 * @ndlp: Pointer to remote node object.
377 * If NLP_IN_RECOV_POST_DEV_LOSS flag was set due to outstanding recovery of
378 * node during dev_loss_tmo processing, then this function restores the nlp_put
379 * kref decrement from lpfc_dev_loss_tmo_handler.
382 lpfc_check_nlp_post_devloss(struct lpfc_vport *vport,
383 struct lpfc_nodelist *ndlp)
385 unsigned long iflags;
387 spin_lock_irqsave(&ndlp->lock, iflags);
388 if (ndlp->save_flags & NLP_IN_RECOV_POST_DEV_LOSS) {
389 ndlp->save_flags &= ~NLP_IN_RECOV_POST_DEV_LOSS;
390 spin_unlock_irqrestore(&ndlp->lock, iflags);
392 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY | LOG_NODE,
393 "8438 Devloss timeout reversed on DID x%x "
394 "refcnt %d ndlp %p flag x%x "
395 "port_state = x%x\n",
396 ndlp->nlp_DID, kref_read(&ndlp->kref), ndlp,
397 ndlp->nlp_flag, vport->port_state);
398 spin_lock_irqsave(&ndlp->lock, iflags);
400 spin_unlock_irqrestore(&ndlp->lock, iflags);
404 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
405 * @ndlp: Pointer to remote node object.
407 * This function is called from the worker thread when devloss timeout timer
408 * expires. For SLI4 host, this routine shall return 1 when at lease one
409 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
410 * routine shall return 0 when there is no remote node is still in use of FCF
411 * when devloss timeout happened to this @ndlp.
414 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
416 struct lpfc_vport *vport;
417 struct lpfc_hba *phba;
421 bool recovering = false;
422 struct fc_vport *fc_vport = NULL;
423 unsigned long iflags;
426 name = (uint8_t *)&ndlp->nlp_portname;
429 if (phba->sli_rev == LPFC_SLI_REV4)
430 fcf_inuse = lpfc_fcf_inuse(phba);
432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
433 "rport devlosstmo:did:x%x type:x%x id:x%x",
434 ndlp->nlp_DID, ndlp->nlp_type, ndlp->nlp_sid);
436 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
437 "3182 %s x%06x, nflag x%x xflags x%x refcnt %d\n",
438 __func__, ndlp->nlp_DID, ndlp->nlp_flag,
439 ndlp->fc4_xpt_flags, kref_read(&ndlp->kref));
441 /* If the driver is recovering the rport, ignore devloss. */
442 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
443 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
444 "0284 Devloss timeout Ignored on "
445 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
447 *name, *(name+1), *(name+2), *(name+3),
448 *(name+4), *(name+5), *(name+6), *(name+7),
451 spin_lock_irqsave(&ndlp->lock, iflags);
452 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
453 spin_unlock_irqrestore(&ndlp->lock, iflags);
457 /* Fabric nodes are done. */
458 if (ndlp->nlp_type & NLP_FABRIC) {
459 spin_lock_irqsave(&ndlp->lock, iflags);
461 /* The driver has to account for a race between any fabric
462 * node that's in recovery when dev_loss_tmo expires. When this
463 * happens, the driver has to allow node recovery.
465 switch (ndlp->nlp_DID) {
467 fc_vport = vport->fc_vport;
470 if (fc_vport->vport_state ==
471 FC_VPORT_INITIALIZING)
474 /* Physical port path. */
475 if (phba->hba_flag & HBA_FLOGI_OUTSTANDING)
479 case Fabric_Cntl_DID:
480 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
486 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
487 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE)
491 /* Ensure the nlp_DID at least has the correct prefix.
492 * The fabric domain controller's last three nibbles
493 * vary so we handle it in the default case.
495 if (ndlp->nlp_DID & Fabric_DID_MASK) {
496 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
497 ndlp->nlp_state <= NLP_STE_REG_LOGIN_ISSUE)
502 spin_unlock_irqrestore(&ndlp->lock, iflags);
504 /* Mark an NLP_IN_RECOV_POST_DEV_LOSS flag to know if reversing
505 * the following lpfc_nlp_put is necessary after fabric node is
509 lpfc_printf_vlog(vport, KERN_INFO,
510 LOG_DISCOVERY | LOG_NODE,
511 "8436 Devloss timeout marked on "
512 "DID x%x refcnt %d ndlp %p "
513 "flag x%x port_state = x%x\n",
514 ndlp->nlp_DID, kref_read(&ndlp->kref),
515 ndlp, ndlp->nlp_flag,
517 spin_lock_irqsave(&ndlp->lock, iflags);
518 ndlp->save_flags |= NLP_IN_RECOV_POST_DEV_LOSS;
519 spin_unlock_irqrestore(&ndlp->lock, iflags);
520 } else if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
521 /* Fabric node fully recovered before this dev_loss_tmo
522 * queue work is processed. Thus, ignore the
523 * dev_loss_tmo event.
525 lpfc_printf_vlog(vport, KERN_INFO,
526 LOG_DISCOVERY | LOG_NODE,
527 "8437 Devloss timeout ignored on "
528 "DID x%x refcnt %d ndlp %p "
529 "flag x%x port_state = x%x\n",
530 ndlp->nlp_DID, kref_read(&ndlp->kref),
531 ndlp, ndlp->nlp_flag,
536 spin_lock_irqsave(&ndlp->lock, iflags);
537 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
538 spin_unlock_irqrestore(&ndlp->lock, iflags);
543 if (ndlp->nlp_sid != NLP_NO_SID) {
545 lpfc_sli_abort_iocb(vport, ndlp->nlp_sid, 0, LPFC_CTX_TGT);
549 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
550 "0203 Devloss timeout on "
551 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
552 "NPort x%06x Data: x%x x%x x%x refcnt %d\n",
553 *name, *(name+1), *(name+2), *(name+3),
554 *(name+4), *(name+5), *(name+6), *(name+7),
555 ndlp->nlp_DID, ndlp->nlp_flag,
556 ndlp->nlp_state, ndlp->nlp_rpi,
557 kref_read(&ndlp->kref));
559 lpfc_printf_vlog(vport, KERN_INFO, LOG_TRACE_EVENT,
560 "0204 Devloss timeout on "
561 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
562 "NPort x%06x Data: x%x x%x x%x\n",
563 *name, *(name+1), *(name+2), *(name+3),
564 *(name+4), *(name+5), *(name+6), *(name+7),
565 ndlp->nlp_DID, ndlp->nlp_flag,
566 ndlp->nlp_state, ndlp->nlp_rpi);
568 spin_lock_irqsave(&ndlp->lock, iflags);
569 ndlp->nlp_flag &= ~NLP_IN_DEV_LOSS;
570 spin_unlock_irqrestore(&ndlp->lock, iflags);
572 /* If we are devloss, but we are in the process of rediscovering the
573 * ndlp, don't issue a NLP_EVT_DEVICE_RM event.
575 if (ndlp->nlp_state >= NLP_STE_PLOGI_ISSUE &&
576 ndlp->nlp_state <= NLP_STE_PRLI_ISSUE) {
580 if (!(ndlp->fc4_xpt_flags & NVME_XPT_REGD))
581 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
586 static void lpfc_check_vmid_qfpa_issue(struct lpfc_hba *phba)
588 struct lpfc_vport *vport;
589 struct lpfc_vport **vports;
592 vports = lpfc_create_vport_work_array(phba);
596 for (i = 0; i <= phba->max_vports; i++) {
597 if ((!vports[i]) && (i == 0))
604 if (vport->vmid_flag & LPFC_VMID_ISSUE_QFPA) {
605 if (!lpfc_issue_els_qfpa(vport))
606 vport->vmid_flag &= ~LPFC_VMID_ISSUE_QFPA;
609 lpfc_destroy_vport_work_array(phba, vports);
613 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
614 * @phba: Pointer to hba context object.
615 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
616 * @nlp_did: remote node identifer with devloss timeout.
618 * This function is called from the worker thread after invoking devloss
619 * timeout handler and releasing the reference count for the ndlp with
620 * which the devloss timeout was handled for SLI4 host. For the devloss
621 * timeout of the last remote node which had been in use of FCF, when this
622 * routine is invoked, it shall be guaranteed that none of the remote are
623 * in-use of FCF. When devloss timeout to the last remote using the FCF,
624 * if the FIP engine is neither in FCF table scan process nor roundrobin
625 * failover process, the in-use FCF shall be unregistered. If the FIP
626 * engine is in FCF discovery process, the devloss timeout state shall
627 * be set for either the FCF table scan process or roundrobin failover
628 * process to unregister the in-use FCF.
631 lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
634 /* If devloss timeout happened to a remote node when FCF had no
635 * longer been in-use, do nothing.
640 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
641 spin_lock_irq(&phba->hbalock);
642 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
643 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
644 spin_unlock_irq(&phba->hbalock);
647 phba->hba_flag |= HBA_DEVLOSS_TMO;
648 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
649 "2847 Last remote node (x%x) using "
650 "FCF devloss tmo\n", nlp_did);
652 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
653 spin_unlock_irq(&phba->hbalock);
654 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
655 "2868 Devloss tmo to FCF rediscovery "
659 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
660 spin_unlock_irq(&phba->hbalock);
661 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
662 "2869 Devloss tmo to idle FIP engine, "
663 "unreg in-use FCF and rescan.\n");
664 /* Unregister in-use FCF and rescan */
665 lpfc_unregister_fcf_rescan(phba);
668 spin_unlock_irq(&phba->hbalock);
669 if (phba->hba_flag & FCF_TS_INPROG)
670 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
671 "2870 FCF table scan in progress\n");
672 if (phba->hba_flag & FCF_RR_INPROG)
673 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
674 "2871 FLOGI roundrobin FCF failover "
677 lpfc_unregister_unused_fcf(phba);
681 * lpfc_alloc_fast_evt - Allocates data structure for posting event
682 * @phba: Pointer to hba context object.
684 * This function is called from the functions which need to post
685 * events from interrupt context. This function allocates data
686 * structure required for posting event. It also keeps track of
687 * number of events pending and prevent event storm when there are
690 struct lpfc_fast_path_event *
691 lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
692 struct lpfc_fast_path_event *ret;
694 /* If there are lot of fast event do not exhaust memory due to this */
695 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
698 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
701 atomic_inc(&phba->fast_event_count);
702 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
703 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
709 * lpfc_free_fast_evt - Frees event data structure
710 * @phba: Pointer to hba context object.
711 * @evt: Event object which need to be freed.
713 * This function frees the data structure required for posting
717 lpfc_free_fast_evt(struct lpfc_hba *phba,
718 struct lpfc_fast_path_event *evt) {
720 atomic_dec(&phba->fast_event_count);
725 * lpfc_send_fastpath_evt - Posts events generated from fast path
726 * @phba: Pointer to hba context object.
727 * @evtp: Event data structure.
729 * This function is called from worker thread, when the interrupt
730 * context need to post an event. This function posts the event
731 * to fc transport netlink interface.
734 lpfc_send_fastpath_evt(struct lpfc_hba *phba,
735 struct lpfc_work_evt *evtp)
737 unsigned long evt_category, evt_sub_category;
738 struct lpfc_fast_path_event *fast_evt_data;
740 uint32_t evt_data_size;
741 struct Scsi_Host *shost;
743 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
746 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
747 evt_sub_category = (unsigned long) fast_evt_data->un.
748 fabric_evt.subcategory;
749 shost = lpfc_shost_from_vport(fast_evt_data->vport);
750 if (evt_category == FC_REG_FABRIC_EVENT) {
751 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
752 evt_data = (char *) &fast_evt_data->un.read_check_error;
753 evt_data_size = sizeof(fast_evt_data->un.
755 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
756 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
757 evt_data = (char *) &fast_evt_data->un.fabric_evt;
758 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
760 lpfc_free_fast_evt(phba, fast_evt_data);
763 } else if (evt_category == FC_REG_SCSI_EVENT) {
764 switch (evt_sub_category) {
765 case LPFC_EVENT_QFULL:
766 case LPFC_EVENT_DEVBSY:
767 evt_data = (char *) &fast_evt_data->un.scsi_evt;
768 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
770 case LPFC_EVENT_CHECK_COND:
771 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
772 evt_data_size = sizeof(fast_evt_data->un.
775 case LPFC_EVENT_VARQUEDEPTH:
776 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
777 evt_data_size = sizeof(fast_evt_data->un.
781 lpfc_free_fast_evt(phba, fast_evt_data);
785 lpfc_free_fast_evt(phba, fast_evt_data);
789 if (phba->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
790 fc_host_post_vendor_event(shost,
791 fc_get_event_number(),
796 lpfc_free_fast_evt(phba, fast_evt_data);
801 lpfc_work_list_done(struct lpfc_hba *phba)
803 struct lpfc_work_evt *evtp = NULL;
804 struct lpfc_nodelist *ndlp;
810 spin_lock_irq(&phba->hbalock);
811 while (!list_empty(&phba->work_list)) {
812 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
814 spin_unlock_irq(&phba->hbalock);
815 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
818 case LPFC_EVT_ELS_RETRY:
819 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
821 lpfc_els_retry_delay_handler(ndlp);
822 free_evt = 0; /* evt is part of ndlp */
824 /* decrement the node reference count held
825 * for this queued work
829 case LPFC_EVT_DEV_LOSS:
830 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
831 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
833 /* decrement the node reference count held for
836 nlp_did = ndlp->nlp_DID;
838 if (phba->sli_rev == LPFC_SLI_REV4)
839 lpfc_sli4_post_dev_loss_tmo_handler(phba,
843 case LPFC_EVT_RECOVER_PORT:
844 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
846 lpfc_sli_abts_recover_port(ndlp->vport, ndlp);
849 /* decrement the node reference count held for
854 case LPFC_EVT_ONLINE:
855 if (phba->link_state < LPFC_LINK_DOWN)
856 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
858 *(int *) (evtp->evt_arg1) = 0;
859 complete((struct completion *)(evtp->evt_arg2));
861 case LPFC_EVT_OFFLINE_PREP:
862 if (phba->link_state >= LPFC_LINK_DOWN)
863 lpfc_offline_prep(phba, LPFC_MBX_WAIT);
864 *(int *)(evtp->evt_arg1) = 0;
865 complete((struct completion *)(evtp->evt_arg2));
867 case LPFC_EVT_OFFLINE:
869 lpfc_sli_brdrestart(phba);
870 *(int *)(evtp->evt_arg1) =
871 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
872 lpfc_unblock_mgmt_io(phba);
873 complete((struct completion *)(evtp->evt_arg2));
875 case LPFC_EVT_WARM_START:
877 lpfc_reset_barrier(phba);
878 lpfc_sli_brdreset(phba);
879 lpfc_hba_down_post(phba);
880 *(int *)(evtp->evt_arg1) =
881 lpfc_sli_brdready(phba, HS_MBRDY);
882 lpfc_unblock_mgmt_io(phba);
883 complete((struct completion *)(evtp->evt_arg2));
887 *(int *)(evtp->evt_arg1)
888 = (phba->pport->stopped)
889 ? 0 : lpfc_sli_brdkill(phba);
890 lpfc_unblock_mgmt_io(phba);
891 complete((struct completion *)(evtp->evt_arg2));
893 case LPFC_EVT_FASTPATH_MGMT_EVT:
894 lpfc_send_fastpath_evt(phba, evtp);
897 case LPFC_EVT_RESET_HBA:
898 if (!(phba->pport->load_flag & FC_UNLOADING))
899 lpfc_reset_hba(phba);
904 spin_lock_irq(&phba->hbalock);
906 spin_unlock_irq(&phba->hbalock);
911 lpfc_work_done(struct lpfc_hba *phba)
913 struct lpfc_sli_ring *pring;
914 uint32_t ha_copy, status, control, work_port_events;
915 struct lpfc_vport **vports;
916 struct lpfc_vport *vport;
920 hba_pci_err = test_bit(HBA_PCI_ERR, &phba->bit_flags);
921 spin_lock_irq(&phba->hbalock);
922 ha_copy = phba->work_ha;
924 spin_unlock_irq(&phba->hbalock);
928 /* First, try to post the next mailbox command to SLI4 device */
929 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC && !hba_pci_err)
930 lpfc_sli4_post_async_mbox(phba);
932 if (ha_copy & HA_ERATT) {
933 /* Handle the error attention event */
934 lpfc_handle_eratt(phba);
936 if (phba->fw_dump_cmpl) {
937 complete(phba->fw_dump_cmpl);
938 phba->fw_dump_cmpl = NULL;
942 if (ha_copy & HA_MBATT)
943 lpfc_sli_handle_mb_event(phba);
945 if (ha_copy & HA_LATT)
946 lpfc_handle_latt(phba);
948 /* Handle VMID Events */
949 if (lpfc_is_vmid_enabled(phba) && !hba_pci_err) {
950 if (phba->pport->work_port_events &
951 WORKER_CHECK_VMID_ISSUE_QFPA) {
952 lpfc_check_vmid_qfpa_issue(phba);
953 phba->pport->work_port_events &=
954 ~WORKER_CHECK_VMID_ISSUE_QFPA;
956 if (phba->pport->work_port_events &
957 WORKER_CHECK_INACTIVE_VMID) {
958 lpfc_check_inactive_vmid(phba);
959 phba->pport->work_port_events &=
960 ~WORKER_CHECK_INACTIVE_VMID;
964 /* Process SLI4 events */
965 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
966 if (phba->hba_flag & HBA_RRQ_ACTIVE)
967 lpfc_handle_rrq_active(phba);
968 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
969 lpfc_sli4_els_xri_abort_event_proc(phba);
970 if (phba->hba_flag & ASYNC_EVENT)
971 lpfc_sli4_async_event_proc(phba);
972 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
973 spin_lock_irq(&phba->hbalock);
974 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
975 spin_unlock_irq(&phba->hbalock);
976 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
978 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
979 lpfc_sli4_fcf_redisc_event_proc(phba);
982 vports = lpfc_create_vport_work_array(phba);
984 for (i = 0; i <= phba->max_vports; i++) {
986 * We could have no vports in array if unloading, so if
987 * this happens then just use the pport
989 if (vports[i] == NULL && i == 0)
995 spin_lock_irq(&vport->work_port_lock);
996 work_port_events = vport->work_port_events;
997 vport->work_port_events &= ~work_port_events;
998 spin_unlock_irq(&vport->work_port_lock);
1001 if (work_port_events & WORKER_DISC_TMO)
1002 lpfc_disc_timeout_handler(vport);
1003 if (work_port_events & WORKER_ELS_TMO)
1004 lpfc_els_timeout_handler(vport);
1005 if (work_port_events & WORKER_HB_TMO)
1006 lpfc_hb_timeout_handler(phba);
1007 if (work_port_events & WORKER_MBOX_TMO)
1008 lpfc_mbox_timeout_handler(phba);
1009 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
1010 lpfc_unblock_fabric_iocbs(phba);
1011 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
1012 lpfc_ramp_down_queue_handler(phba);
1013 if (work_port_events & WORKER_DELAYED_DISC_TMO)
1014 lpfc_delayed_disc_timeout_handler(vport);
1016 lpfc_destroy_vport_work_array(phba, vports);
1018 pring = lpfc_phba_elsring(phba);
1019 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
1020 status >>= (4*LPFC_ELS_RING);
1021 if (pring && (status & HA_RXMASK ||
1022 pring->flag & LPFC_DEFERRED_RING_EVENT ||
1023 phba->hba_flag & HBA_SP_QUEUE_EVT)) {
1024 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
1025 pring->flag |= LPFC_DEFERRED_RING_EVENT;
1026 /* Preserve legacy behavior. */
1027 if (!(phba->hba_flag & HBA_SP_QUEUE_EVT))
1028 set_bit(LPFC_DATA_READY, &phba->data_flags);
1030 /* Driver could have abort request completed in queue
1031 * when link goes down. Allow for this transition.
1033 if (phba->link_state >= LPFC_LINK_DOWN ||
1034 phba->link_flag & LS_MDS_LOOPBACK) {
1035 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
1036 lpfc_sli_handle_slow_ring_event(phba, pring,
1041 if (phba->sli_rev == LPFC_SLI_REV4)
1042 lpfc_drain_txq(phba);
1044 * Turn on Ring interrupts
1046 if (phba->sli_rev <= LPFC_SLI_REV3) {
1047 spin_lock_irq(&phba->hbalock);
1048 control = readl(phba->HCregaddr);
1049 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
1050 lpfc_debugfs_slow_ring_trc(phba,
1051 "WRK Enable ring: cntl:x%x hacopy:x%x",
1052 control, ha_copy, 0);
1054 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
1055 writel(control, phba->HCregaddr);
1056 readl(phba->HCregaddr); /* flush */
1058 lpfc_debugfs_slow_ring_trc(phba,
1059 "WRK Ring ok: cntl:x%x hacopy:x%x",
1060 control, ha_copy, 0);
1062 spin_unlock_irq(&phba->hbalock);
1065 lpfc_work_list_done(phba);
1069 lpfc_do_work(void *p)
1071 struct lpfc_hba *phba = p;
1074 set_user_nice(current, MIN_NICE);
1075 current->flags |= PF_NOFREEZE;
1076 phba->data_flags = 0;
1078 while (!kthread_should_stop()) {
1079 /* wait and check worker queue activities */
1080 rc = wait_event_interruptible(phba->work_waitq,
1081 (test_and_clear_bit(LPFC_DATA_READY,
1083 || kthread_should_stop()));
1084 /* Signal wakeup shall terminate the worker thread */
1086 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
1087 "0433 Wakeup on signal: rc=x%x\n", rc);
1091 /* Attend pending lpfc data processing */
1092 lpfc_work_done(phba);
1094 phba->worker_thread = NULL;
1095 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1096 "0432 Worker thread stopped.\n");
1101 * This is only called to handle FC worker events. Since this a rare
1102 * occurrence, we allocate a struct lpfc_work_evt structure here instead of
1103 * embedding it in the IOCB.
1106 lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
1109 struct lpfc_work_evt *evtp;
1110 unsigned long flags;
1113 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
1114 * be queued to worker thread for processing
1116 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
1120 evtp->evt_arg1 = arg1;
1121 evtp->evt_arg2 = arg2;
1124 spin_lock_irqsave(&phba->hbalock, flags);
1125 list_add_tail(&evtp->evt_listp, &phba->work_list);
1126 spin_unlock_irqrestore(&phba->hbalock, flags);
1128 lpfc_worker_wake_up(phba);
1134 lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
1136 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1137 struct lpfc_hba *phba = vport->phba;
1138 struct lpfc_nodelist *ndlp, *next_ndlp;
1140 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
1141 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
1142 ((vport->port_type == LPFC_NPIV_PORT) &&
1143 ((ndlp->nlp_DID == NameServer_DID) ||
1144 (ndlp->nlp_DID == FDMI_DID) ||
1145 (ndlp->nlp_DID == Fabric_Cntl_DID))))
1146 lpfc_unreg_rpi(vport, ndlp);
1148 /* Leave Fabric nodes alone on link down */
1149 if ((phba->sli_rev < LPFC_SLI_REV4) &&
1150 (!remove && ndlp->nlp_type & NLP_FABRIC))
1153 /* Notify transport of connectivity loss to trigger cleanup. */
1154 if (phba->nvmet_support &&
1155 ndlp->nlp_state == NLP_STE_UNMAPPED_NODE)
1156 lpfc_nvmet_invalidate_host(phba, ndlp);
1158 lpfc_disc_state_machine(vport, ndlp, NULL,
1161 : NLP_EVT_DEVICE_RECOVERY);
1163 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
1164 if (phba->sli_rev == LPFC_SLI_REV4)
1165 lpfc_sli4_unreg_all_rpis(vport);
1166 lpfc_mbx_unreg_vpi(vport);
1167 spin_lock_irq(shost->host_lock);
1168 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1169 spin_unlock_irq(shost->host_lock);
1174 lpfc_port_link_failure(struct lpfc_vport *vport)
1176 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
1178 /* Cleanup any outstanding received buffers */
1179 lpfc_cleanup_rcv_buffers(vport);
1181 /* Cleanup any outstanding RSCN activity */
1182 lpfc_els_flush_rscn(vport);
1184 /* Cleanup any outstanding ELS commands */
1185 lpfc_els_flush_cmd(vport);
1187 lpfc_cleanup_rpis(vport, 0);
1189 /* Turn off discovery timer if its running */
1190 lpfc_can_disctmo(vport);
1194 lpfc_linkdown_port(struct lpfc_vport *vport)
1196 struct lpfc_hba *phba = vport->phba;
1197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1199 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1200 fc_host_post_event(shost, fc_get_event_number(),
1201 FCH_EVT_LINKDOWN, 0);
1203 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1204 "Link Down: state:x%x rtry:x%x flg:x%x",
1205 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1207 lpfc_port_link_failure(vport);
1209 /* Stop delayed Nport discovery */
1210 spin_lock_irq(shost->host_lock);
1211 vport->fc_flag &= ~FC_DISC_DELAYED;
1212 spin_unlock_irq(shost->host_lock);
1213 del_timer_sync(&vport->delayed_disc_tmo);
1215 if (phba->sli_rev == LPFC_SLI_REV4 &&
1216 vport->port_type == LPFC_PHYSICAL_PORT &&
1217 phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG) {
1218 /* Assume success on link up */
1219 phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
1224 lpfc_linkdown(struct lpfc_hba *phba)
1226 struct lpfc_vport *vport = phba->pport;
1227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1228 struct lpfc_vport **vports;
1233 if (phba->link_state == LPFC_LINK_DOWN)
1236 /* Block all SCSI stack I/Os */
1237 lpfc_scsi_dev_block(phba);
1238 offline = pci_channel_offline(phba->pcidev);
1240 phba->defer_flogi_acc_flag = false;
1242 /* Clear external loopback plug detected flag */
1243 phba->link_flag &= ~LS_EXTERNAL_LOOPBACK;
1245 spin_lock_irq(&phba->hbalock);
1246 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1247 spin_unlock_irq(&phba->hbalock);
1248 if (phba->link_state > LPFC_LINK_DOWN) {
1249 phba->link_state = LPFC_LINK_DOWN;
1250 if (phba->sli4_hba.conf_trunk) {
1251 phba->trunk_link.link0.state = 0;
1252 phba->trunk_link.link1.state = 0;
1253 phba->trunk_link.link2.state = 0;
1254 phba->trunk_link.link3.state = 0;
1255 phba->trunk_link.phy_lnk_speed =
1256 LPFC_LINK_SPEED_UNKNOWN;
1257 phba->sli4_hba.link_state.logical_speed =
1258 LPFC_LINK_SPEED_UNKNOWN;
1260 spin_lock_irq(shost->host_lock);
1261 phba->pport->fc_flag &= ~FC_LBIT;
1262 spin_unlock_irq(shost->host_lock);
1264 vports = lpfc_create_vport_work_array(phba);
1265 if (vports != NULL) {
1266 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1267 /* Issue a LINK DOWN event to all nodes */
1268 lpfc_linkdown_port(vports[i]);
1270 vports[i]->fc_myDID = 0;
1272 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
1273 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
1274 if (phba->nvmet_support)
1275 lpfc_nvmet_update_targetport(phba);
1277 lpfc_nvme_update_localport(vports[i]);
1281 lpfc_destroy_vport_work_array(phba, vports);
1283 /* Clean up any SLI3 firmware default rpi's */
1284 if (phba->sli_rev > LPFC_SLI_REV3 || offline)
1285 goto skip_unreg_did;
1287 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1289 lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
1291 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1292 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1293 == MBX_NOT_FINISHED) {
1294 mempool_free(mb, phba->mbox_mem_pool);
1299 /* Setup myDID for link up if we are in pt2pt mode */
1300 if (phba->pport->fc_flag & FC_PT2PT) {
1301 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1303 lpfc_config_link(phba, mb);
1304 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1306 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
1307 == MBX_NOT_FINISHED) {
1308 mempool_free(mb, phba->mbox_mem_pool);
1311 spin_lock_irq(shost->host_lock);
1312 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
1313 phba->pport->rcv_flogi_cnt = 0;
1314 spin_unlock_irq(shost->host_lock);
1320 lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
1322 struct lpfc_nodelist *ndlp;
1324 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1325 ndlp->nlp_fc4_type &= ~(NLP_FC4_FCP | NLP_FC4_NVME);
1327 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1329 if (ndlp->nlp_type & NLP_FABRIC) {
1330 /* On Linkup its safe to clean up the ndlp
1331 * from Fabric connections.
1333 if (ndlp->nlp_DID != Fabric_DID)
1334 lpfc_unreg_rpi(vport, ndlp);
1335 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1336 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
1337 /* Fail outstanding IO now since device is
1340 lpfc_unreg_rpi(vport, ndlp);
1346 lpfc_linkup_port(struct lpfc_vport *vport)
1348 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1349 struct lpfc_hba *phba = vport->phba;
1351 if ((vport->load_flag & FC_UNLOADING) != 0)
1354 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1355 "Link Up: top:x%x speed:x%x flg:x%x",
1356 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
1358 /* If NPIV is not enabled, only bring the physical port up */
1359 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1360 (vport != phba->pport))
1363 if (vport->cfg_enable_fc4_type != LPFC_ENABLE_NVME)
1364 fc_host_post_event(shost, fc_get_event_number(),
1367 spin_lock_irq(shost->host_lock);
1368 if (phba->defer_flogi_acc_flag)
1369 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_RSCN_MODE |
1370 FC_NLP_MORE | FC_RSCN_DISCOVERY);
1372 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI |
1373 FC_ABORT_DISCOVERY | FC_RSCN_MODE |
1374 FC_NLP_MORE | FC_RSCN_DISCOVERY);
1375 vport->fc_flag |= FC_NDISC_ACTIVE;
1376 vport->fc_ns_retry = 0;
1377 spin_unlock_irq(shost->host_lock);
1378 lpfc_setup_fdmi_mask(vport);
1380 lpfc_linkup_cleanup_nodes(vport);
1384 lpfc_linkup(struct lpfc_hba *phba)
1386 struct lpfc_vport **vports;
1388 struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
1390 phba->link_state = LPFC_LINK_UP;
1392 /* Unblock fabric iocbs if they are blocked */
1393 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
1394 del_timer_sync(&phba->fabric_block_timer);
1396 vports = lpfc_create_vport_work_array(phba);
1398 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
1399 lpfc_linkup_port(vports[i]);
1400 lpfc_destroy_vport_work_array(phba, vports);
1402 /* Clear the pport flogi counter in case the link down was
1403 * absorbed without an ACQE. No lock here - in worker thread
1404 * and discovery is synchronized.
1406 spin_lock_irq(shost->host_lock);
1407 phba->pport->rcv_flogi_cnt = 0;
1408 spin_unlock_irq(shost->host_lock);
1410 /* reinitialize initial HBA flag */
1411 phba->hba_flag &= ~(HBA_FLOGI_ISSUED | HBA_RHBA_CMPL);
1417 * This routine handles processing a CLEAR_LA mailbox
1418 * command upon completion. It is setup in the LPFC_MBOXQ
1419 * as the completion routine when the command is
1420 * handed off to the SLI layer. SLI3 only.
1423 lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1425 struct lpfc_vport *vport = pmb->vport;
1426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1427 struct lpfc_sli *psli = &phba->sli;
1428 MAILBOX_t *mb = &pmb->u.mb;
1431 /* Since we don't do discovery right now, turn these off here */
1432 psli->sli3_ring[LPFC_EXTRA_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1433 psli->sli3_ring[LPFC_FCP_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
1435 /* Check for error */
1436 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
1437 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
1438 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1439 "0320 CLEAR_LA mbxStatus error x%x hba "
1441 mb->mbxStatus, vport->port_state);
1442 phba->link_state = LPFC_HBA_ERROR;
1446 if (vport->port_type == LPFC_PHYSICAL_PORT)
1447 phba->link_state = LPFC_HBA_READY;
1449 spin_lock_irq(&phba->hbalock);
1450 psli->sli_flag |= LPFC_PROCESS_LA;
1451 control = readl(phba->HCregaddr);
1452 control |= HC_LAINT_ENA;
1453 writel(control, phba->HCregaddr);
1454 readl(phba->HCregaddr); /* flush */
1455 spin_unlock_irq(&phba->hbalock);
1456 mempool_free(pmb, phba->mbox_mem_pool);
1460 /* Device Discovery completes */
1461 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1462 "0225 Device Discovery completes\n");
1463 mempool_free(pmb, phba->mbox_mem_pool);
1465 spin_lock_irq(shost->host_lock);
1466 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
1467 spin_unlock_irq(shost->host_lock);
1469 lpfc_can_disctmo(vport);
1471 /* turn on Link Attention interrupts */
1473 spin_lock_irq(&phba->hbalock);
1474 psli->sli_flag |= LPFC_PROCESS_LA;
1475 control = readl(phba->HCregaddr);
1476 control |= HC_LAINT_ENA;
1477 writel(control, phba->HCregaddr);
1478 readl(phba->HCregaddr); /* flush */
1479 spin_unlock_irq(&phba->hbalock);
1485 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1487 struct lpfc_vport *vport = pmb->vport;
1488 LPFC_MBOXQ_t *sparam_mb;
1489 u16 status = pmb->u.mb.mbxStatus;
1492 mempool_free(pmb, phba->mbox_mem_pool);
1497 /* don't perform discovery for SLI4 loopback diagnostic test */
1498 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1499 !(phba->hba_flag & HBA_FCOE_MODE) &&
1500 (phba->link_flag & LS_LOOPBACK_MODE))
1503 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
1504 vport->fc_flag & FC_PUBLIC_LOOP &&
1505 !(vport->fc_flag & FC_LBIT)) {
1506 /* Need to wait for FAN - use discovery timer
1507 * for timeout. port_state is identically
1508 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1510 lpfc_set_disctmo(vport);
1514 /* Start discovery by sending a FLOGI. port_state is identically
1515 * LPFC_FLOGI while waiting for FLOGI cmpl.
1517 if (vport->port_state != LPFC_FLOGI) {
1518 /* Issue MBX_READ_SPARAM to update CSPs before FLOGI if
1519 * bb-credit recovery is in place.
1521 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
1522 !(phba->link_flag & LS_LOOPBACK_MODE)) {
1523 sparam_mb = mempool_alloc(phba->mbox_mem_pool,
1528 rc = lpfc_read_sparam(phba, sparam_mb, 0);
1530 mempool_free(sparam_mb, phba->mbox_mem_pool);
1533 sparam_mb->vport = vport;
1534 sparam_mb->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
1535 rc = lpfc_sli_issue_mbox(phba, sparam_mb, MBX_NOWAIT);
1536 if (rc == MBX_NOT_FINISHED) {
1537 lpfc_mbox_rsrc_cleanup(phba, sparam_mb,
1542 phba->hba_flag |= HBA_DEFER_FLOGI;
1544 lpfc_initial_flogi(vport);
1547 if (vport->fc_flag & FC_PT2PT)
1548 lpfc_disc_start(vport);
1553 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1554 "0306 CONFIG_LINK mbxStatus error x%x HBA state x%x\n",
1555 status, vport->port_state);
1558 lpfc_linkdown(phba);
1560 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1561 "0200 CONFIG_LINK bad hba state x%x\n",
1564 lpfc_issue_clear_la(phba, vport);
1569 * lpfc_sli4_clear_fcf_rr_bmask
1570 * @phba: pointer to the struct lpfc_hba for this port.
1571 * This fucnction resets the round robin bit mask and clears the
1572 * fcf priority list. The list deletions are done while holding the
1573 * hbalock. The ON_LIST flag and the FLOGI_FAILED flags are cleared
1574 * from the lpfc_fcf_pri record.
1577 lpfc_sli4_clear_fcf_rr_bmask(struct lpfc_hba *phba)
1579 struct lpfc_fcf_pri *fcf_pri;
1580 struct lpfc_fcf_pri *next_fcf_pri;
1581 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
1582 spin_lock_irq(&phba->hbalock);
1583 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
1584 &phba->fcf.fcf_pri_list, list) {
1585 list_del_init(&fcf_pri->list);
1586 fcf_pri->fcf_rec.flag = 0;
1588 spin_unlock_irq(&phba->hbalock);
1591 lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1593 struct lpfc_vport *vport = mboxq->vport;
1595 if (mboxq->u.mb.mbxStatus) {
1596 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1597 "2017 REG_FCFI mbxStatus error x%x "
1598 "HBA state x%x\n", mboxq->u.mb.mbxStatus,
1603 /* Start FCoE discovery by sending a FLOGI. */
1604 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1605 /* Set the FCFI registered flag */
1606 spin_lock_irq(&phba->hbalock);
1607 phba->fcf.fcf_flag |= FCF_REGISTERED;
1608 spin_unlock_irq(&phba->hbalock);
1610 /* If there is a pending FCoE event, restart FCF table scan. */
1611 if ((!(phba->hba_flag & FCF_RR_INPROG)) &&
1612 lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1615 /* Mark successful completion of FCF table scan */
1616 spin_lock_irq(&phba->hbalock);
1617 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1618 phba->hba_flag &= ~FCF_TS_INPROG;
1619 if (vport->port_state != LPFC_FLOGI) {
1620 phba->hba_flag |= FCF_RR_INPROG;
1621 spin_unlock_irq(&phba->hbalock);
1622 lpfc_issue_init_vfi(vport);
1625 spin_unlock_irq(&phba->hbalock);
1629 spin_lock_irq(&phba->hbalock);
1630 phba->hba_flag &= ~FCF_RR_INPROG;
1631 spin_unlock_irq(&phba->hbalock);
1633 mempool_free(mboxq, phba->mbox_mem_pool);
1637 * lpfc_fab_name_match - Check if the fcf fabric name match.
1638 * @fab_name: pointer to fabric name.
1639 * @new_fcf_record: pointer to fcf record.
1641 * This routine compare the fcf record's fabric name with provided
1642 * fabric name. If the fabric name are identical this function
1643 * returns 1 else return 0.
1646 lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1648 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
1650 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1652 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1654 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1656 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1658 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1660 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1662 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1668 * lpfc_sw_name_match - Check if the fcf switch name match.
1669 * @sw_name: pointer to switch name.
1670 * @new_fcf_record: pointer to fcf record.
1672 * This routine compare the fcf record's switch name with provided
1673 * switch name. If the switch name are identical this function
1674 * returns 1 else return 0.
1677 lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1679 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
1681 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1683 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1685 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1687 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1689 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1691 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1693 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1699 * lpfc_mac_addr_match - Check if the fcf mac address match.
1700 * @mac_addr: pointer to mac address.
1701 * @new_fcf_record: pointer to fcf record.
1703 * This routine compare the fcf record's mac address with HBA's
1704 * FCF mac address. If the mac addresses are identical this function
1705 * returns 1 else return 0.
1708 lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
1710 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
1712 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1714 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1716 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1718 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1720 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1726 lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1728 return (curr_vlan_id == new_vlan_id);
1732 * __lpfc_update_fcf_record_pri - update the lpfc_fcf_pri record.
1733 * @phba: pointer to lpfc hba data structure.
1734 * @fcf_index: Index for the lpfc_fcf_record.
1735 * @new_fcf_record: pointer to hba fcf record.
1737 * This routine updates the driver FCF priority record from the new HBA FCF
1738 * record. The hbalock is asserted held in the code path calling this
1742 __lpfc_update_fcf_record_pri(struct lpfc_hba *phba, uint16_t fcf_index,
1743 struct fcf_record *new_fcf_record
1746 struct lpfc_fcf_pri *fcf_pri;
1748 fcf_pri = &phba->fcf.fcf_pri[fcf_index];
1749 fcf_pri->fcf_rec.fcf_index = fcf_index;
1750 /* FCF record priority */
1751 fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
1756 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
1757 * @fcf_rec: pointer to driver fcf record.
1758 * @new_fcf_record: pointer to fcf record.
1760 * This routine copies the FCF information from the FCF
1761 * record to lpfc_hba data structure.
1764 lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1765 struct fcf_record *new_fcf_record)
1768 fcf_rec->fabric_name[0] =
1769 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
1770 fcf_rec->fabric_name[1] =
1771 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
1772 fcf_rec->fabric_name[2] =
1773 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
1774 fcf_rec->fabric_name[3] =
1775 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
1776 fcf_rec->fabric_name[4] =
1777 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
1778 fcf_rec->fabric_name[5] =
1779 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
1780 fcf_rec->fabric_name[6] =
1781 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
1782 fcf_rec->fabric_name[7] =
1783 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
1785 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1786 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1787 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1788 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1789 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1790 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1791 /* FCF record index */
1792 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1793 /* FCF record priority */
1794 fcf_rec->priority = new_fcf_record->fip_priority;
1796 fcf_rec->switch_name[0] =
1797 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
1798 fcf_rec->switch_name[1] =
1799 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
1800 fcf_rec->switch_name[2] =
1801 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
1802 fcf_rec->switch_name[3] =
1803 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
1804 fcf_rec->switch_name[4] =
1805 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
1806 fcf_rec->switch_name[5] =
1807 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
1808 fcf_rec->switch_name[6] =
1809 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
1810 fcf_rec->switch_name[7] =
1811 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
1815 * __lpfc_update_fcf_record - Update driver fcf record
1816 * @phba: pointer to lpfc hba data structure.
1817 * @fcf_rec: pointer to driver fcf record.
1818 * @new_fcf_record: pointer to hba fcf record.
1819 * @addr_mode: address mode to be set to the driver fcf record.
1820 * @vlan_id: vlan tag to be set to the driver fcf record.
1821 * @flag: flag bits to be set to the driver fcf record.
1823 * This routine updates the driver FCF record from the new HBA FCF record
1824 * together with the address mode, vlan_id, and other informations. This
1825 * routine is called with the hbalock held.
1828 __lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1829 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1830 uint16_t vlan_id, uint32_t flag)
1832 lockdep_assert_held(&phba->hbalock);
1834 /* Copy the fields from the HBA's FCF record */
1835 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1836 /* Update other fields of driver FCF record */
1837 fcf_rec->addr_mode = addr_mode;
1838 fcf_rec->vlan_id = vlan_id;
1839 fcf_rec->flag |= (flag | RECORD_VALID);
1840 __lpfc_update_fcf_record_pri(phba,
1841 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record),
1846 * lpfc_register_fcf - Register the FCF with hba.
1847 * @phba: pointer to lpfc hba data structure.
1849 * This routine issues a register fcfi mailbox command to register
1853 lpfc_register_fcf(struct lpfc_hba *phba)
1855 LPFC_MBOXQ_t *fcf_mbxq;
1858 spin_lock_irq(&phba->hbalock);
1859 /* If the FCF is not available do nothing. */
1860 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
1861 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1862 spin_unlock_irq(&phba->hbalock);
1866 /* The FCF is already registered, start discovery */
1867 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
1868 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
1869 phba->hba_flag &= ~FCF_TS_INPROG;
1870 if (phba->pport->port_state != LPFC_FLOGI &&
1871 phba->pport->fc_flag & FC_FABRIC) {
1872 phba->hba_flag |= FCF_RR_INPROG;
1873 spin_unlock_irq(&phba->hbalock);
1874 lpfc_initial_flogi(phba->pport);
1877 spin_unlock_irq(&phba->hbalock);
1880 spin_unlock_irq(&phba->hbalock);
1882 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1884 spin_lock_irq(&phba->hbalock);
1885 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1886 spin_unlock_irq(&phba->hbalock);
1890 lpfc_reg_fcfi(phba, fcf_mbxq);
1891 fcf_mbxq->vport = phba->pport;
1892 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1893 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
1894 if (rc == MBX_NOT_FINISHED) {
1895 spin_lock_irq(&phba->hbalock);
1896 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
1897 spin_unlock_irq(&phba->hbalock);
1898 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
1905 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1906 * @phba: pointer to lpfc hba data structure.
1907 * @new_fcf_record: pointer to fcf record.
1908 * @boot_flag: Indicates if this record used by boot bios.
1909 * @addr_mode: The address mode to be used by this FCF
1910 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
1912 * This routine compare the fcf record with connect list obtained from the
1913 * config region to decide if this FCF can be used for SAN discovery. It returns
1914 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1915 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1916 * is used by boot bios and addr_mode will indicate the addressing mode to be
1917 * used for this FCF when the function returns.
1918 * If the FCF record need to be used with a particular vlan id, the vlan is
1919 * set in the vlan_id on return of the function. If not VLAN tagging need to
1920 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
1923 lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1924 struct fcf_record *new_fcf_record,
1925 uint32_t *boot_flag, uint32_t *addr_mode,
1928 struct lpfc_fcf_conn_entry *conn_entry;
1929 int i, j, fcf_vlan_id = 0;
1931 /* Find the lowest VLAN id in the FCF record */
1932 for (i = 0; i < 512; i++) {
1933 if (new_fcf_record->vlan_bitmap[i]) {
1934 fcf_vlan_id = i * 8;
1936 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1944 /* FCF not valid/available or solicitation in progress */
1945 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1946 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record) ||
1947 bf_get(lpfc_fcf_record_fcf_sol, new_fcf_record))
1950 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
1952 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1954 if (phba->valid_vlan)
1955 *vlan_id = phba->vlan_id;
1957 *vlan_id = LPFC_FCOE_NULL_VID;
1962 * If there are no FCF connection table entry, driver connect to all
1965 if (list_empty(&phba->fcf_conn_rec_list)) {
1967 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1971 * When there are no FCF connect entries, use driver's default
1972 * addressing mode - FPMA.
1974 if (*addr_mode & LPFC_FCF_FPMA)
1975 *addr_mode = LPFC_FCF_FPMA;
1977 /* If FCF record report a vlan id use that vlan id */
1979 *vlan_id = fcf_vlan_id;
1981 *vlan_id = LPFC_FCOE_NULL_VID;
1985 list_for_each_entry(conn_entry,
1986 &phba->fcf_conn_rec_list, list) {
1987 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1990 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1991 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
1994 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1995 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1998 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
2000 * If the vlan bit map does not have the bit set for the
2001 * vlan id to be used, then it is not a match.
2003 if (!(new_fcf_record->vlan_bitmap
2004 [conn_entry->conn_rec.vlan_tag / 8] &
2005 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
2010 * If connection record does not support any addressing mode,
2011 * skip the FCF record.
2013 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
2014 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
2018 * Check if the connection record specifies a required
2021 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2022 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
2025 * If SPMA required but FCF not support this continue.
2027 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2028 !(bf_get(lpfc_fcf_record_mac_addr_prov,
2029 new_fcf_record) & LPFC_FCF_SPMA))
2033 * If FPMA required but FCF not support this continue.
2035 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2036 !(bf_get(lpfc_fcf_record_mac_addr_prov,
2037 new_fcf_record) & LPFC_FCF_FPMA))
2042 * This fcf record matches filtering criteria.
2044 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
2050 * If user did not specify any addressing mode, or if the
2051 * preferred addressing mode specified by user is not supported
2052 * by FCF, allow fabric to pick the addressing mode.
2054 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
2057 * If the user specified a required address mode, assign that
2060 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2061 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
2062 *addr_mode = (conn_entry->conn_rec.flags &
2064 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
2066 * If the user specified a preferred address mode, use the
2067 * addr mode only if FCF support the addr_mode.
2069 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2070 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2071 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2072 (*addr_mode & LPFC_FCF_SPMA))
2073 *addr_mode = LPFC_FCF_SPMA;
2074 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
2075 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
2076 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
2077 (*addr_mode & LPFC_FCF_FPMA))
2078 *addr_mode = LPFC_FCF_FPMA;
2080 /* If matching connect list has a vlan id, use it */
2081 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
2082 *vlan_id = conn_entry->conn_rec.vlan_tag;
2084 * If no vlan id is specified in connect list, use the vlan id
2087 else if (fcf_vlan_id)
2088 *vlan_id = fcf_vlan_id;
2090 *vlan_id = LPFC_FCOE_NULL_VID;
2099 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
2100 * @phba: pointer to lpfc hba data structure.
2101 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
2103 * This function check if there is any fcoe event pending while driver
2104 * scan FCF entries. If there is any pending event, it will restart the
2105 * FCF saning and return 1 else return 0.
2108 lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
2111 * If the Link is up and no FCoE events while in the
2112 * FCF discovery, no need to restart FCF discovery.
2114 if ((phba->link_state >= LPFC_LINK_UP) &&
2115 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
2118 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2119 "2768 Pending link or FCF event during current "
2120 "handling of the previous event: link_state:x%x, "
2121 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
2122 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
2123 phba->fcoe_eventtag);
2125 spin_lock_irq(&phba->hbalock);
2126 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
2127 spin_unlock_irq(&phba->hbalock);
2129 if (phba->link_state >= LPFC_LINK_UP) {
2130 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2131 "2780 Restart FCF table scan due to "
2132 "pending FCF event:evt_tag_at_scan:x%x, "
2133 "evt_tag_current:x%x\n",
2134 phba->fcoe_eventtag_at_fcf_scan,
2135 phba->fcoe_eventtag);
2136 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
2139 * Do not continue FCF discovery and clear FCF_TS_INPROG
2142 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2143 "2833 Stop FCF discovery process due to link "
2144 "state change (x%x)\n", phba->link_state);
2145 spin_lock_irq(&phba->hbalock);
2146 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
2147 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
2148 spin_unlock_irq(&phba->hbalock);
2151 /* Unregister the currently registered FCF if required */
2153 spin_lock_irq(&phba->hbalock);
2154 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
2155 spin_unlock_irq(&phba->hbalock);
2156 lpfc_sli4_unregister_fcf(phba);
2162 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
2163 * @phba: pointer to lpfc hba data structure.
2164 * @fcf_cnt: number of eligible fcf record seen so far.
2166 * This function makes an running random selection decision on FCF record to
2167 * use through a sequence of @fcf_cnt eligible FCF records with equal
2168 * probability. To perform integer manunipulation of random numbers with
2169 * size unit32_t, a 16-bit random number returned from get_random_u16() is
2170 * taken as the random random number generated.
2172 * Returns true when outcome is for the newly read FCF record should be
2173 * chosen; otherwise, return false when outcome is for keeping the previously
2174 * chosen FCF record.
2177 lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
2181 /* Get 16-bit uniform random number */
2182 rand_num = get_random_u16();
2184 /* Decision with probability 1/fcf_cnt */
2185 if ((fcf_cnt * rand_num) < 0xFFFF)
2192 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
2193 * @phba: pointer to lpfc hba data structure.
2194 * @mboxq: pointer to mailbox object.
2195 * @next_fcf_index: pointer to holder of next fcf index.
2197 * This routine parses the non-embedded fcf mailbox command by performing the
2198 * necessarily error checking, non-embedded read FCF record mailbox command
2199 * SGE parsing, and endianness swapping.
2201 * Returns the pointer to the new FCF record in the non-embedded mailbox
2202 * command DMA memory if successfully, other NULL.
2204 static struct fcf_record *
2205 lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
2206 uint16_t *next_fcf_index)
2209 struct lpfc_mbx_sge sge;
2210 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2211 uint32_t shdr_status, shdr_add_status, if_type;
2212 union lpfc_sli4_cfg_shdr *shdr;
2213 struct fcf_record *new_fcf_record;
2215 /* Get the first SGE entry from the non-embedded DMA memory. This
2216 * routine only uses a single SGE.
2218 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2219 if (unlikely(!mboxq->sge_array)) {
2220 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2221 "2524 Failed to get the non-embedded SGE "
2222 "virtual address\n");
2225 virt_addr = mboxq->sge_array->addr[0];
2227 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
2228 lpfc_sli_pcimem_bcopy(shdr, shdr,
2229 sizeof(union lpfc_sli4_cfg_shdr));
2230 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
2231 if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
2232 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
2233 if (shdr_status || shdr_add_status) {
2234 if (shdr_status == STATUS_FCF_TABLE_EMPTY ||
2235 if_type == LPFC_SLI_INTF_IF_TYPE_2)
2236 lpfc_printf_log(phba, KERN_ERR,
2238 "2726 READ_FCF_RECORD Indicates empty "
2241 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2242 "2521 READ_FCF_RECORD mailbox failed "
2243 "with status x%x add_status x%x, "
2244 "mbx\n", shdr_status, shdr_add_status);
2248 /* Interpreting the returned information of the FCF record */
2249 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2250 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
2251 sizeof(struct lpfc_mbx_read_fcf_tbl));
2252 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
2253 new_fcf_record = (struct fcf_record *)(virt_addr +
2254 sizeof(struct lpfc_mbx_read_fcf_tbl));
2255 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
2256 offsetof(struct fcf_record, vlan_bitmap));
2257 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
2258 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
2260 return new_fcf_record;
2264 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
2265 * @phba: pointer to lpfc hba data structure.
2266 * @fcf_record: pointer to the fcf record.
2267 * @vlan_id: the lowest vlan identifier associated to this fcf record.
2268 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
2270 * This routine logs the detailed FCF record if the LOG_FIP loggin is
2274 lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
2275 struct fcf_record *fcf_record,
2277 uint16_t next_fcf_index)
2279 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2280 "2764 READ_FCF_RECORD:\n"
2281 "\tFCF_Index : x%x\n"
2282 "\tFCF_Avail : x%x\n"
2283 "\tFCF_Valid : x%x\n"
2285 "\tFIP_Priority : x%x\n"
2286 "\tMAC_Provider : x%x\n"
2287 "\tLowest VLANID : x%x\n"
2288 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
2289 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2290 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
2291 "\tNext_FCF_Index: x%x\n",
2292 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
2293 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
2294 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
2295 bf_get(lpfc_fcf_record_fcf_sol, fcf_record),
2296 fcf_record->fip_priority,
2297 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
2299 bf_get(lpfc_fcf_record_mac_0, fcf_record),
2300 bf_get(lpfc_fcf_record_mac_1, fcf_record),
2301 bf_get(lpfc_fcf_record_mac_2, fcf_record),
2302 bf_get(lpfc_fcf_record_mac_3, fcf_record),
2303 bf_get(lpfc_fcf_record_mac_4, fcf_record),
2304 bf_get(lpfc_fcf_record_mac_5, fcf_record),
2305 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
2306 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
2307 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
2308 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
2309 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
2310 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
2311 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
2312 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
2313 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
2314 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
2315 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
2316 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
2317 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
2318 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
2319 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
2320 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
2325 * lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
2326 * @phba: pointer to lpfc hba data structure.
2327 * @fcf_rec: pointer to an existing FCF record.
2328 * @new_fcf_record: pointer to a new FCF record.
2329 * @new_vlan_id: vlan id from the new FCF record.
2331 * This function performs matching test of a new FCF record against an existing
2332 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
2333 * will not be used as part of the FCF record matching criteria.
2335 * Returns true if all the fields matching, otherwise returns false.
2338 lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
2339 struct lpfc_fcf_rec *fcf_rec,
2340 struct fcf_record *new_fcf_record,
2341 uint16_t new_vlan_id)
2343 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
2344 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
2346 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
2348 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
2350 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
2352 if (fcf_rec->priority != new_fcf_record->fip_priority)
2358 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
2359 * @vport: Pointer to vport object.
2360 * @fcf_index: index to next fcf.
2362 * This function processing the roundrobin fcf failover to next fcf index.
2363 * When this function is invoked, there will be a current fcf registered
2365 * Return: 0 for continue retrying flogi on currently registered fcf;
2366 * 1 for stop flogi on currently registered fcf;
2368 int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
2370 struct lpfc_hba *phba = vport->phba;
2373 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
2374 spin_lock_irq(&phba->hbalock);
2375 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2376 spin_unlock_irq(&phba->hbalock);
2377 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2378 "2872 Devloss tmo with no eligible "
2379 "FCF, unregister in-use FCF (x%x) "
2380 "and rescan FCF table\n",
2381 phba->fcf.current_rec.fcf_indx);
2382 lpfc_unregister_fcf_rescan(phba);
2383 goto stop_flogi_current_fcf;
2385 /* Mark the end to FLOGI roundrobin failover */
2386 phba->hba_flag &= ~FCF_RR_INPROG;
2387 /* Allow action to new fcf asynchronous event */
2388 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
2389 spin_unlock_irq(&phba->hbalock);
2390 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2391 "2865 No FCF available, stop roundrobin FCF "
2392 "failover and change port state:x%x/x%x\n",
2393 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
2394 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2396 if (!phba->fcf.fcf_redisc_attempted) {
2397 lpfc_unregister_fcf(phba);
2399 rc = lpfc_sli4_redisc_fcf_table(phba);
2401 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2402 "3195 Rediscover FCF table\n");
2403 phba->fcf.fcf_redisc_attempted = 1;
2404 lpfc_sli4_clear_fcf_rr_bmask(phba);
2406 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2407 "3196 Rediscover FCF table "
2408 "failed. Status:x%x\n", rc);
2411 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2412 "3197 Already rediscover FCF table "
2413 "attempted. No more retry\n");
2415 goto stop_flogi_current_fcf;
2417 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
2418 "2794 Try FLOGI roundrobin FCF failover to "
2419 "(x%x)\n", fcf_index);
2420 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
2422 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
2423 "2761 FLOGI roundrobin FCF failover "
2424 "failed (rc:x%x) to read FCF (x%x)\n",
2425 rc, phba->fcf.current_rec.fcf_indx);
2427 goto stop_flogi_current_fcf;
2431 stop_flogi_current_fcf:
2432 lpfc_can_disctmo(vport);
2437 * lpfc_sli4_fcf_pri_list_del
2438 * @phba: pointer to lpfc hba data structure.
2439 * @fcf_index: the index of the fcf record to delete
2440 * This routine checks the on list flag of the fcf_index to be deleted.
2441 * If it is one the list then it is removed from the list, and the flag
2442 * is cleared. This routine grab the hbalock before removing the fcf
2443 * record from the list.
2445 static void lpfc_sli4_fcf_pri_list_del(struct lpfc_hba *phba,
2448 struct lpfc_fcf_pri *new_fcf_pri;
2450 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2451 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2452 "3058 deleting idx x%x pri x%x flg x%x\n",
2453 fcf_index, new_fcf_pri->fcf_rec.priority,
2454 new_fcf_pri->fcf_rec.flag);
2455 spin_lock_irq(&phba->hbalock);
2456 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST) {
2457 if (phba->fcf.current_rec.priority ==
2458 new_fcf_pri->fcf_rec.priority)
2459 phba->fcf.eligible_fcf_cnt--;
2460 list_del_init(&new_fcf_pri->list);
2461 new_fcf_pri->fcf_rec.flag &= ~LPFC_FCF_ON_PRI_LIST;
2463 spin_unlock_irq(&phba->hbalock);
2467 * lpfc_sli4_set_fcf_flogi_fail
2468 * @phba: pointer to lpfc hba data structure.
2469 * @fcf_index: the index of the fcf record to update
2470 * This routine acquires the hbalock and then set the LPFC_FCF_FLOGI_FAILED
2471 * flag so the round robin selection for the particular priority level
2472 * will try a different fcf record that does not have this bit set.
2473 * If the fcf record is re-read for any reason this flag is cleared brfore
2474 * adding it to the priority list.
2477 lpfc_sli4_set_fcf_flogi_fail(struct lpfc_hba *phba, uint16_t fcf_index)
2479 struct lpfc_fcf_pri *new_fcf_pri;
2480 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2481 spin_lock_irq(&phba->hbalock);
2482 new_fcf_pri->fcf_rec.flag |= LPFC_FCF_FLOGI_FAILED;
2483 spin_unlock_irq(&phba->hbalock);
2487 * lpfc_sli4_fcf_pri_list_add
2488 * @phba: pointer to lpfc hba data structure.
2489 * @fcf_index: the index of the fcf record to add
2490 * @new_fcf_record: pointer to a new FCF record.
2491 * This routine checks the priority of the fcf_index to be added.
2492 * If it is a lower priority than the current head of the fcf_pri list
2493 * then it is added to the list in the right order.
2494 * If it is the same priority as the current head of the list then it
2495 * is added to the head of the list and its bit in the rr_bmask is set.
2496 * If the fcf_index to be added is of a higher priority than the current
2497 * head of the list then the rr_bmask is cleared, its bit is set in the
2498 * rr_bmask and it is added to the head of the list.
2500 * 0=success 1=failure
2502 static int lpfc_sli4_fcf_pri_list_add(struct lpfc_hba *phba,
2504 struct fcf_record *new_fcf_record)
2506 uint16_t current_fcf_pri;
2507 uint16_t last_index;
2508 struct lpfc_fcf_pri *fcf_pri;
2509 struct lpfc_fcf_pri *next_fcf_pri;
2510 struct lpfc_fcf_pri *new_fcf_pri;
2513 new_fcf_pri = &phba->fcf.fcf_pri[fcf_index];
2514 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2515 "3059 adding idx x%x pri x%x flg x%x\n",
2516 fcf_index, new_fcf_record->fip_priority,
2517 new_fcf_pri->fcf_rec.flag);
2518 spin_lock_irq(&phba->hbalock);
2519 if (new_fcf_pri->fcf_rec.flag & LPFC_FCF_ON_PRI_LIST)
2520 list_del_init(&new_fcf_pri->list);
2521 new_fcf_pri->fcf_rec.fcf_index = fcf_index;
2522 new_fcf_pri->fcf_rec.priority = new_fcf_record->fip_priority;
2523 if (list_empty(&phba->fcf.fcf_pri_list)) {
2524 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2525 ret = lpfc_sli4_fcf_rr_index_set(phba,
2526 new_fcf_pri->fcf_rec.fcf_index);
2530 last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
2531 LPFC_SLI4_FCF_TBL_INDX_MAX);
2532 if (last_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
2533 ret = 0; /* Empty rr list */
2536 current_fcf_pri = phba->fcf.fcf_pri[last_index].fcf_rec.priority;
2537 if (new_fcf_pri->fcf_rec.priority <= current_fcf_pri) {
2538 list_add(&new_fcf_pri->list, &phba->fcf.fcf_pri_list);
2539 if (new_fcf_pri->fcf_rec.priority < current_fcf_pri) {
2540 memset(phba->fcf.fcf_rr_bmask, 0,
2541 sizeof(*phba->fcf.fcf_rr_bmask));
2542 /* fcfs_at_this_priority_level = 1; */
2543 phba->fcf.eligible_fcf_cnt = 1;
2545 /* fcfs_at_this_priority_level++; */
2546 phba->fcf.eligible_fcf_cnt++;
2547 ret = lpfc_sli4_fcf_rr_index_set(phba,
2548 new_fcf_pri->fcf_rec.fcf_index);
2552 list_for_each_entry_safe(fcf_pri, next_fcf_pri,
2553 &phba->fcf.fcf_pri_list, list) {
2554 if (new_fcf_pri->fcf_rec.priority <=
2555 fcf_pri->fcf_rec.priority) {
2556 if (fcf_pri->list.prev == &phba->fcf.fcf_pri_list)
2557 list_add(&new_fcf_pri->list,
2558 &phba->fcf.fcf_pri_list);
2560 list_add(&new_fcf_pri->list,
2561 &((struct lpfc_fcf_pri *)
2562 fcf_pri->list.prev)->list);
2565 } else if (fcf_pri->list.next == &phba->fcf.fcf_pri_list
2566 || new_fcf_pri->fcf_rec.priority <
2567 next_fcf_pri->fcf_rec.priority) {
2568 list_add(&new_fcf_pri->list, &fcf_pri->list);
2572 if (new_fcf_pri->fcf_rec.priority > fcf_pri->fcf_rec.priority)
2578 /* we use = instead of |= to clear the FLOGI_FAILED flag. */
2579 new_fcf_pri->fcf_rec.flag = LPFC_FCF_ON_PRI_LIST;
2580 spin_unlock_irq(&phba->hbalock);
2585 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
2586 * @phba: pointer to lpfc hba data structure.
2587 * @mboxq: pointer to mailbox object.
2589 * This function iterates through all the fcf records available in
2590 * HBA and chooses the optimal FCF record for discovery. After finding
2591 * the FCF for discovery it registers the FCF record and kicks start
2593 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
2594 * use an FCF record which matches fabric name and mac address of the
2595 * currently used FCF record.
2596 * If the driver supports only one FCF, it will try to use the FCF record
2597 * used by BOOT_BIOS.
2600 lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2602 struct fcf_record *new_fcf_record;
2603 uint32_t boot_flag, addr_mode;
2604 uint16_t fcf_index, next_fcf_index;
2605 struct lpfc_fcf_rec *fcf_rec = NULL;
2606 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2607 bool select_new_fcf;
2610 /* If there is pending FCoE event restart FCF table scan */
2611 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
2612 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2616 /* Parse the FCF record from the non-embedded mailbox command */
2617 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2619 if (!new_fcf_record) {
2620 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2621 "2765 Mailbox command READ_FCF_RECORD "
2622 "failed to retrieve a FCF record.\n");
2623 /* Let next new FCF event trigger fast failover */
2624 spin_lock_irq(&phba->hbalock);
2625 phba->hba_flag &= ~FCF_TS_INPROG;
2626 spin_unlock_irq(&phba->hbalock);
2627 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2631 /* Check the FCF record against the connection list */
2632 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2633 &addr_mode, &vlan_id);
2635 /* Log the FCF record information if turned on */
2636 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2640 * If the fcf record does not match with connect list entries
2641 * read the next entry; otherwise, this is an eligible FCF
2642 * record for roundrobin FCF failover.
2645 lpfc_sli4_fcf_pri_list_del(phba,
2646 bf_get(lpfc_fcf_record_fcf_index,
2648 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2649 "2781 FCF (x%x) failed connection "
2650 "list check: (x%x/x%x/%x)\n",
2651 bf_get(lpfc_fcf_record_fcf_index,
2653 bf_get(lpfc_fcf_record_fcf_avail,
2655 bf_get(lpfc_fcf_record_fcf_valid,
2657 bf_get(lpfc_fcf_record_fcf_sol,
2659 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
2660 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2661 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
2662 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
2663 phba->fcf.current_rec.fcf_indx) {
2664 lpfc_printf_log(phba, KERN_ERR,
2666 "2862 FCF (x%x) matches property "
2667 "of in-use FCF (x%x)\n",
2668 bf_get(lpfc_fcf_record_fcf_index,
2670 phba->fcf.current_rec.fcf_indx);
2674 * In case the current in-use FCF record becomes
2675 * invalid/unavailable during FCF discovery that
2676 * was not triggered by fast FCF failover process,
2677 * treat it as fast FCF failover.
2679 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
2680 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2681 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2682 "2835 Invalid in-use FCF "
2683 "(x%x), enter FCF failover "
2685 phba->fcf.current_rec.fcf_indx);
2686 spin_lock_irq(&phba->hbalock);
2687 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2688 spin_unlock_irq(&phba->hbalock);
2689 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2690 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2691 LPFC_FCOE_FCF_GET_FIRST);
2697 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2698 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index,
2705 * If this is not the first FCF discovery of the HBA, use last
2706 * FCF record for the discovery. The condition that a rescan
2707 * matches the in-use FCF record: fabric name, switch name, mac
2708 * address, and vlan_id.
2710 spin_lock_irq(&phba->hbalock);
2711 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2712 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2713 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2714 new_fcf_record, vlan_id)) {
2715 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2716 phba->fcf.current_rec.fcf_indx) {
2717 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2718 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2719 /* Stop FCF redisc wait timer */
2720 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2722 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2723 /* Fast failover, mark completed */
2724 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2725 spin_unlock_irq(&phba->hbalock);
2726 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2727 "2836 New FCF matches in-use "
2728 "FCF (x%x), port_state:x%x, "
2730 phba->fcf.current_rec.fcf_indx,
2731 phba->pport->port_state,
2732 phba->pport->fc_flag);
2735 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
2736 "2863 New FCF (x%x) matches "
2737 "property of in-use FCF (x%x)\n",
2738 bf_get(lpfc_fcf_record_fcf_index,
2740 phba->fcf.current_rec.fcf_indx);
2743 * Read next FCF record from HBA searching for the matching
2744 * with in-use record only if not during the fast failover
2745 * period. In case of fast failover period, it shall try to
2746 * determine whether the FCF record just read should be the
2749 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
2750 spin_unlock_irq(&phba->hbalock);
2755 * Update on failover FCF record only if it's in FCF fast-failover
2756 * period; otherwise, update on current FCF record.
2758 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2759 fcf_rec = &phba->fcf.failover_rec;
2761 fcf_rec = &phba->fcf.current_rec;
2763 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2765 * If the driver FCF record does not have boot flag
2766 * set and new hba fcf record has boot flag set, use
2767 * the new hba fcf record.
2769 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2770 /* Choose this FCF record */
2771 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2772 "2837 Update current FCF record "
2773 "(x%x) with new FCF record (x%x)\n",
2775 bf_get(lpfc_fcf_record_fcf_index,
2777 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2778 addr_mode, vlan_id, BOOT_ENABLE);
2779 spin_unlock_irq(&phba->hbalock);
2783 * If the driver FCF record has boot flag set and the
2784 * new hba FCF record does not have boot flag, read
2785 * the next FCF record.
2787 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
2788 spin_unlock_irq(&phba->hbalock);
2792 * If the new hba FCF record has lower priority value
2793 * than the driver FCF record, use the new record.
2795 if (new_fcf_record->fip_priority < fcf_rec->priority) {
2796 /* Choose the new FCF record with lower priority */
2797 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2798 "2838 Update current FCF record "
2799 "(x%x) with new FCF record (x%x)\n",
2801 bf_get(lpfc_fcf_record_fcf_index,
2803 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2804 addr_mode, vlan_id, 0);
2805 /* Reset running random FCF selection count */
2806 phba->fcf.eligible_fcf_cnt = 1;
2807 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2808 /* Update running random FCF selection count */
2809 phba->fcf.eligible_fcf_cnt++;
2810 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2811 phba->fcf.eligible_fcf_cnt);
2812 if (select_new_fcf) {
2813 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2814 "2839 Update current FCF record "
2815 "(x%x) with new FCF record (x%x)\n",
2817 bf_get(lpfc_fcf_record_fcf_index,
2819 /* Choose the new FCF by random selection */
2820 __lpfc_update_fcf_record(phba, fcf_rec,
2822 addr_mode, vlan_id, 0);
2825 spin_unlock_irq(&phba->hbalock);
2829 * This is the first suitable FCF record, choose this record for
2830 * initial best-fit FCF.
2833 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2834 "2840 Update initial FCF candidate "
2836 bf_get(lpfc_fcf_record_fcf_index,
2838 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2839 addr_mode, vlan_id, (boot_flag ?
2841 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2842 /* Setup initial running random FCF selection count */
2843 phba->fcf.eligible_fcf_cnt = 1;
2845 spin_unlock_irq(&phba->hbalock);
2849 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2850 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2851 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2853 * Case of FCF fast failover scan
2857 * It has not found any suitable FCF record, cancel
2858 * FCF scan inprogress, and do nothing
2860 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
2861 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2862 "2782 No suitable FCF found: "
2864 phba->fcoe_eventtag_at_fcf_scan,
2865 bf_get(lpfc_fcf_record_fcf_index,
2867 spin_lock_irq(&phba->hbalock);
2868 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2869 phba->hba_flag &= ~FCF_TS_INPROG;
2870 spin_unlock_irq(&phba->hbalock);
2871 /* Unregister in-use FCF and rescan */
2872 lpfc_printf_log(phba, KERN_INFO,
2874 "2864 On devloss tmo "
2875 "unreg in-use FCF and "
2876 "rescan FCF table\n");
2877 lpfc_unregister_fcf_rescan(phba);
2881 * Let next new FCF event trigger fast failover
2883 phba->hba_flag &= ~FCF_TS_INPROG;
2884 spin_unlock_irq(&phba->hbalock);
2888 * It has found a suitable FCF record that is not
2889 * the same as in-use FCF record, unregister the
2890 * in-use FCF record, replace the in-use FCF record
2891 * with the new FCF record, mark FCF fast failover
2892 * completed, and then start register the new FCF
2896 /* Unregister the current in-use FCF record */
2897 lpfc_unregister_fcf(phba);
2899 /* Replace in-use record with the new record */
2900 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2901 "2842 Replace in-use FCF (x%x) "
2902 "with failover FCF (x%x)\n",
2903 phba->fcf.current_rec.fcf_indx,
2904 phba->fcf.failover_rec.fcf_indx);
2905 memcpy(&phba->fcf.current_rec,
2906 &phba->fcf.failover_rec,
2907 sizeof(struct lpfc_fcf_rec));
2909 * Mark the fast FCF failover rediscovery completed
2910 * and the start of the first round of the roundrobin
2913 spin_lock_irq(&phba->hbalock);
2914 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2915 spin_unlock_irq(&phba->hbalock);
2916 /* Register to the new FCF record */
2917 lpfc_register_fcf(phba);
2920 * In case of transaction period to fast FCF failover,
2921 * do nothing when search to the end of the FCF table.
2923 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2924 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2927 if (phba->cfg_fcf_failover_policy == LPFC_FCF_FOV &&
2928 phba->fcf.fcf_flag & FCF_IN_USE) {
2930 * In case the current in-use FCF record no
2931 * longer existed during FCF discovery that
2932 * was not triggered by fast FCF failover
2933 * process, treat it as fast FCF failover.
2935 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2936 "2841 In-use FCF record (x%x) "
2937 "not reported, entering fast "
2938 "FCF failover mode scanning.\n",
2939 phba->fcf.current_rec.fcf_indx);
2940 spin_lock_irq(&phba->hbalock);
2941 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2942 spin_unlock_irq(&phba->hbalock);
2943 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2944 LPFC_FCOE_FCF_GET_FIRST);
2947 /* Register to the new FCF record */
2948 lpfc_register_fcf(phba);
2951 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
2955 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2956 lpfc_register_fcf(phba);
2962 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
2963 * @phba: pointer to lpfc hba data structure.
2964 * @mboxq: pointer to mailbox object.
2966 * This is the callback function for FLOGI failure roundrobin FCF failover
2967 * read FCF record mailbox command from the eligible FCF record bmask for
2968 * performing the failover. If the FCF read back is not valid/available, it
2969 * fails through to retrying FLOGI to the currently registered FCF again.
2970 * Otherwise, if the FCF read back is valid and available, it will set the
2971 * newly read FCF record to the failover FCF record, unregister currently
2972 * registered FCF record, copy the failover FCF record to the current
2973 * FCF record, and then register the current FCF record before proceeding
2974 * to trying FLOGI on the new failover FCF.
2977 lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2979 struct fcf_record *new_fcf_record;
2980 uint32_t boot_flag, addr_mode;
2981 uint16_t next_fcf_index, fcf_index;
2982 uint16_t current_fcf_index;
2983 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
2986 /* If link state is not up, stop the roundrobin failover process */
2987 if (phba->link_state < LPFC_LINK_UP) {
2988 spin_lock_irq(&phba->hbalock);
2989 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2990 phba->hba_flag &= ~FCF_RR_INPROG;
2991 spin_unlock_irq(&phba->hbalock);
2995 /* Parse the FCF record from the non-embedded mailbox command */
2996 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2998 if (!new_fcf_record) {
2999 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
3000 "2766 Mailbox command READ_FCF_RECORD "
3001 "failed to retrieve a FCF record. "
3002 "hba_flg x%x fcf_flg x%x\n", phba->hba_flag,
3003 phba->fcf.fcf_flag);
3004 lpfc_unregister_fcf_rescan(phba);
3008 /* Get the needed parameters from FCF record */
3009 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3010 &addr_mode, &vlan_id);
3012 /* Log the FCF record information if turned on */
3013 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3016 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
3018 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3019 "2848 Remove ineligible FCF (x%x) from "
3020 "from roundrobin bmask\n", fcf_index);
3021 /* Clear roundrobin bmask bit for ineligible FCF */
3022 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
3023 /* Perform next round of roundrobin FCF failover */
3024 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
3025 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
3031 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
3032 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3033 "2760 Perform FLOGI roundrobin FCF failover: "
3034 "FCF (x%x) back to FCF (x%x)\n",
3035 phba->fcf.current_rec.fcf_indx, fcf_index);
3036 /* Wait 500 ms before retrying FLOGI to current FCF */
3038 lpfc_issue_init_vfi(phba->pport);
3042 /* Upload new FCF record to the failover FCF record */
3043 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3044 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
3045 phba->fcf.failover_rec.fcf_indx, fcf_index);
3046 spin_lock_irq(&phba->hbalock);
3047 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
3048 new_fcf_record, addr_mode, vlan_id,
3049 (boot_flag ? BOOT_ENABLE : 0));
3050 spin_unlock_irq(&phba->hbalock);
3052 current_fcf_index = phba->fcf.current_rec.fcf_indx;
3054 /* Unregister the current in-use FCF record */
3055 lpfc_unregister_fcf(phba);
3057 /* Replace in-use record with the new record */
3058 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
3059 sizeof(struct lpfc_fcf_rec));
3061 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3062 "2783 Perform FLOGI roundrobin FCF failover: FCF "
3063 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
3066 lpfc_register_fcf(phba);
3068 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3072 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
3073 * @phba: pointer to lpfc hba data structure.
3074 * @mboxq: pointer to mailbox object.
3076 * This is the callback function of read FCF record mailbox command for
3077 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
3078 * failover when a new FCF event happened. If the FCF read back is
3079 * valid/available and it passes the connection list check, it updates
3080 * the bmask for the eligible FCF record for roundrobin failover.
3083 lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3085 struct fcf_record *new_fcf_record;
3086 uint32_t boot_flag, addr_mode;
3087 uint16_t fcf_index, next_fcf_index;
3088 uint16_t vlan_id = LPFC_FCOE_NULL_VID;
3091 /* If link state is not up, no need to proceed */
3092 if (phba->link_state < LPFC_LINK_UP)
3095 /* If FCF discovery period is over, no need to proceed */
3096 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
3099 /* Parse the FCF record from the non-embedded mailbox command */
3100 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
3102 if (!new_fcf_record) {
3103 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
3104 "2767 Mailbox command READ_FCF_RECORD "
3105 "failed to retrieve a FCF record.\n");
3109 /* Check the connection list for eligibility */
3110 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
3111 &addr_mode, &vlan_id);
3113 /* Log the FCF record information if turned on */
3114 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
3120 /* Update the eligible FCF record index bmask */
3121 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
3123 rc = lpfc_sli4_fcf_pri_list_add(phba, fcf_index, new_fcf_record);
3126 lpfc_sli4_mbox_cmd_free(phba, mboxq);
3130 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
3131 * @phba: pointer to lpfc hba data structure.
3132 * @mboxq: pointer to mailbox data structure.
3134 * This function handles completion of init vfi mailbox command.
3137 lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3139 struct lpfc_vport *vport = mboxq->vport;
3142 * VFI not supported on interface type 0, just do the flogi
3143 * Also continue if the VFI is in use - just use the same one.
3145 if (mboxq->u.mb.mbxStatus &&
3146 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3147 LPFC_SLI_INTF_IF_TYPE_0) &&
3148 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3149 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3150 "2891 Init VFI mailbox failed 0x%x\n",
3151 mboxq->u.mb.mbxStatus);
3152 mempool_free(mboxq, phba->mbox_mem_pool);
3153 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3157 lpfc_initial_flogi(vport);
3158 mempool_free(mboxq, phba->mbox_mem_pool);
3163 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
3164 * @vport: pointer to lpfc_vport data structure.
3166 * This function issue a init_vfi mailbox command to initialize the VFI and
3167 * VPI for the physical port.
3170 lpfc_issue_init_vfi(struct lpfc_vport *vport)
3172 LPFC_MBOXQ_t *mboxq;
3174 struct lpfc_hba *phba = vport->phba;
3176 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3178 lpfc_printf_vlog(vport, KERN_ERR,
3179 LOG_TRACE_EVENT, "2892 Failed to allocate "
3180 "init_vfi mailbox\n");
3183 lpfc_init_vfi(mboxq, vport);
3184 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
3185 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
3186 if (rc == MBX_NOT_FINISHED) {
3187 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3188 "2893 Failed to issue init_vfi mailbox\n");
3189 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3194 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
3195 * @phba: pointer to lpfc hba data structure.
3196 * @mboxq: pointer to mailbox data structure.
3198 * This function handles completion of init vpi mailbox command.
3201 lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3203 struct lpfc_vport *vport = mboxq->vport;
3204 struct lpfc_nodelist *ndlp;
3205 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3207 if (mboxq->u.mb.mbxStatus) {
3208 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3209 "2609 Init VPI mailbox failed 0x%x\n",
3210 mboxq->u.mb.mbxStatus);
3211 mempool_free(mboxq, phba->mbox_mem_pool);
3212 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3215 spin_lock_irq(shost->host_lock);
3216 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3217 spin_unlock_irq(shost->host_lock);
3219 /* If this port is physical port or FDISC is done, do reg_vpi */
3220 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
3221 ndlp = lpfc_findnode_did(vport, Fabric_DID);
3223 lpfc_printf_vlog(vport, KERN_ERR,
3225 "2731 Cannot find fabric "
3226 "controller node\n");
3228 lpfc_register_new_vport(phba, vport, ndlp);
3229 mempool_free(mboxq, phba->mbox_mem_pool);
3233 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3234 lpfc_initial_fdisc(vport);
3236 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
3237 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3238 "2606 No NPIV Fabric support\n");
3240 mempool_free(mboxq, phba->mbox_mem_pool);
3245 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
3246 * @vport: pointer to lpfc_vport data structure.
3248 * This function issue a init_vpi mailbox command to initialize
3249 * VPI for the vport.
3252 lpfc_issue_init_vpi(struct lpfc_vport *vport)
3254 LPFC_MBOXQ_t *mboxq;
3257 if ((vport->port_type != LPFC_PHYSICAL_PORT) && (!vport->vpi)) {
3258 vpi = lpfc_alloc_vpi(vport->phba);
3260 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3261 "3303 Failed to obtain vport vpi\n");
3262 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3268 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
3270 lpfc_printf_vlog(vport, KERN_ERR,
3271 LOG_TRACE_EVENT, "2607 Failed to allocate "
3272 "init_vpi mailbox\n");
3275 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
3276 mboxq->vport = vport;
3277 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
3278 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
3279 if (rc == MBX_NOT_FINISHED) {
3280 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3281 "2608 Failed to issue init_vpi mailbox\n");
3282 mempool_free(mboxq, vport->phba->mbox_mem_pool);
3287 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
3288 * @phba: pointer to lpfc hba data structure.
3290 * This function loops through the list of vports on the @phba and issues an
3291 * FDISC if possible.
3294 lpfc_start_fdiscs(struct lpfc_hba *phba)
3296 struct lpfc_vport **vports;
3299 vports = lpfc_create_vport_work_array(phba);
3300 if (vports != NULL) {
3301 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3302 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
3304 /* There are no vpi for this vport */
3305 if (vports[i]->vpi > phba->max_vpi) {
3306 lpfc_vport_set_state(vports[i],
3310 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3311 lpfc_vport_set_state(vports[i],
3315 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
3316 lpfc_issue_init_vpi(vports[i]);
3319 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
3320 lpfc_initial_fdisc(vports[i]);
3322 lpfc_vport_set_state(vports[i],
3323 FC_VPORT_NO_FABRIC_SUPP);
3324 lpfc_printf_vlog(vports[i], KERN_ERR,
3327 "Fabric support\n");
3331 lpfc_destroy_vport_work_array(phba, vports);
3335 lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
3337 struct lpfc_vport *vport = mboxq->vport;
3338 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3341 * VFI not supported for interface type 0, so ignore any mailbox
3342 * error (except VFI in use) and continue with the discovery.
3344 if (mboxq->u.mb.mbxStatus &&
3345 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
3346 LPFC_SLI_INTF_IF_TYPE_0) &&
3347 mboxq->u.mb.mbxStatus != MBX_VFI_IN_USE) {
3348 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3349 "2018 REG_VFI mbxStatus error x%x "
3351 mboxq->u.mb.mbxStatus, vport->port_state);
3352 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3353 /* FLOGI failed, use loop map to make discovery list */
3354 lpfc_disc_list_loopmap(vport);
3355 /* Start discovery */
3356 lpfc_disc_start(vport);
3359 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3363 /* If the VFI is already registered, there is nothing else to do
3364 * Unless this was a VFI update and we are in PT2PT mode, then
3365 * we should drop through to set the port state to ready.
3367 if (vport->fc_flag & FC_VFI_REGISTERED)
3368 if (!(phba->sli_rev == LPFC_SLI_REV4 &&
3369 vport->fc_flag & FC_PT2PT))
3372 /* The VPI is implicitly registered when the VFI is registered */
3373 spin_lock_irq(shost->host_lock);
3374 vport->vpi_state |= LPFC_VPI_REGISTERED;
3375 vport->fc_flag |= FC_VFI_REGISTERED;
3376 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
3377 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
3378 spin_unlock_irq(shost->host_lock);
3380 /* In case SLI4 FC loopback test, we are ready */
3381 if ((phba->sli_rev == LPFC_SLI_REV4) &&
3382 (phba->link_flag & LS_LOOPBACK_MODE)) {
3383 phba->link_state = LPFC_HBA_READY;
3387 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
3388 "3313 cmpl reg vfi port_state:%x fc_flag:%x myDid:%x "
3389 "alpacnt:%d LinkState:%x topology:%x\n",
3390 vport->port_state, vport->fc_flag, vport->fc_myDID,
3391 vport->phba->alpa_map[0],
3392 phba->link_state, phba->fc_topology);
3394 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
3396 * For private loop or for NPort pt2pt,
3397 * just start discovery and we are done.
3399 if ((vport->fc_flag & FC_PT2PT) ||
3400 ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
3401 !(vport->fc_flag & FC_PUBLIC_LOOP))) {
3403 /* Use loop map to make discovery list */
3404 lpfc_disc_list_loopmap(vport);
3405 /* Start discovery */
3406 if (vport->fc_flag & FC_PT2PT)
3407 vport->port_state = LPFC_VPORT_READY;
3409 lpfc_disc_start(vport);
3411 lpfc_start_fdiscs(phba);
3412 lpfc_do_scr_ns_plogi(phba, vport);
3417 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
3421 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3423 MAILBOX_t *mb = &pmb->u.mb;
3424 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3425 struct lpfc_vport *vport = pmb->vport;
3426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3427 struct serv_parm *sp = &vport->fc_sparam;
3430 /* Check for error */
3431 if (mb->mbxStatus) {
3432 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
3433 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3434 "0319 READ_SPARAM mbxStatus error x%x "
3436 mb->mbxStatus, vport->port_state);
3437 lpfc_linkdown(phba);
3441 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
3442 sizeof (struct serv_parm));
3444 ed_tov = be32_to_cpu(sp->cmn.e_d_tov);
3445 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
3446 ed_tov = (ed_tov + 999999) / 1000000;
3448 phba->fc_edtov = ed_tov;
3449 phba->fc_ratov = (2 * ed_tov) / 1000;
3450 if (phba->fc_ratov < FF_DEF_RATOV) {
3451 /* RA_TOV should be atleast 10sec for initial flogi */
3452 phba->fc_ratov = FF_DEF_RATOV;
3455 lpfc_update_vport_wwn(vport);
3456 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
3457 if (vport->port_type == LPFC_PHYSICAL_PORT) {
3458 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
3459 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
3462 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3464 /* Check if sending the FLOGI is being deferred to after we get
3465 * up to date CSPs from MBX_READ_SPARAM.
3467 if (phba->hba_flag & HBA_DEFER_FLOGI) {
3468 lpfc_initial_flogi(vport);
3469 phba->hba_flag &= ~HBA_DEFER_FLOGI;
3474 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3475 lpfc_issue_clear_la(phba, vport);
3479 lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
3481 struct lpfc_vport *vport = phba->pport;
3482 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
3483 struct Scsi_Host *shost;
3486 struct fcf_record *fcf_record;
3487 uint32_t fc_flags = 0;
3488 unsigned long iflags;
3490 spin_lock_irqsave(&phba->hbalock, iflags);
3491 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
3493 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3494 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
3495 case LPFC_LINK_SPEED_1GHZ:
3496 case LPFC_LINK_SPEED_2GHZ:
3497 case LPFC_LINK_SPEED_4GHZ:
3498 case LPFC_LINK_SPEED_8GHZ:
3499 case LPFC_LINK_SPEED_10GHZ:
3500 case LPFC_LINK_SPEED_16GHZ:
3501 case LPFC_LINK_SPEED_32GHZ:
3502 case LPFC_LINK_SPEED_64GHZ:
3503 case LPFC_LINK_SPEED_128GHZ:
3504 case LPFC_LINK_SPEED_256GHZ:
3507 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
3512 if (phba->fc_topology &&
3513 phba->fc_topology != bf_get(lpfc_mbx_read_top_topology, la)) {
3514 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
3515 "3314 Toplogy changed was 0x%x is 0x%x\n",
3517 bf_get(lpfc_mbx_read_top_topology, la));
3518 phba->fc_topology_changed = 1;
3521 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
3522 phba->link_flag &= ~(LS_NPIV_FAB_SUPPORTED | LS_CT_VEN_RPA);
3524 shost = lpfc_shost_from_vport(vport);
3525 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
3526 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
3528 /* if npiv is enabled and this adapter supports npiv log
3529 * a message that npiv is not supported in this topology
3531 if (phba->cfg_enable_npiv && phba->max_vpi)
3532 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3533 "1309 Link Up Event npiv not supported in loop "
3535 /* Get Loop Map information */
3536 if (bf_get(lpfc_mbx_read_top_il, la))
3537 fc_flags |= FC_LBIT;
3539 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
3540 i = la->lilpBde64.tus.f.bdeSize;
3543 phba->alpa_map[0] = 0;
3545 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
3556 numalpa = phba->alpa_map[0];
3558 while (j < numalpa) {
3559 memset(un.pamap, 0, 16);
3560 for (k = 1; j < numalpa; k++) {
3562 phba->alpa_map[j + 1];
3567 /* Link Up Event ALPA map */
3568 lpfc_printf_log(phba,
3571 "1304 Link Up Event "
3572 "ALPA map Data: x%x "
3574 un.pa.wd1, un.pa.wd2,
3575 un.pa.wd3, un.pa.wd4);
3580 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
3581 if (phba->max_vpi && phba->cfg_enable_npiv &&
3582 (phba->sli_rev >= LPFC_SLI_REV3))
3583 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3585 vport->fc_myDID = phba->fc_pref_DID;
3586 fc_flags |= FC_LBIT;
3588 spin_unlock_irqrestore(&phba->hbalock, iflags);
3591 spin_lock_irqsave(shost->host_lock, iflags);
3592 vport->fc_flag |= fc_flags;
3593 spin_unlock_irqrestore(shost->host_lock, iflags);
3599 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3603 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
3605 mempool_free(sparam_mbox, phba->mbox_mem_pool);
3608 sparam_mbox->vport = vport;
3609 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
3610 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
3611 if (rc == MBX_NOT_FINISHED) {
3612 lpfc_mbox_rsrc_cleanup(phba, sparam_mbox, MBOX_THD_UNLOCKED);
3616 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
3617 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3620 vport->port_state = LPFC_LOCAL_CFG_LINK;
3621 lpfc_config_link(phba, cfglink_mbox);
3622 cfglink_mbox->vport = vport;
3623 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
3624 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
3625 if (rc == MBX_NOT_FINISHED) {
3626 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
3630 vport->port_state = LPFC_VPORT_UNKNOWN;
3632 * Add the driver's default FCF record at FCF index 0 now. This
3633 * is phase 1 implementation that support FCF index 0 and driver
3636 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
3637 fcf_record = kzalloc(sizeof(struct fcf_record),
3639 if (unlikely(!fcf_record)) {
3640 lpfc_printf_log(phba, KERN_ERR,
3642 "2554 Could not allocate memory for "
3648 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
3649 LPFC_FCOE_FCF_DEF_INDEX);
3650 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
3652 lpfc_printf_log(phba, KERN_ERR,
3654 "2013 Could not manually add FCF "
3655 "record 0, status %d\n", rc);
3663 * The driver is expected to do FIP/FCF. Call the port
3664 * and get the FCF Table.
3666 spin_lock_irqsave(&phba->hbalock, iflags);
3667 if (phba->hba_flag & FCF_TS_INPROG) {
3668 spin_unlock_irqrestore(&phba->hbalock, iflags);
3671 /* This is the initial FCF discovery scan */
3672 phba->fcf.fcf_flag |= FCF_INIT_DISC;
3673 spin_unlock_irqrestore(&phba->hbalock, iflags);
3674 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
3675 "2778 Start FCF table scan at linkup\n");
3676 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
3677 LPFC_FCOE_FCF_GET_FIRST);
3679 spin_lock_irqsave(&phba->hbalock, iflags);
3680 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
3681 spin_unlock_irqrestore(&phba->hbalock, iflags);
3684 /* Reset FCF roundrobin bmask for new discovery */
3685 lpfc_sli4_clear_fcf_rr_bmask(phba);
3688 /* Prepare for LINK up registrations */
3689 memset(phba->os_host_name, 0, sizeof(phba->os_host_name));
3690 scnprintf(phba->os_host_name, sizeof(phba->os_host_name), "%s",
3691 init_utsname()->nodename);
3694 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3695 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3696 "0263 Discovery Mailbox error: state: 0x%x : x%px x%px\n",
3697 vport->port_state, sparam_mbox, cfglink_mbox);
3698 lpfc_issue_clear_la(phba, vport);
3703 lpfc_enable_la(struct lpfc_hba *phba)
3706 struct lpfc_sli *psli = &phba->sli;
3707 spin_lock_irq(&phba->hbalock);
3708 psli->sli_flag |= LPFC_PROCESS_LA;
3709 if (phba->sli_rev <= LPFC_SLI_REV3) {
3710 control = readl(phba->HCregaddr);
3711 control |= HC_LAINT_ENA;
3712 writel(control, phba->HCregaddr);
3713 readl(phba->HCregaddr); /* flush */
3715 spin_unlock_irq(&phba->hbalock);
3719 lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
3721 lpfc_linkdown(phba);
3722 lpfc_enable_la(phba);
3723 lpfc_unregister_unused_fcf(phba);
3724 /* turn on Link Attention interrupts - no CLEAR_LA needed */
3729 * This routine handles processing a READ_TOPOLOGY mailbox
3730 * command upon completion. It is setup in the LPFC_MBOXQ
3731 * as the completion routine when the command is
3732 * handed off to the SLI layer. SLI4 only.
3735 lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3737 struct lpfc_vport *vport = pmb->vport;
3738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3739 struct lpfc_mbx_read_top *la;
3740 struct lpfc_sli_ring *pring;
3741 MAILBOX_t *mb = &pmb->u.mb;
3742 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
3744 unsigned long iflags;
3746 /* Unblock ELS traffic */
3747 pring = lpfc_phba_elsring(phba);
3749 pring->flag &= ~LPFC_STOP_IOCB_EVENT;
3751 /* Check for error */
3752 if (mb->mbxStatus) {
3753 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3754 "1307 READ_LA mbox error x%x state x%x\n",
3755 mb->mbxStatus, vport->port_state);
3756 lpfc_mbx_issue_link_down(phba);
3757 phba->link_state = LPFC_HBA_ERROR;
3758 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
3761 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
3762 attn_type = bf_get(lpfc_mbx_read_top_att_type, la);
3764 memcpy(&phba->alpa_map[0], mp->virt, 128);
3766 spin_lock_irqsave(shost->host_lock, iflags);
3767 if (bf_get(lpfc_mbx_read_top_pb, la))
3768 vport->fc_flag |= FC_BYPASSED_MODE;
3770 vport->fc_flag &= ~FC_BYPASSED_MODE;
3771 spin_unlock_irqrestore(shost->host_lock, iflags);
3773 if (phba->fc_eventTag <= la->eventTag) {
3774 phba->fc_stat.LinkMultiEvent++;
3775 if (attn_type == LPFC_ATT_LINK_UP)
3776 if (phba->fc_eventTag != 0)
3777 lpfc_linkdown(phba);
3780 phba->fc_eventTag = la->eventTag;
3781 phba->link_events++;
3782 if (attn_type == LPFC_ATT_LINK_UP) {
3783 phba->fc_stat.LinkUp++;
3784 if (phba->link_flag & LS_LOOPBACK_MODE) {
3785 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3786 "1306 Link Up Event in loop back mode "
3787 "x%x received Data: x%x x%x x%x x%x\n",
3788 la->eventTag, phba->fc_eventTag,
3789 bf_get(lpfc_mbx_read_top_alpa_granted,
3791 bf_get(lpfc_mbx_read_top_link_spd, la),
3794 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3795 "1303 Link Up Event x%x received "
3796 "Data: x%x x%x x%x x%x x%x\n",
3797 la->eventTag, phba->fc_eventTag,
3798 bf_get(lpfc_mbx_read_top_alpa_granted,
3800 bf_get(lpfc_mbx_read_top_link_spd, la),
3802 bf_get(lpfc_mbx_read_top_fa, la));
3804 lpfc_mbx_process_link_up(phba, la);
3806 if (phba->cmf_active_mode != LPFC_CFG_OFF)
3807 lpfc_cmf_signal_init(phba);
3809 if (phba->lmt & LMT_64Gb)
3810 lpfc_read_lds_params(phba);
3812 } else if (attn_type == LPFC_ATT_LINK_DOWN ||
3813 attn_type == LPFC_ATT_UNEXP_WWPN) {
3814 phba->fc_stat.LinkDown++;
3815 if (phba->link_flag & LS_LOOPBACK_MODE)
3816 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3817 "1308 Link Down Event in loop back mode "
3819 "Data: x%x x%x x%x\n",
3820 la->eventTag, phba->fc_eventTag,
3821 phba->pport->port_state, vport->fc_flag);
3822 else if (attn_type == LPFC_ATT_UNEXP_WWPN)
3823 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3824 "1313 Link Down Unexpected FA WWPN Event x%x "
3825 "received Data: x%x x%x x%x x%x\n",
3826 la->eventTag, phba->fc_eventTag,
3827 phba->pport->port_state, vport->fc_flag,
3828 bf_get(lpfc_mbx_read_top_fa, la));
3830 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3831 "1305 Link Down Event x%x received "
3832 "Data: x%x x%x x%x x%x\n",
3833 la->eventTag, phba->fc_eventTag,
3834 phba->pport->port_state, vport->fc_flag,
3835 bf_get(lpfc_mbx_read_top_fa, la));
3836 lpfc_mbx_issue_link_down(phba);
3839 if ((phba->sli_rev < LPFC_SLI_REV4) &&
3840 bf_get(lpfc_mbx_read_top_fa, la))
3841 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
3843 bf_get(lpfc_mbx_read_top_fa, la));
3845 lpfc_mbx_cmpl_read_topology_free_mbuf:
3846 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3850 * This routine handles processing a REG_LOGIN mailbox
3851 * command upon completion. It is setup in the LPFC_MBOXQ
3852 * as the completion routine when the command is
3853 * handed off to the SLI layer.
3856 lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3858 struct lpfc_vport *vport = pmb->vport;
3859 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
3860 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
3862 /* The driver calls the state machine with the pmb pointer
3863 * but wants to make sure a stale ctx_buf isn't acted on.
3864 * The ctx_buf is restored later and cleaned up.
3866 pmb->ctx_buf = NULL;
3867 pmb->ctx_ndlp = NULL;
3869 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NODE | LOG_DISCOVERY,
3870 "0002 rpi:%x DID:%x flg:%x %d x%px\n",
3871 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3872 kref_read(&ndlp->kref),
3874 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3875 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3877 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3878 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3879 /* We rcvd a rscn after issuing this
3880 * mbox reg login, we may have cycled
3881 * back through the state and be
3882 * back at reg login state so this
3883 * mbox needs to be ignored becase
3884 * there is another reg login in
3887 spin_lock_irq(&ndlp->lock);
3888 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3889 spin_unlock_irq(&ndlp->lock);
3892 * We cannot leave the RPI registered because
3893 * if we go thru discovery again for this ndlp
3894 * a subsequent REG_RPI will fail.
3896 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
3897 lpfc_unreg_rpi(vport, ndlp);
3900 /* Call state machine */
3901 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
3903 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
3905 /* decrement the node reference count held for this callback
3914 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3916 MAILBOX_t *mb = &pmb->u.mb;
3917 struct lpfc_vport *vport = pmb->vport;
3918 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3920 switch (mb->mbxStatus) {
3923 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3924 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3927 /* If VPI is busy, reset the HBA */
3929 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3930 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3931 vport->vpi, mb->mbxStatus);
3932 if (!(phba->pport->load_flag & FC_UNLOADING))
3933 lpfc_workq_post_event(phba, NULL, NULL,
3934 LPFC_EVT_RESET_HBA);
3936 spin_lock_irq(shost->host_lock);
3937 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
3938 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
3939 spin_unlock_irq(shost->host_lock);
3940 mempool_free(pmb, phba->mbox_mem_pool);
3941 lpfc_cleanup_vports_rrqs(vport, NULL);
3943 * This shost reference might have been taken at the beginning of
3944 * lpfc_vport_delete()
3946 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
3947 scsi_host_put(shost);
3951 lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3953 struct lpfc_hba *phba = vport->phba;
3957 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3961 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3962 mbox->vport = vport;
3963 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
3964 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3965 if (rc == MBX_NOT_FINISHED) {
3966 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3967 "1800 Could not issue unreg_vpi\n");
3968 mempool_free(mbox, phba->mbox_mem_pool);
3975 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3977 struct lpfc_vport *vport = pmb->vport;
3978 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3979 MAILBOX_t *mb = &pmb->u.mb;
3981 switch (mb->mbxStatus) {
3985 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3986 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3988 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3989 spin_lock_irq(shost->host_lock);
3990 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3991 spin_unlock_irq(shost->host_lock);
3992 vport->fc_myDID = 0;
3994 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
3995 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
3996 if (phba->nvmet_support)
3997 lpfc_nvmet_update_targetport(phba);
3999 lpfc_nvme_update_localport(vport);
4004 spin_lock_irq(shost->host_lock);
4005 vport->vpi_state |= LPFC_VPI_REGISTERED;
4006 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4007 spin_unlock_irq(shost->host_lock);
4008 vport->num_disc_nodes = 0;
4009 /* go thru NPR list and issue ELS PLOGIs */
4010 if (vport->fc_npr_cnt)
4011 lpfc_els_disc_plogi(vport);
4013 if (!vport->num_disc_nodes) {
4014 spin_lock_irq(shost->host_lock);
4015 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4016 spin_unlock_irq(shost->host_lock);
4017 lpfc_can_disctmo(vport);
4019 vport->port_state = LPFC_VPORT_READY;
4022 mempool_free(pmb, phba->mbox_mem_pool);
4027 * lpfc_create_static_vport - Read HBA config region to create static vports.
4028 * @phba: pointer to lpfc hba data structure.
4030 * This routine issue a DUMP mailbox command for config region 22 to get
4031 * the list of static vports to be created. The function create vports
4032 * based on the information returned from the HBA.
4035 lpfc_create_static_vport(struct lpfc_hba *phba)
4037 LPFC_MBOXQ_t *pmb = NULL;
4039 struct static_vport_info *vport_info;
4040 int mbx_wait_rc = 0, i;
4041 struct fc_vport_identifiers vport_id;
4042 struct fc_vport *new_fc_vport;
4043 struct Scsi_Host *shost;
4044 struct lpfc_vport *vport;
4045 uint16_t offset = 0;
4046 uint8_t *vport_buff;
4047 struct lpfc_dmabuf *mp;
4048 uint32_t byte_count = 0;
4050 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4052 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4053 "0542 lpfc_create_static_vport failed to"
4054 " allocate mailbox memory\n");
4057 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
4060 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
4062 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4063 "0543 lpfc_create_static_vport failed to"
4064 " allocate vport_info\n");
4065 mempool_free(pmb, phba->mbox_mem_pool);
4069 vport_buff = (uint8_t *) vport_info;
4071 /* While loop iteration forces a free dma buffer from
4072 * the previous loop because the mbox is reused and
4073 * the dump routine is a single-use construct.
4076 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4077 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4079 pmb->ctx_buf = NULL;
4081 if (lpfc_dump_static_vport(phba, pmb, offset))
4084 pmb->vport = phba->pport;
4085 mbx_wait_rc = lpfc_sli_issue_mbox_wait(phba, pmb,
4088 if ((mbx_wait_rc != MBX_SUCCESS) || mb->mbxStatus) {
4089 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4090 "0544 lpfc_create_static_vport failed to"
4091 " issue dump mailbox command ret 0x%x "
4093 mbx_wait_rc, mb->mbxStatus);
4097 if (phba->sli_rev == LPFC_SLI_REV4) {
4098 byte_count = pmb->u.mqe.un.mb_words[5];
4099 mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
4100 if (byte_count > sizeof(struct static_vport_info) -
4102 byte_count = sizeof(struct static_vport_info)
4104 memcpy(vport_buff + offset, mp->virt, byte_count);
4105 offset += byte_count;
4107 if (mb->un.varDmp.word_cnt >
4108 sizeof(struct static_vport_info) - offset)
4109 mb->un.varDmp.word_cnt =
4110 sizeof(struct static_vport_info)
4112 byte_count = mb->un.varDmp.word_cnt;
4113 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
4114 vport_buff + offset,
4117 offset += byte_count;
4120 } while (byte_count &&
4121 offset < sizeof(struct static_vport_info));
4124 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
4125 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
4126 != VPORT_INFO_REV)) {
4127 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4128 "0545 lpfc_create_static_vport bad"
4129 " information header 0x%x 0x%x\n",
4130 le32_to_cpu(vport_info->signature),
4131 le32_to_cpu(vport_info->rev) &
4132 VPORT_INFO_REV_MASK);
4137 shost = lpfc_shost_from_vport(phba->pport);
4139 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
4140 memset(&vport_id, 0, sizeof(vport_id));
4141 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
4142 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
4143 if (!vport_id.port_name || !vport_id.node_name)
4146 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
4147 vport_id.vport_type = FC_PORTTYPE_NPIV;
4148 vport_id.disable = false;
4149 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
4151 if (!new_fc_vport) {
4152 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4153 "0546 lpfc_create_static_vport failed to"
4158 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
4159 vport->vport_flag |= STATIC_VPORT;
4164 if (mbx_wait_rc != MBX_TIMEOUT)
4165 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4169 * This routine handles processing a Fabric REG_LOGIN mailbox
4170 * command upon completion. It is setup in the LPFC_MBOXQ
4171 * as the completion routine when the command is
4172 * handed off to the SLI layer.
4175 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4177 struct lpfc_vport *vport = pmb->vport;
4178 MAILBOX_t *mb = &pmb->u.mb;
4179 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4180 struct Scsi_Host *shost;
4182 pmb->ctx_ndlp = NULL;
4184 if (mb->mbxStatus) {
4185 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4186 "0258 Register Fabric login error: 0x%x\n",
4188 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4189 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4190 /* FLOGI failed, use loop map to make discovery list */
4191 lpfc_disc_list_loopmap(vport);
4193 /* Start discovery */
4194 lpfc_disc_start(vport);
4195 /* Decrement the reference count to ndlp after the
4196 * reference to the ndlp are done.
4202 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4203 /* Decrement the reference count to ndlp after the reference
4204 * to the ndlp are done.
4210 if (phba->sli_rev < LPFC_SLI_REV4)
4211 ndlp->nlp_rpi = mb->un.varWords[0];
4212 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4213 ndlp->nlp_type |= NLP_FABRIC;
4214 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4216 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
4217 /* when physical port receive logo donot start
4218 * vport discovery */
4219 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
4220 lpfc_start_fdiscs(phba);
4222 shost = lpfc_shost_from_vport(vport);
4223 spin_lock_irq(shost->host_lock);
4224 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
4225 spin_unlock_irq(shost->host_lock);
4227 lpfc_do_scr_ns_plogi(phba, vport);
4230 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4232 /* Drop the reference count from the mbox at the end after
4233 * all the current reference to the ndlp have been done.
4240 * This routine will issue a GID_FT for each FC4 Type supported
4241 * by the driver. ALL GID_FTs must complete before discovery is started.
4244 lpfc_issue_gidft(struct lpfc_vport *vport)
4246 /* Good status, issue CT Request to NameServer */
4247 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4248 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP)) {
4249 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_FCP)) {
4250 /* Cannot issue NameServer FCP Query, so finish up
4253 lpfc_printf_vlog(vport, KERN_ERR,
4255 "0604 %s FC TYPE %x %s\n",
4256 "Failed to issue GID_FT to ",
4258 "Finishing discovery.");
4264 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4265 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
4266 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, SLI_CTPT_NVME)) {
4267 /* Cannot issue NameServer NVME Query, so finish up
4270 lpfc_printf_vlog(vport, KERN_ERR,
4272 "0605 %s FC_TYPE %x %s %d\n",
4273 "Failed to issue GID_FT to ",
4275 "Finishing discovery: gidftinp ",
4277 if (vport->gidft_inp == 0)
4282 return vport->gidft_inp;
4286 * lpfc_issue_gidpt - issue a GID_PT for all N_Ports
4287 * @vport: The virtual port for which this call is being executed.
4289 * This routine will issue a GID_PT to get a list of all N_Ports
4292 * 0 - Failure to issue a GID_PT
4296 lpfc_issue_gidpt(struct lpfc_vport *vport)
4298 /* Good status, issue CT Request to NameServer */
4299 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_PT, 0, GID_PT_N_PORT)) {
4300 /* Cannot issue NameServer FCP Query, so finish up
4303 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4304 "0606 %s Port TYPE %x %s\n",
4305 "Failed to issue GID_PT to ",
4307 "Finishing discovery.");
4315 * This routine handles processing a NameServer REG_LOGIN mailbox
4316 * command upon completion. It is setup in the LPFC_MBOXQ
4317 * as the completion routine when the command is
4318 * handed off to the SLI layer.
4321 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4323 MAILBOX_t *mb = &pmb->u.mb;
4324 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4325 struct lpfc_vport *vport = pmb->vport;
4328 pmb->ctx_ndlp = NULL;
4329 vport->gidft_inp = 0;
4331 if (mb->mbxStatus) {
4332 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4333 "0260 Register NameServer error: 0x%x\n",
4337 /* decrement the node reference count held for this
4338 * callback function.
4341 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4343 /* If the node is not registered with the scsi or nvme
4344 * transport, remove the fabric node. The failed reg_login
4345 * is terminal and forces the removal of the last node
4348 if (!(ndlp->fc4_xpt_flags & (SCSI_XPT_REGD | NVME_XPT_REGD))) {
4349 spin_lock_irq(&ndlp->lock);
4350 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
4351 spin_unlock_irq(&ndlp->lock);
4355 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4357 * RegLogin failed, use loop map to make discovery
4360 lpfc_disc_list_loopmap(vport);
4362 /* Start discovery */
4363 lpfc_disc_start(vport);
4366 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4370 if (phba->sli_rev < LPFC_SLI_REV4)
4371 ndlp->nlp_rpi = mb->un.varWords[0];
4372 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4373 ndlp->nlp_type |= NLP_FABRIC;
4374 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4375 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
4376 "0003 rpi:%x DID:%x flg:%x %d x%px\n",
4377 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4378 kref_read(&ndlp->kref),
4381 if (vport->port_state < LPFC_VPORT_READY) {
4382 /* Link up discovery requires Fabric registration. */
4383 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
4384 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
4385 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
4386 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
4388 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4389 (vport->cfg_enable_fc4_type == LPFC_ENABLE_FCP))
4390 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, FC_TYPE_FCP);
4392 if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
4393 (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME))
4394 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0,
4397 /* Issue SCR just before NameServer GID_FT Query */
4398 lpfc_issue_els_scr(vport, 0);
4400 /* Link was bounced or a Fabric LOGO occurred. Start EDC
4401 * with initial FW values provided the congestion mode is
4402 * not off. Note that signals may or may not be supported
4403 * by the adapter but FPIN is provided by default for 1
4404 * or both missing signals support.
4406 if (phba->cmf_active_mode != LPFC_CFG_OFF) {
4407 phba->cgn_reg_fpin = phba->cgn_init_reg_fpin;
4408 phba->cgn_reg_signal = phba->cgn_init_reg_signal;
4409 rc = lpfc_issue_els_edc(vport, 0);
4410 lpfc_printf_log(phba, KERN_INFO,
4411 LOG_INIT | LOG_ELS | LOG_DISCOVERY,
4412 "4220 Issue EDC status x%x Data x%x\n",
4413 rc, phba->cgn_init_reg_signal);
4414 } else if (phba->lmt & LMT_64Gb) {
4415 /* may send link fault capability descriptor */
4416 lpfc_issue_els_edc(vport, 0);
4418 lpfc_issue_els_rdf(vport, 0);
4422 vport->fc_ns_retry = 0;
4423 if (lpfc_issue_gidft(vport) == 0)
4427 * At this point in time we may need to wait for multiple
4428 * SLI_CTNS_GID_FT CT commands to complete before we start discovery.
4430 * decrement the node reference count held for this
4431 * callback function.
4434 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4439 * This routine handles processing a Fabric Controller REG_LOGIN mailbox
4440 * command upon completion. It is setup in the LPFC_MBOXQ
4441 * as the completion routine when the command is handed off to the SLI layer.
4444 lpfc_mbx_cmpl_fc_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4446 struct lpfc_vport *vport = pmb->vport;
4447 MAILBOX_t *mb = &pmb->u.mb;
4448 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4450 pmb->ctx_ndlp = NULL;
4451 if (mb->mbxStatus) {
4452 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4453 "0933 %s: Register FC login error: 0x%x\n",
4454 __func__, mb->mbxStatus);
4458 lpfc_check_nlp_post_devloss(vport, ndlp);
4460 if (phba->sli_rev < LPFC_SLI_REV4)
4461 ndlp->nlp_rpi = mb->un.varWords[0];
4463 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4464 "0934 %s: Complete FC x%x RegLogin rpi x%x ste x%x\n",
4465 __func__, ndlp->nlp_DID, ndlp->nlp_rpi,
4468 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
4469 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4470 ndlp->nlp_type |= NLP_FABRIC;
4471 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4474 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
4476 /* Drop the reference count from the mbox at the end after
4477 * all the current reference to the ndlp have been done.
4483 lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4485 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4486 struct fc_rport *rport;
4487 struct lpfc_rport_data *rdata;
4488 struct fc_rport_identifiers rport_ids;
4489 struct lpfc_hba *phba = vport->phba;
4490 unsigned long flags;
4492 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4495 /* Remote port has reappeared. Re-register w/ FC transport */
4496 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
4497 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
4498 rport_ids.port_id = ndlp->nlp_DID;
4499 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
4502 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4503 "rport add: did:x%x flg:x%x type x%x",
4504 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4506 /* Don't add the remote port if unloading. */
4507 if (vport->load_flag & FC_UNLOADING)
4510 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
4512 dev_printk(KERN_WARNING, &phba->pcidev->dev,
4513 "Warning: fc_remote_port_add failed\n");
4517 /* Successful port add. Complete initializing node data */
4518 rport->maxframe_size = ndlp->nlp_maxframe;
4519 rport->supported_classes = ndlp->nlp_class_sup;
4520 rdata = rport->dd_data;
4521 rdata->pnode = lpfc_nlp_get(ndlp);
4522 if (!rdata->pnode) {
4523 dev_warn(&phba->pcidev->dev,
4524 "Warning - node ref failed. Unreg rport\n");
4525 fc_remote_port_delete(rport);
4530 spin_lock_irqsave(&ndlp->lock, flags);
4531 ndlp->fc4_xpt_flags |= SCSI_XPT_REGD;
4532 spin_unlock_irqrestore(&ndlp->lock, flags);
4534 if (ndlp->nlp_type & NLP_FCP_TARGET)
4535 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
4536 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
4537 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
4538 if (ndlp->nlp_type & NLP_NVME_INITIATOR)
4539 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
4540 if (ndlp->nlp_type & NLP_NVME_TARGET)
4541 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
4542 if (ndlp->nlp_type & NLP_NVME_DISCOVERY)
4543 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
4545 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
4546 fc_remote_port_rolechg(rport, rport_ids.roles);
4548 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4549 "3183 %s rport x%px DID x%x, role x%x refcnt %d\n",
4550 __func__, rport, rport->port_id, rport->roles,
4551 kref_read(&ndlp->kref));
4553 if ((rport->scsi_target_id != -1) &&
4554 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
4555 ndlp->nlp_sid = rport->scsi_target_id;
4562 lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
4564 struct fc_rport *rport = ndlp->rport;
4565 struct lpfc_vport *vport = ndlp->vport;
4567 if (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)
4570 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
4571 "rport delete: did:x%x flg:x%x type x%x",
4572 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4574 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4575 "3184 rport unregister x%06x, rport x%px "
4576 "xptflg x%x refcnt %d\n",
4577 ndlp->nlp_DID, rport, ndlp->fc4_xpt_flags,
4578 kref_read(&ndlp->kref));
4580 fc_remote_port_delete(rport);
4585 lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
4587 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4588 unsigned long iflags;
4590 spin_lock_irqsave(shost->host_lock, iflags);
4592 case NLP_STE_UNUSED_NODE:
4593 vport->fc_unused_cnt += count;
4595 case NLP_STE_PLOGI_ISSUE:
4596 vport->fc_plogi_cnt += count;
4598 case NLP_STE_ADISC_ISSUE:
4599 vport->fc_adisc_cnt += count;
4601 case NLP_STE_REG_LOGIN_ISSUE:
4602 vport->fc_reglogin_cnt += count;
4604 case NLP_STE_PRLI_ISSUE:
4605 vport->fc_prli_cnt += count;
4607 case NLP_STE_UNMAPPED_NODE:
4608 vport->fc_unmap_cnt += count;
4610 case NLP_STE_MAPPED_NODE:
4611 vport->fc_map_cnt += count;
4613 case NLP_STE_NPR_NODE:
4614 if (vport->fc_npr_cnt == 0 && count == -1)
4615 vport->fc_npr_cnt = 0;
4617 vport->fc_npr_cnt += count;
4620 spin_unlock_irqrestore(shost->host_lock, iflags);
4623 /* Register a node with backend if not already done */
4625 lpfc_nlp_reg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4627 unsigned long iflags;
4629 lpfc_check_nlp_post_devloss(vport, ndlp);
4631 spin_lock_irqsave(&ndlp->lock, iflags);
4632 if (ndlp->fc4_xpt_flags & NLP_XPT_REGD) {
4633 /* Already registered with backend, trigger rescan */
4634 spin_unlock_irqrestore(&ndlp->lock, iflags);
4636 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD &&
4637 ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY)) {
4638 lpfc_nvme_rescan_port(vport, ndlp);
4643 ndlp->fc4_xpt_flags |= NLP_XPT_REGD;
4644 spin_unlock_irqrestore(&ndlp->lock, iflags);
4646 if (lpfc_valid_xpt_node(ndlp)) {
4647 vport->phba->nport_event_cnt++;
4649 * Tell the fc transport about the port, if we haven't
4650 * already. If we have, and it's a scsi entity, be
4652 lpfc_register_remote_port(vport, ndlp);
4655 /* We are done if we do not have any NVME remote node */
4656 if (!(ndlp->nlp_fc4_type & NLP_FC4_NVME))
4659 /* Notify the NVME transport of this new rport. */
4660 if (vport->phba->sli_rev >= LPFC_SLI_REV4 &&
4661 ndlp->nlp_fc4_type & NLP_FC4_NVME) {
4662 if (vport->phba->nvmet_support == 0) {
4663 /* Register this rport with the transport.
4664 * Only NVME Target Rports are registered with
4667 if (ndlp->nlp_type & NLP_NVME_TARGET) {
4668 vport->phba->nport_event_cnt++;
4669 lpfc_nvme_register_port(vport, ndlp);
4672 /* Just take an NDLP ref count since the
4673 * target does not register rports.
4680 /* Unregister a node with backend if not already done */
4682 lpfc_nlp_unreg_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4684 unsigned long iflags;
4686 spin_lock_irqsave(&ndlp->lock, iflags);
4687 if (!(ndlp->fc4_xpt_flags & NLP_XPT_REGD)) {
4688 spin_unlock_irqrestore(&ndlp->lock, iflags);
4689 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4690 "0999 %s Not regd: ndlp x%px rport x%px DID "
4691 "x%x FLG x%x XPT x%x\n",
4692 __func__, ndlp, ndlp->rport, ndlp->nlp_DID,
4693 ndlp->nlp_flag, ndlp->fc4_xpt_flags);
4697 ndlp->fc4_xpt_flags &= ~NLP_XPT_REGD;
4698 spin_unlock_irqrestore(&ndlp->lock, iflags);
4701 ndlp->fc4_xpt_flags & SCSI_XPT_REGD) {
4702 vport->phba->nport_event_cnt++;
4703 lpfc_unregister_remote_port(ndlp);
4704 } else if (!ndlp->rport) {
4705 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4706 "1999 %s NDLP in devloss x%px DID x%x FLG x%x"
4707 " XPT x%x refcnt %d\n",
4708 __func__, ndlp, ndlp->nlp_DID, ndlp->nlp_flag,
4709 ndlp->fc4_xpt_flags,
4710 kref_read(&ndlp->kref));
4713 if (ndlp->fc4_xpt_flags & NVME_XPT_REGD) {
4714 vport->phba->nport_event_cnt++;
4715 if (vport->phba->nvmet_support == 0) {
4716 /* Start devloss if target. */
4717 if (ndlp->nlp_type & NLP_NVME_TARGET)
4718 lpfc_nvme_unregister_port(vport, ndlp);
4720 /* NVMET has no upcall. */
4728 * Adisc state change handling
4731 lpfc_handle_adisc_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4734 switch (new_state) {
4736 * Any state to ADISC_ISSUE
4737 * Do nothing, adisc cmpl handling will trigger state changes
4739 case NLP_STE_ADISC_ISSUE:
4743 * ADISC_ISSUE to mapped states
4744 * Trigger a registration with backend, it will be nop if
4745 * already registered
4747 case NLP_STE_UNMAPPED_NODE:
4748 ndlp->nlp_type |= NLP_FC_NODE;
4750 case NLP_STE_MAPPED_NODE:
4751 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4752 lpfc_nlp_reg_node(vport, ndlp);
4756 * ADISC_ISSUE to non-mapped states
4757 * We are moving from ADISC_ISSUE to a non-mapped state because
4758 * ADISC failed, we would have skipped unregistering with
4759 * backend, attempt it now
4761 case NLP_STE_NPR_NODE:
4762 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4765 lpfc_nlp_unreg_node(vport, ndlp);
4772 lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4773 int old_state, int new_state)
4775 /* Trap ADISC changes here */
4776 if (new_state == NLP_STE_ADISC_ISSUE ||
4777 old_state == NLP_STE_ADISC_ISSUE) {
4778 lpfc_handle_adisc_state(vport, ndlp, new_state);
4782 if (new_state == NLP_STE_UNMAPPED_NODE) {
4783 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4784 ndlp->nlp_type |= NLP_FC_NODE;
4786 if (new_state == NLP_STE_MAPPED_NODE)
4787 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
4788 if (new_state == NLP_STE_NPR_NODE)
4789 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
4791 /* Reg/Unreg for FCP and NVME Transport interface */
4792 if ((old_state == NLP_STE_MAPPED_NODE ||
4793 old_state == NLP_STE_UNMAPPED_NODE)) {
4794 /* For nodes marked for ADISC, Handle unreg in ADISC cmpl
4795 * if linkup. In linkdown do unreg_node
4797 if (!(ndlp->nlp_flag & NLP_NPR_ADISC) ||
4798 !lpfc_is_link_up(vport->phba))
4799 lpfc_nlp_unreg_node(vport, ndlp);
4802 if (new_state == NLP_STE_MAPPED_NODE ||
4803 new_state == NLP_STE_UNMAPPED_NODE)
4804 lpfc_nlp_reg_node(vport, ndlp);
4807 * If the node just added to Mapped list was an FCP target,
4808 * but the remote port registration failed or assigned a target
4809 * id outside the presentable range - move the node to the
4812 if ((new_state == NLP_STE_MAPPED_NODE) &&
4813 (ndlp->nlp_type & NLP_FCP_TARGET) &&
4815 ndlp->rport->scsi_target_id == -1 ||
4816 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
4817 spin_lock_irq(&ndlp->lock);
4818 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
4819 spin_unlock_irq(&ndlp->lock);
4820 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
4825 lpfc_nlp_state_name(char *buffer, size_t size, int state)
4827 static char *states[] = {
4828 [NLP_STE_UNUSED_NODE] = "UNUSED",
4829 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
4830 [NLP_STE_ADISC_ISSUE] = "ADISC",
4831 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
4832 [NLP_STE_PRLI_ISSUE] = "PRLI",
4833 [NLP_STE_LOGO_ISSUE] = "LOGO",
4834 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
4835 [NLP_STE_MAPPED_NODE] = "MAPPED",
4836 [NLP_STE_NPR_NODE] = "NPR",
4839 if (state < NLP_STE_MAX_STATE && states[state])
4840 strscpy(buffer, states[state], size);
4842 snprintf(buffer, size, "unknown (%d)", state);
4847 lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4850 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4851 int old_state = ndlp->nlp_state;
4852 int node_dropped = ndlp->nlp_flag & NLP_DROPPED;
4853 char name1[16], name2[16];
4855 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4856 "0904 NPort state transition x%06x, %s -> %s\n",
4858 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
4859 lpfc_nlp_state_name(name2, sizeof(name2), state));
4861 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4862 "node statechg did:x%x old:%d ste:%d",
4863 ndlp->nlp_DID, old_state, state);
4865 if (node_dropped && old_state == NLP_STE_UNUSED_NODE &&
4866 state != NLP_STE_UNUSED_NODE) {
4867 ndlp->nlp_flag &= ~NLP_DROPPED;
4871 if (old_state == NLP_STE_NPR_NODE &&
4872 state != NLP_STE_NPR_NODE)
4873 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4874 if (old_state == NLP_STE_UNMAPPED_NODE) {
4875 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
4876 ndlp->nlp_type &= ~NLP_FC_NODE;
4879 if (list_empty(&ndlp->nlp_listp)) {
4880 spin_lock_irq(shost->host_lock);
4881 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4882 spin_unlock_irq(shost->host_lock);
4883 } else if (old_state)
4884 lpfc_nlp_counters(vport, old_state, -1);
4886 ndlp->nlp_state = state;
4887 lpfc_nlp_counters(vport, state, 1);
4888 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
4892 lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4894 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4896 if (list_empty(&ndlp->nlp_listp)) {
4897 spin_lock_irq(shost->host_lock);
4898 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
4899 spin_unlock_irq(shost->host_lock);
4904 lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4906 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4908 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4909 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
4910 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
4911 spin_lock_irq(shost->host_lock);
4912 list_del_init(&ndlp->nlp_listp);
4913 spin_unlock_irq(shost->host_lock);
4914 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
4915 NLP_STE_UNUSED_NODE);
4919 * lpfc_initialize_node - Initialize all fields of node object
4920 * @vport: Pointer to Virtual Port object.
4921 * @ndlp: Pointer to FC node object.
4922 * @did: FC_ID of the node.
4924 * This function is always called when node object need to be initialized.
4925 * It initializes all the fields of the node object. Although the reference
4926 * to phba from @ndlp can be obtained indirectly through it's reference to
4927 * @vport, a direct reference to phba is taken here by @ndlp. This is due
4928 * to the life-span of the @ndlp might go beyond the existence of @vport as
4929 * the final release of ndlp is determined by its reference count. And, the
4930 * operation on @ndlp needs the reference to phba.
4933 lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4936 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
4937 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
4938 timer_setup(&ndlp->nlp_delayfunc, lpfc_els_retry_delay, 0);
4939 INIT_LIST_HEAD(&ndlp->recovery_evt.evt_listp);
4941 ndlp->nlp_DID = did;
4942 ndlp->vport = vport;
4943 ndlp->phba = vport->phba;
4944 ndlp->nlp_sid = NLP_NO_SID;
4945 ndlp->nlp_fc4_type = NLP_FC4_NONE;
4946 kref_init(&ndlp->kref);
4947 atomic_set(&ndlp->cmd_pending, 0);
4948 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
4949 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
4953 lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4956 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
4957 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
4958 * the ndlp from the vport. The ndlp marked as UNUSED on the list
4959 * until ALL other outstanding threads have completed. We check
4960 * that the ndlp not already in the UNUSED state before we proceed.
4962 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
4964 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
4965 ndlp->nlp_flag |= NLP_DROPPED;
4966 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
4967 lpfc_cleanup_vports_rrqs(vport, ndlp);
4968 lpfc_unreg_rpi(vport, ndlp);
4976 * Start / ReStart rescue timer for Discovery / RSCN handling
4979 lpfc_set_disctmo(struct lpfc_vport *vport)
4981 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4982 struct lpfc_hba *phba = vport->phba;
4985 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
4986 /* For FAN, timeout should be greater than edtov */
4987 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
4989 /* Normal discovery timeout should be > than ELS/CT timeout
4990 * FC spec states we need 3 * ratov for CT requests
4992 tmo = ((phba->fc_ratov * 3) + 3);
4996 if (!timer_pending(&vport->fc_disctmo)) {
4997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4998 "set disc timer: tmo:x%x state:x%x flg:x%x",
4999 tmo, vport->port_state, vport->fc_flag);
5002 mod_timer(&vport->fc_disctmo, jiffies + msecs_to_jiffies(1000 * tmo));
5003 spin_lock_irq(shost->host_lock);
5004 vport->fc_flag |= FC_DISC_TMO;
5005 spin_unlock_irq(shost->host_lock);
5007 /* Start Discovery Timer state <hba_state> */
5008 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5009 "0247 Start Discovery Timer state x%x "
5010 "Data: x%x x%lx x%x x%x\n",
5011 vport->port_state, tmo,
5012 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
5013 vport->fc_adisc_cnt);
5019 * Cancel rescue timer for Discovery / RSCN handling
5022 lpfc_can_disctmo(struct lpfc_vport *vport)
5024 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5025 unsigned long iflags;
5027 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5028 "can disc timer: state:x%x rtry:x%x flg:x%x",
5029 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
5031 /* Turn off discovery timer if its running */
5032 if (vport->fc_flag & FC_DISC_TMO ||
5033 timer_pending(&vport->fc_disctmo)) {
5034 spin_lock_irqsave(shost->host_lock, iflags);
5035 vport->fc_flag &= ~FC_DISC_TMO;
5036 spin_unlock_irqrestore(shost->host_lock, iflags);
5037 del_timer_sync(&vport->fc_disctmo);
5038 spin_lock_irqsave(&vport->work_port_lock, iflags);
5039 vport->work_port_events &= ~WORKER_DISC_TMO;
5040 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
5043 /* Cancel Discovery Timer state <hba_state> */
5044 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5045 "0248 Cancel Discovery Timer state x%x "
5046 "Data: x%x x%x x%x\n",
5047 vport->port_state, vport->fc_flag,
5048 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
5053 * Check specified ring for outstanding IOCB on the SLI queue
5054 * Return true if iocb matches the specified nport
5057 lpfc_check_sli_ndlp(struct lpfc_hba *phba,
5058 struct lpfc_sli_ring *pring,
5059 struct lpfc_iocbq *iocb,
5060 struct lpfc_nodelist *ndlp)
5062 struct lpfc_vport *vport = ndlp->vport;
5067 if (iocb->vport != vport)
5070 ulp_command = get_job_cmnd(phba, iocb);
5071 ulp_context = get_job_ulpcontext(phba, iocb);
5072 remote_id = get_job_els_rsp64_did(phba, iocb);
5074 if (pring->ringno == LPFC_ELS_RING) {
5075 switch (ulp_command) {
5076 case CMD_GEN_REQUEST64_CR:
5077 if (iocb->ndlp == ndlp)
5080 case CMD_ELS_REQUEST64_CR:
5081 if (remote_id == ndlp->nlp_DID)
5084 case CMD_XMIT_ELS_RSP64_CX:
5085 if (iocb->ndlp == ndlp)
5088 } else if (pring->ringno == LPFC_FCP_RING) {
5089 /* Skip match check if waiting to relogin to FCP target */
5090 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5091 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
5094 if (ulp_context == ndlp->nlp_rpi)
5101 __lpfc_dequeue_nport_iocbs(struct lpfc_hba *phba,
5102 struct lpfc_nodelist *ndlp, struct lpfc_sli_ring *pring,
5103 struct list_head *dequeue_list)
5105 struct lpfc_iocbq *iocb, *next_iocb;
5107 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
5108 /* Check to see if iocb matches the nport */
5109 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
5110 /* match, dequeue */
5111 list_move_tail(&iocb->list, dequeue_list);
5116 lpfc_sli3_dequeue_nport_iocbs(struct lpfc_hba *phba,
5117 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5119 struct lpfc_sli *psli = &phba->sli;
5122 spin_lock_irq(&phba->hbalock);
5123 for (i = 0; i < psli->num_rings; i++)
5124 __lpfc_dequeue_nport_iocbs(phba, ndlp, &psli->sli3_ring[i],
5126 spin_unlock_irq(&phba->hbalock);
5130 lpfc_sli4_dequeue_nport_iocbs(struct lpfc_hba *phba,
5131 struct lpfc_nodelist *ndlp, struct list_head *dequeue_list)
5133 struct lpfc_sli_ring *pring;
5134 struct lpfc_queue *qp = NULL;
5136 spin_lock_irq(&phba->hbalock);
5137 list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
5141 spin_lock(&pring->ring_lock);
5142 __lpfc_dequeue_nport_iocbs(phba, ndlp, pring, dequeue_list);
5143 spin_unlock(&pring->ring_lock);
5145 spin_unlock_irq(&phba->hbalock);
5149 * Free resources / clean up outstanding I/Os
5150 * associated with nlp_rpi in the LPFC_NODELIST entry.
5153 lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
5155 LIST_HEAD(completions);
5157 lpfc_fabric_abort_nport(ndlp);
5160 * Everything that matches on txcmplq will be returned
5161 * by firmware with a no rpi error.
5163 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5164 if (phba->sli_rev != LPFC_SLI_REV4)
5165 lpfc_sli3_dequeue_nport_iocbs(phba, ndlp, &completions);
5167 lpfc_sli4_dequeue_nport_iocbs(phba, ndlp, &completions);
5170 /* Cancel all the IOCBs from the completions list */
5171 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5178 * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO
5179 * @phba: Pointer to HBA context object.
5180 * @pmb: Pointer to mailbox object.
5182 * This function will issue an ELS LOGO command after completing
5186 lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5188 struct lpfc_vport *vport = pmb->vport;
5189 struct lpfc_nodelist *ndlp;
5191 ndlp = (struct lpfc_nodelist *)(pmb->ctx_ndlp);
5194 lpfc_issue_els_logo(vport, ndlp, 0);
5196 /* Check to see if there are any deferred events to process */
5197 if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
5198 (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
5199 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5200 "1434 UNREG cmpl deferred logo x%x "
5201 "on NPort x%x Data: x%x x%px\n",
5202 ndlp->nlp_rpi, ndlp->nlp_DID,
5203 ndlp->nlp_defer_did, ndlp);
5205 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5206 ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
5207 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5209 /* NLP_RELEASE_RPI is only set for SLI4 ports. */
5210 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
5211 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
5212 spin_lock_irq(&ndlp->lock);
5213 ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
5214 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
5215 spin_unlock_irq(&ndlp->lock);
5217 spin_lock_irq(&ndlp->lock);
5218 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5219 spin_unlock_irq(&ndlp->lock);
5222 /* The node has an outstanding reference for the unreg. Now
5223 * that the LOGO action and cleanup are finished, release
5227 mempool_free(pmb, phba->mbox_mem_pool);
5231 * Sets the mailbox completion handler to be used for the
5232 * unreg_rpi command. The handler varies based on the state of
5233 * the port and what will be happening to the rpi next.
5236 lpfc_set_unreg_login_mbx_cmpl(struct lpfc_hba *phba, struct lpfc_vport *vport,
5237 struct lpfc_nodelist *ndlp, LPFC_MBOXQ_t *mbox)
5239 unsigned long iflags;
5241 /* Driver always gets a reference on the mailbox job
5242 * in support of async jobs.
5244 mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
5245 if (!mbox->ctx_ndlp)
5248 if (ndlp->nlp_flag & NLP_ISSUE_LOGO) {
5249 mbox->mbox_cmpl = lpfc_nlp_logo_unreg;
5251 } else if (phba->sli_rev == LPFC_SLI_REV4 &&
5252 (!(vport->load_flag & FC_UNLOADING)) &&
5253 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) >=
5254 LPFC_SLI_INTF_IF_TYPE_2) &&
5255 (kref_read(&ndlp->kref) > 0)) {
5256 mbox->mbox_cmpl = lpfc_sli4_unreg_rpi_cmpl_clr;
5258 if (vport->load_flag & FC_UNLOADING) {
5259 if (phba->sli_rev == LPFC_SLI_REV4) {
5260 spin_lock_irqsave(&ndlp->lock, iflags);
5261 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5262 spin_unlock_irqrestore(&ndlp->lock, iflags);
5265 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5270 * Free rpi associated with LPFC_NODELIST entry.
5271 * This routine is called from lpfc_freenode(), when we are removing
5272 * a LPFC_NODELIST entry. It is also called if the driver initiates a
5273 * LOGO that completes successfully, and we are waiting to PLOGI back
5274 * to the remote NPort. In addition, it is called after we receive
5275 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
5276 * we are waiting to PLOGI back to the remote NPort.
5279 lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5281 struct lpfc_hba *phba = vport->phba;
5283 int rc, acc_plogi = 1;
5286 if (ndlp->nlp_flag & NLP_RPI_REGISTERED ||
5287 ndlp->nlp_flag & NLP_REG_LOGIN_SEND) {
5288 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
5289 lpfc_printf_vlog(vport, KERN_INFO,
5290 LOG_NODE | LOG_DISCOVERY,
5291 "3366 RPI x%x needs to be "
5292 "unregistered nlp_flag x%x "
5294 ndlp->nlp_rpi, ndlp->nlp_flag,
5297 /* If there is already an UNREG in progress for this ndlp,
5298 * no need to queue up another one.
5300 if (ndlp->nlp_flag & NLP_UNREG_INP) {
5301 lpfc_printf_vlog(vport, KERN_INFO,
5302 LOG_NODE | LOG_DISCOVERY,
5303 "1436 unreg_rpi SKIP UNREG x%x on "
5304 "NPort x%x deferred x%x flg x%x "
5306 ndlp->nlp_rpi, ndlp->nlp_DID,
5307 ndlp->nlp_defer_did,
5308 ndlp->nlp_flag, ndlp);
5312 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5314 /* SLI4 ports require the physical rpi value. */
5315 rpi = ndlp->nlp_rpi;
5316 if (phba->sli_rev == LPFC_SLI_REV4)
5317 rpi = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
5319 lpfc_unreg_login(phba, vport->vpi, rpi, mbox);
5320 mbox->vport = vport;
5321 lpfc_set_unreg_login_mbx_cmpl(phba, vport, ndlp, mbox);
5322 if (!mbox->ctx_ndlp) {
5323 mempool_free(mbox, phba->mbox_mem_pool);
5327 if (mbox->mbox_cmpl == lpfc_sli4_unreg_rpi_cmpl_clr)
5329 * accept PLOGIs after unreg_rpi_cmpl
5332 if (((ndlp->nlp_DID & Fabric_DID_MASK) !=
5334 (!(vport->fc_flag & FC_OFFLINE_MODE)))
5335 ndlp->nlp_flag |= NLP_UNREG_INP;
5337 lpfc_printf_vlog(vport, KERN_INFO,
5338 LOG_NODE | LOG_DISCOVERY,
5339 "1433 unreg_rpi UNREG x%x on "
5340 "NPort x%x deferred flg x%x "
5342 ndlp->nlp_rpi, ndlp->nlp_DID,
5343 ndlp->nlp_flag, ndlp);
5345 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5346 if (rc == MBX_NOT_FINISHED) {
5347 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5348 mempool_free(mbox, phba->mbox_mem_pool);
5353 lpfc_printf_vlog(vport, KERN_INFO,
5354 LOG_NODE | LOG_DISCOVERY,
5355 "1444 Failed to allocate mempool "
5356 "unreg_rpi UNREG x%x, "
5357 "DID x%x, flag x%x, "
5359 ndlp->nlp_rpi, ndlp->nlp_DID,
5360 ndlp->nlp_flag, ndlp);
5362 /* Because mempool_alloc failed, we
5363 * will issue a LOGO here and keep the rpi alive if
5366 if (!(vport->load_flag & FC_UNLOADING)) {
5367 ndlp->nlp_flag &= ~NLP_UNREG_INP;
5368 lpfc_issue_els_logo(vport, ndlp, 0);
5369 ndlp->nlp_prev_state = ndlp->nlp_state;
5370 lpfc_nlp_set_state(vport, ndlp,
5376 lpfc_no_rpi(phba, ndlp);
5378 if (phba->sli_rev != LPFC_SLI_REV4)
5380 ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
5381 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5383 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5386 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
5391 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
5392 * @phba: pointer to lpfc hba data structure.
5394 * This routine is invoked to unregister all the currently registered RPIs
5398 lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
5400 struct lpfc_vport **vports;
5401 struct lpfc_nodelist *ndlp;
5402 struct Scsi_Host *shost;
5405 vports = lpfc_create_vport_work_array(phba);
5407 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
5408 "2884 Vport array allocation failed \n");
5411 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5412 shost = lpfc_shost_from_vport(vports[i]);
5413 spin_lock_irq(shost->host_lock);
5414 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5415 if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
5416 /* The mempool_alloc might sleep */
5417 spin_unlock_irq(shost->host_lock);
5418 lpfc_unreg_rpi(vports[i], ndlp);
5419 spin_lock_irq(shost->host_lock);
5422 spin_unlock_irq(shost->host_lock);
5424 lpfc_destroy_vport_work_array(phba, vports);
5428 lpfc_unreg_all_rpis(struct lpfc_vport *vport)
5430 struct lpfc_hba *phba = vport->phba;
5434 if (phba->sli_rev == LPFC_SLI_REV4) {
5435 lpfc_sli4_unreg_all_rpis(vport);
5439 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5441 lpfc_unreg_login(phba, vport->vpi, LPFC_UNREG_ALL_RPIS_VPORT,
5443 mbox->vport = vport;
5444 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5445 mbox->ctx_ndlp = NULL;
5446 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5447 if (rc != MBX_TIMEOUT)
5448 mempool_free(mbox, phba->mbox_mem_pool);
5450 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5451 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5452 "1836 Could not issue "
5453 "unreg_login(all_rpis) status %d\n",
5459 lpfc_unreg_default_rpis(struct lpfc_vport *vport)
5461 struct lpfc_hba *phba = vport->phba;
5465 /* Unreg DID is an SLI3 operation. */
5466 if (phba->sli_rev > LPFC_SLI_REV3)
5469 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5471 lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
5473 mbox->vport = vport;
5474 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5475 mbox->ctx_ndlp = NULL;
5476 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
5477 if (rc != MBX_TIMEOUT)
5478 mempool_free(mbox, phba->mbox_mem_pool);
5480 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
5481 lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
5482 "1815 Could not issue "
5483 "unreg_did (default rpis) status %d\n",
5489 * Free resources associated with LPFC_NODELIST entry
5490 * so it can be freed.
5493 lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5495 struct lpfc_hba *phba = vport->phba;
5496 LPFC_MBOXQ_t *mb, *nextmb;
5498 /* Cleanup node for NPort <nlp_DID> */
5499 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5500 "0900 Cleanup node for NPort x%x "
5501 "Data: x%x x%x x%x\n",
5502 ndlp->nlp_DID, ndlp->nlp_flag,
5503 ndlp->nlp_state, ndlp->nlp_rpi);
5504 lpfc_dequeue_node(vport, ndlp);
5506 /* Don't need to clean up REG_LOGIN64 cmds for Default RPI cleanup */
5508 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
5509 if ((mb = phba->sli.mbox_active)) {
5510 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5511 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5512 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5513 mb->ctx_ndlp = NULL;
5514 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5518 spin_lock_irq(&phba->hbalock);
5519 /* Cleanup REG_LOGIN completions which are not yet processed */
5520 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
5521 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
5522 (mb->mbox_flag & LPFC_MBX_IMED_UNREG) ||
5523 (ndlp != (struct lpfc_nodelist *)mb->ctx_ndlp))
5526 mb->ctx_ndlp = NULL;
5527 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5530 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
5531 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
5532 !(mb->mbox_flag & LPFC_MBX_IMED_UNREG) &&
5533 (ndlp == (struct lpfc_nodelist *)mb->ctx_ndlp)) {
5534 list_del(&mb->list);
5535 lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_LOCKED);
5537 /* Don't invoke lpfc_nlp_put. The driver is in
5538 * lpfc_nlp_release context.
5542 spin_unlock_irq(&phba->hbalock);
5544 lpfc_els_abort(phba, ndlp);
5546 spin_lock_irq(&ndlp->lock);
5547 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
5548 spin_unlock_irq(&ndlp->lock);
5550 ndlp->nlp_last_elscmd = 0;
5551 del_timer_sync(&ndlp->nlp_delayfunc);
5553 list_del_init(&ndlp->els_retry_evt.evt_listp);
5554 list_del_init(&ndlp->dev_loss_evt.evt_listp);
5555 list_del_init(&ndlp->recovery_evt.evt_listp);
5556 lpfc_cleanup_vports_rrqs(vport, ndlp);
5558 if (phba->sli_rev == LPFC_SLI_REV4)
5559 ndlp->nlp_flag |= NLP_RELEASE_RPI;
5565 lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5568 D_ID mydid, ndlpdid, matchdid;
5570 if (did == Bcast_DID)
5573 /* First check for Direct match */
5574 if (ndlp->nlp_DID == did)
5577 /* Next check for area/domain identically equals 0 match */
5578 mydid.un.word = vport->fc_myDID;
5579 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
5583 matchdid.un.word = did;
5584 ndlpdid.un.word = ndlp->nlp_DID;
5585 if (matchdid.un.b.id == ndlpdid.un.b.id) {
5586 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
5587 (mydid.un.b.area == matchdid.un.b.area)) {
5588 /* This code is supposed to match the ID
5589 * for a private loop device that is
5590 * connect to fl_port. But we need to
5591 * check that the port did not just go
5592 * from pt2pt to fabric or we could end
5593 * up matching ndlp->nlp_DID 000001 to
5594 * fabric DID 0x20101
5596 if ((ndlpdid.un.b.domain == 0) &&
5597 (ndlpdid.un.b.area == 0)) {
5598 if (ndlpdid.un.b.id &&
5599 vport->phba->fc_topology ==
5606 matchdid.un.word = ndlp->nlp_DID;
5607 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
5608 (mydid.un.b.area == ndlpdid.un.b.area)) {
5609 if ((matchdid.un.b.domain == 0) &&
5610 (matchdid.un.b.area == 0)) {
5611 if (matchdid.un.b.id)
5619 /* Search for a nodelist entry */
5620 static struct lpfc_nodelist *
5621 __lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5623 struct lpfc_nodelist *ndlp;
5626 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5627 if (lpfc_matchdid(vport, ndlp, did)) {
5628 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5629 ((uint32_t)ndlp->nlp_xri << 16) |
5630 ((uint32_t)ndlp->nlp_type << 8)
5632 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5633 "0929 FIND node DID "
5634 "Data: x%px x%x x%x x%x x%x x%px\n",
5635 ndlp, ndlp->nlp_DID,
5636 ndlp->nlp_flag, data1, ndlp->nlp_rpi,
5637 ndlp->active_rrqs_xri_bitmap);
5642 /* FIND node did <did> NOT FOUND */
5643 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5644 "0932 FIND node did x%x NOT FOUND.\n", did);
5648 struct lpfc_nodelist *
5649 lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
5651 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5652 struct lpfc_nodelist *ndlp;
5653 unsigned long iflags;
5655 spin_lock_irqsave(shost->host_lock, iflags);
5656 ndlp = __lpfc_findnode_did(vport, did);
5657 spin_unlock_irqrestore(shost->host_lock, iflags);
5661 struct lpfc_nodelist *
5662 lpfc_findnode_mapped(struct lpfc_vport *vport)
5664 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5665 struct lpfc_nodelist *ndlp;
5667 unsigned long iflags;
5669 spin_lock_irqsave(shost->host_lock, iflags);
5671 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
5672 if (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE ||
5673 ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
5674 data1 = (((uint32_t)ndlp->nlp_state << 24) |
5675 ((uint32_t)ndlp->nlp_xri << 16) |
5676 ((uint32_t)ndlp->nlp_type << 8) |
5677 ((uint32_t)ndlp->nlp_rpi & 0xff));
5678 spin_unlock_irqrestore(shost->host_lock, iflags);
5679 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5680 "2025 FIND node DID "
5681 "Data: x%px x%x x%x x%x x%px\n",
5682 ndlp, ndlp->nlp_DID,
5683 ndlp->nlp_flag, data1,
5684 ndlp->active_rrqs_xri_bitmap);
5688 spin_unlock_irqrestore(shost->host_lock, iflags);
5690 /* FIND node did <did> NOT FOUND */
5691 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
5692 "2026 FIND mapped did NOT FOUND.\n");
5696 struct lpfc_nodelist *
5697 lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
5699 struct lpfc_nodelist *ndlp;
5701 ndlp = lpfc_findnode_did(vport, did);
5703 if (vport->phba->nvmet_support)
5705 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
5706 lpfc_rscn_payload_check(vport, did) == 0)
5708 ndlp = lpfc_nlp_init(vport, did);
5711 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5713 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5714 "6453 Setup New Node 2B_DISC x%x "
5715 "Data:x%x x%x x%x\n",
5716 ndlp->nlp_DID, ndlp->nlp_flag,
5717 ndlp->nlp_state, vport->fc_flag);
5719 spin_lock_irq(&ndlp->lock);
5720 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5721 spin_unlock_irq(&ndlp->lock);
5725 /* The NVME Target does not want to actively manage an rport.
5726 * The goal is to allow the target to reset its state and clear
5727 * pending IO in preparation for the initiator to recover.
5729 if ((vport->fc_flag & FC_RSCN_MODE) &&
5730 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
5731 if (lpfc_rscn_payload_check(vport, did)) {
5733 /* Since this node is marked for discovery,
5734 * delay timeout is not needed.
5736 lpfc_cancel_retry_delay_tmo(vport, ndlp);
5738 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5739 "6455 Setup RSCN Node 2B_DISC x%x "
5740 "Data:x%x x%x x%x\n",
5741 ndlp->nlp_DID, ndlp->nlp_flag,
5742 ndlp->nlp_state, vport->fc_flag);
5744 /* NVME Target mode waits until rport is known to be
5745 * impacted by the RSCN before it transitions. No
5746 * active management - just go to NPR provided the
5747 * node had a valid login.
5749 if (vport->phba->nvmet_support)
5752 /* If we've already received a PLOGI from this NPort
5753 * we don't need to try to discover it again.
5755 if (ndlp->nlp_flag & NLP_RCV_PLOGI &&
5757 (NLP_FCP_TARGET | NLP_NVME_TARGET)))
5760 lpfc_disc_state_machine(vport, ndlp, NULL,
5761 NLP_EVT_DEVICE_RECOVERY);
5763 spin_lock_irq(&ndlp->lock);
5764 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5765 spin_unlock_irq(&ndlp->lock);
5767 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5768 "6456 Skip Setup RSCN Node x%x "
5769 "Data:x%x x%x x%x\n",
5770 ndlp->nlp_DID, ndlp->nlp_flag,
5771 ndlp->nlp_state, vport->fc_flag);
5775 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5776 "6457 Setup Active Node 2B_DISC x%x "
5777 "Data:x%x x%x x%x\n",
5778 ndlp->nlp_DID, ndlp->nlp_flag,
5779 ndlp->nlp_state, vport->fc_flag);
5781 /* If the initiator received a PLOGI from this NPort or if the
5782 * initiator is already in the process of discovery on it,
5783 * there's no need to try to discover it again.
5785 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
5786 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
5787 (!vport->phba->nvmet_support &&
5788 ndlp->nlp_flag & NLP_RCV_PLOGI))
5791 if (vport->phba->nvmet_support)
5794 /* Moving to NPR state clears unsolicited flags and
5795 * allows for rediscovery
5797 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5799 spin_lock_irq(&ndlp->lock);
5800 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
5801 spin_unlock_irq(&ndlp->lock);
5806 /* Build a list of nodes to discover based on the loopmap */
5808 lpfc_disc_list_loopmap(struct lpfc_vport *vport)
5810 struct lpfc_hba *phba = vport->phba;
5812 uint32_t alpa, index;
5814 if (!lpfc_is_link_up(phba))
5817 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5820 /* Check for loop map present or not */
5821 if (phba->alpa_map[0]) {
5822 for (j = 1; j <= phba->alpa_map[0]; j++) {
5823 alpa = phba->alpa_map[j];
5824 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
5826 lpfc_setup_disc_node(vport, alpa);
5829 /* No alpamap, so try all alpa's */
5830 for (j = 0; j < FC_MAXLOOP; j++) {
5831 /* If cfg_scan_down is set, start from highest
5832 * ALPA (0xef) to lowest (0x1).
5834 if (vport->cfg_scan_down)
5837 index = FC_MAXLOOP - j - 1;
5838 alpa = lpfcAlpaArray[index];
5839 if ((vport->fc_myDID & 0xff) == alpa)
5841 lpfc_setup_disc_node(vport, alpa);
5849 lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
5852 struct lpfc_sli *psli = &phba->sli;
5853 struct lpfc_sli_ring *extra_ring = &psli->sli3_ring[LPFC_EXTRA_RING];
5854 struct lpfc_sli_ring *fcp_ring = &psli->sli3_ring[LPFC_FCP_RING];
5858 * if it's not a physical port or if we already send
5859 * clear_la then don't send it.
5861 if ((phba->link_state >= LPFC_CLEAR_LA) ||
5862 (vport->port_type != LPFC_PHYSICAL_PORT) ||
5863 (phba->sli_rev == LPFC_SLI_REV4))
5866 /* Link up discovery */
5867 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
5868 phba->link_state = LPFC_CLEAR_LA;
5869 lpfc_clear_la(phba, mbox);
5870 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
5871 mbox->vport = vport;
5872 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5873 if (rc == MBX_NOT_FINISHED) {
5874 mempool_free(mbox, phba->mbox_mem_pool);
5875 lpfc_disc_flush_list(vport);
5876 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5877 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
5878 phba->link_state = LPFC_HBA_ERROR;
5883 /* Reg_vpi to tell firmware to resume normal operations */
5885 lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5887 LPFC_MBOXQ_t *regvpimbox;
5889 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5891 lpfc_reg_vpi(vport, regvpimbox);
5892 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
5893 regvpimbox->vport = vport;
5894 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
5895 == MBX_NOT_FINISHED) {
5896 mempool_free(regvpimbox, phba->mbox_mem_pool);
5901 /* Start Link up / RSCN discovery on NPR nodes */
5903 lpfc_disc_start(struct lpfc_vport *vport)
5905 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5906 struct lpfc_hba *phba = vport->phba;
5908 uint32_t clear_la_pending;
5910 if (!lpfc_is_link_up(phba)) {
5911 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
5912 "3315 Link is not up %x\n",
5917 if (phba->link_state == LPFC_CLEAR_LA)
5918 clear_la_pending = 1;
5920 clear_la_pending = 0;
5922 if (vport->port_state < LPFC_VPORT_READY)
5923 vport->port_state = LPFC_DISC_AUTH;
5925 lpfc_set_disctmo(vport);
5927 vport->fc_prevDID = vport->fc_myDID;
5928 vport->num_disc_nodes = 0;
5930 /* Start Discovery state <hba_state> */
5931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5932 "0202 Start Discovery port state x%x "
5933 "flg x%x Data: x%x x%x x%x\n",
5934 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
5935 vport->fc_adisc_cnt, vport->fc_npr_cnt);
5937 /* First do ADISCs - if any */
5938 num_sent = lpfc_els_disc_adisc(vport);
5943 /* Register the VPI for SLI3, NPIV only. */
5944 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5945 !(vport->fc_flag & FC_PT2PT) &&
5946 !(vport->fc_flag & FC_RSCN_MODE) &&
5947 (phba->sli_rev < LPFC_SLI_REV4)) {
5948 lpfc_issue_clear_la(phba, vport);
5949 lpfc_issue_reg_vpi(phba, vport);
5954 * For SLI2, we need to set port_state to READY and continue
5957 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
5958 /* If we get here, there is nothing to ADISC */
5959 lpfc_issue_clear_la(phba, vport);
5961 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
5962 vport->num_disc_nodes = 0;
5963 /* go thru NPR nodes and issue ELS PLOGIs */
5964 if (vport->fc_npr_cnt)
5965 lpfc_els_disc_plogi(vport);
5967 if (!vport->num_disc_nodes) {
5968 spin_lock_irq(shost->host_lock);
5969 vport->fc_flag &= ~FC_NDISC_ACTIVE;
5970 spin_unlock_irq(shost->host_lock);
5971 lpfc_can_disctmo(vport);
5974 vport->port_state = LPFC_VPORT_READY;
5976 /* Next do PLOGIs - if any */
5977 num_sent = lpfc_els_disc_plogi(vport);
5982 if (vport->fc_flag & FC_RSCN_MODE) {
5983 /* Check to see if more RSCNs came in while we
5984 * were processing this one.
5986 if ((vport->fc_rscn_id_cnt == 0) &&
5987 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
5988 spin_lock_irq(shost->host_lock);
5989 vport->fc_flag &= ~FC_RSCN_MODE;
5990 spin_unlock_irq(shost->host_lock);
5991 lpfc_can_disctmo(vport);
5993 lpfc_els_handle_rscn(vport);
6000 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
6001 * ring the match the sppecified nodelist.
6004 lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
6006 LIST_HEAD(completions);
6007 struct lpfc_iocbq *iocb, *next_iocb;
6008 struct lpfc_sli_ring *pring;
6011 pring = lpfc_phba_elsring(phba);
6012 if (unlikely(!pring))
6015 /* Error matching iocb on txq or txcmplq
6016 * First check the txq.
6018 spin_lock_irq(&phba->hbalock);
6019 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
6020 if (iocb->ndlp != ndlp)
6023 ulp_command = get_job_cmnd(phba, iocb);
6025 if (ulp_command == CMD_ELS_REQUEST64_CR ||
6026 ulp_command == CMD_XMIT_ELS_RSP64_CX) {
6028 list_move_tail(&iocb->list, &completions);
6032 /* Next check the txcmplq */
6033 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
6034 if (iocb->ndlp != ndlp)
6037 ulp_command = get_job_cmnd(phba, iocb);
6039 if (ulp_command == CMD_ELS_REQUEST64_CR ||
6040 ulp_command == CMD_XMIT_ELS_RSP64_CX) {
6041 lpfc_sli_issue_abort_iotag(phba, pring, iocb, NULL);
6044 spin_unlock_irq(&phba->hbalock);
6046 /* Make sure HBA is alive */
6047 lpfc_issue_hb_tmo(phba);
6049 /* Cancel all the IOCBs from the completions list */
6050 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6055 lpfc_disc_flush_list(struct lpfc_vport *vport)
6057 struct lpfc_nodelist *ndlp, *next_ndlp;
6058 struct lpfc_hba *phba = vport->phba;
6060 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
6061 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6063 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
6064 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
6065 lpfc_free_tx(phba, ndlp);
6072 * lpfc_notify_xport_npr - notifies xport of node disappearance
6073 * @vport: Pointer to Virtual Port object.
6075 * Transitions all ndlps to NPR state. When lpfc_nlp_set_state
6076 * calls lpfc_nlp_state_cleanup, the ndlp->rport is unregistered
6077 * and transport notified that the node is gone.
6082 lpfc_notify_xport_npr(struct lpfc_vport *vport)
6084 struct lpfc_nodelist *ndlp, *next_ndlp;
6086 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6088 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6092 lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
6094 lpfc_els_flush_rscn(vport);
6095 lpfc_els_flush_cmd(vport);
6096 lpfc_disc_flush_list(vport);
6097 if (pci_channel_offline(vport->phba->pcidev))
6098 lpfc_notify_xport_npr(vport);
6101 /*****************************************************************************/
6103 * NAME: lpfc_disc_timeout
6105 * FUNCTION: Fibre Channel driver discovery timeout routine.
6107 * EXECUTION ENVIRONMENT: interrupt only
6115 /*****************************************************************************/
6117 lpfc_disc_timeout(struct timer_list *t)
6119 struct lpfc_vport *vport = from_timer(vport, t, fc_disctmo);
6120 struct lpfc_hba *phba = vport->phba;
6121 uint32_t tmo_posted;
6122 unsigned long flags = 0;
6124 if (unlikely(!phba))
6127 spin_lock_irqsave(&vport->work_port_lock, flags);
6128 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
6130 vport->work_port_events |= WORKER_DISC_TMO;
6131 spin_unlock_irqrestore(&vport->work_port_lock, flags);
6134 lpfc_worker_wake_up(phba);
6139 lpfc_disc_timeout_handler(struct lpfc_vport *vport)
6141 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6142 struct lpfc_hba *phba = vport->phba;
6143 struct lpfc_sli *psli = &phba->sli;
6144 struct lpfc_nodelist *ndlp, *next_ndlp;
6145 LPFC_MBOXQ_t *initlinkmbox;
6146 int rc, clrlaerr = 0;
6148 if (!(vport->fc_flag & FC_DISC_TMO))
6151 spin_lock_irq(shost->host_lock);
6152 vport->fc_flag &= ~FC_DISC_TMO;
6153 spin_unlock_irq(shost->host_lock);
6155 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6156 "disc timeout: state:x%x rtry:x%x flg:x%x",
6157 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
6159 switch (vport->port_state) {
6161 case LPFC_LOCAL_CFG_LINK:
6163 * port_state is identically LPFC_LOCAL_CFG_LINK while
6164 * waiting for FAN timeout
6166 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
6167 "0221 FAN timeout\n");
6169 /* Start discovery by sending FLOGI, clean up old rpis */
6170 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
6172 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
6174 if (ndlp->nlp_type & NLP_FABRIC) {
6175 /* Clean up the ndlp on Fabric connections */
6176 lpfc_drop_node(vport, ndlp);
6178 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
6179 /* Fail outstanding IO now since device
6180 * is marked for PLOGI.
6182 lpfc_unreg_rpi(vport, ndlp);
6185 if (vport->port_state != LPFC_FLOGI) {
6186 if (phba->sli_rev <= LPFC_SLI_REV3)
6187 lpfc_initial_flogi(vport);
6189 lpfc_issue_init_vfi(vport);
6196 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
6197 /* Initial FLOGI timeout */
6198 lpfc_printf_vlog(vport, KERN_ERR,
6200 "0222 Initial %s timeout\n",
6201 vport->vpi ? "FDISC" : "FLOGI");
6203 /* Assume no Fabric and go on with discovery.
6204 * Check for outstanding ELS FLOGI to abort.
6207 /* FLOGI failed, so just use loop map to make discovery list */
6208 lpfc_disc_list_loopmap(vport);
6210 /* Start discovery */
6211 lpfc_disc_start(vport);
6214 case LPFC_FABRIC_CFG_LINK:
6215 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
6217 lpfc_printf_vlog(vport, KERN_ERR,
6219 "0223 Timeout while waiting for "
6220 "NameServer login\n");
6221 /* Next look for NameServer ndlp */
6222 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6224 lpfc_els_abort(phba, ndlp);
6226 /* ReStart discovery */
6230 /* Check for wait for NameServer Rsp timeout */
6231 lpfc_printf_vlog(vport, KERN_ERR,
6233 "0224 NameServer Query timeout "
6235 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
6237 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
6238 /* Try it one more time */
6239 vport->fc_ns_retry++;
6240 vport->gidft_inp = 0;
6241 rc = lpfc_issue_gidft(vport);
6245 vport->fc_ns_retry = 0;
6249 * Discovery is over.
6250 * set port_state to PORT_READY if SLI2.
6251 * cmpl_reg_vpi will set port_state to READY for SLI3.
6253 if (phba->sli_rev < LPFC_SLI_REV4) {
6254 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6255 lpfc_issue_reg_vpi(phba, vport);
6257 lpfc_issue_clear_la(phba, vport);
6258 vport->port_state = LPFC_VPORT_READY;
6262 /* Setup and issue mailbox INITIALIZE LINK command */
6263 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6264 if (!initlinkmbox) {
6265 lpfc_printf_vlog(vport, KERN_ERR,
6267 "0206 Device Discovery "
6268 "completion error\n");
6269 phba->link_state = LPFC_HBA_ERROR;
6273 lpfc_linkdown(phba);
6274 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
6275 phba->cfg_link_speed);
6276 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6277 initlinkmbox->vport = vport;
6278 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6279 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
6280 lpfc_set_loopback_flag(phba);
6281 if (rc == MBX_NOT_FINISHED)
6282 mempool_free(initlinkmbox, phba->mbox_mem_pool);
6286 case LPFC_DISC_AUTH:
6287 /* Node Authentication timeout */
6288 lpfc_printf_vlog(vport, KERN_ERR,
6290 "0227 Node Authentication timeout\n");
6291 lpfc_disc_flush_list(vport);
6294 * set port_state to PORT_READY if SLI2.
6295 * cmpl_reg_vpi will set port_state to READY for SLI3.
6297 if (phba->sli_rev < LPFC_SLI_REV4) {
6298 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
6299 lpfc_issue_reg_vpi(phba, vport);
6300 else { /* NPIV Not enabled */
6301 lpfc_issue_clear_la(phba, vport);
6302 vport->port_state = LPFC_VPORT_READY;
6307 case LPFC_VPORT_READY:
6308 if (vport->fc_flag & FC_RSCN_MODE) {
6309 lpfc_printf_vlog(vport, KERN_ERR,
6311 "0231 RSCN timeout Data: x%x "
6313 vport->fc_ns_retry, LPFC_MAX_NS_RETRY,
6314 vport->port_state, vport->gidft_inp);
6316 /* Cleanup any outstanding ELS commands */
6317 lpfc_els_flush_cmd(vport);
6319 lpfc_els_flush_rscn(vport);
6320 lpfc_disc_flush_list(vport);
6325 lpfc_printf_vlog(vport, KERN_ERR,
6327 "0273 Unexpected discovery timeout, "
6328 "vport State x%x\n", vport->port_state);
6332 switch (phba->link_state) {
6334 /* CLEAR LA timeout */
6335 lpfc_printf_vlog(vport, KERN_ERR,
6337 "0228 CLEAR LA timeout\n");
6342 lpfc_issue_clear_la(phba, vport);
6344 case LPFC_LINK_UNKNOWN:
6345 case LPFC_WARM_START:
6346 case LPFC_INIT_START:
6347 case LPFC_INIT_MBX_CMDS:
6348 case LPFC_LINK_DOWN:
6349 case LPFC_HBA_ERROR:
6350 lpfc_printf_vlog(vport, KERN_ERR,
6352 "0230 Unexpected timeout, hba link "
6353 "state x%x\n", phba->link_state);
6357 case LPFC_HBA_READY:
6362 lpfc_disc_flush_list(vport);
6363 if (phba->sli_rev != LPFC_SLI_REV4) {
6364 psli->sli3_ring[(LPFC_EXTRA_RING)].flag &=
6365 ~LPFC_STOP_IOCB_EVENT;
6366 psli->sli3_ring[LPFC_FCP_RING].flag &=
6367 ~LPFC_STOP_IOCB_EVENT;
6369 vport->port_state = LPFC_VPORT_READY;
6375 * This routine handles processing a NameServer REG_LOGIN mailbox
6376 * command upon completion. It is setup in the LPFC_MBOXQ
6377 * as the completion routine when the command is
6378 * handed off to the SLI layer.
6381 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6383 MAILBOX_t *mb = &pmb->u.mb;
6384 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
6385 struct lpfc_vport *vport = pmb->vport;
6387 pmb->ctx_ndlp = NULL;
6389 if (phba->sli_rev < LPFC_SLI_REV4)
6390 ndlp->nlp_rpi = mb->un.varWords[0];
6391 ndlp->nlp_flag |= NLP_RPI_REGISTERED;
6392 ndlp->nlp_type |= NLP_FABRIC;
6393 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
6394 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6395 "0004 rpi:%x DID:%x flg:%x %d x%px\n",
6396 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
6397 kref_read(&ndlp->kref),
6400 * Start issuing Fabric-Device Management Interface (FDMI) command to
6401 * 0xfffffa (FDMI well known port).
6402 * DHBA -> DPRT -> RHBA -> RPA (physical port)
6403 * DPRT -> RPRT (vports)
6405 if (vport->port_type == LPFC_PHYSICAL_PORT) {
6406 phba->link_flag &= ~LS_CT_VEN_RPA; /* For extra Vendor RPA */
6407 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
6409 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
6413 /* decrement the node reference count held for this callback
6417 lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
6422 lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
6424 uint16_t *rpi = param;
6426 return ndlp->nlp_rpi == *rpi;
6430 lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
6432 return memcmp(&ndlp->nlp_portname, param,
6433 sizeof(ndlp->nlp_portname)) == 0;
6436 static struct lpfc_nodelist *
6437 __lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
6439 struct lpfc_nodelist *ndlp;
6441 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6442 if (filter(ndlp, param)) {
6443 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6444 "3185 FIND node filter %ps DID "
6445 "ndlp x%px did x%x flg x%x st x%x "
6446 "xri x%x type x%x rpi x%x\n",
6447 filter, ndlp, ndlp->nlp_DID,
6448 ndlp->nlp_flag, ndlp->nlp_state,
6449 ndlp->nlp_xri, ndlp->nlp_type,
6454 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6455 "3186 FIND node filter %ps NOT FOUND.\n", filter);
6460 * This routine looks up the ndlp lists for the given RPI. If rpi found it
6461 * returns the node list element pointer else return NULL.
6463 struct lpfc_nodelist *
6464 __lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6466 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
6470 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
6471 * returns the node element list pointer else return NULL.
6473 struct lpfc_nodelist *
6474 lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
6476 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6477 struct lpfc_nodelist *ndlp;
6479 spin_lock_irq(shost->host_lock);
6480 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
6481 spin_unlock_irq(shost->host_lock);
6486 * This routine looks up the ndlp lists for the given RPI. If the rpi
6487 * is found, the routine returns the node element list pointer else
6490 struct lpfc_nodelist *
6491 lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
6493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6494 struct lpfc_nodelist *ndlp;
6495 unsigned long flags;
6497 spin_lock_irqsave(shost->host_lock, flags);
6498 ndlp = __lpfc_findnode_rpi(vport, rpi);
6499 spin_unlock_irqrestore(shost->host_lock, flags);
6504 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6505 * @phba: pointer to lpfc hba data structure.
6506 * @vpi: the physical host virtual N_Port identifier.
6508 * This routine finds a vport on a HBA (referred by @phba) through a
6509 * @vpi. The function walks the HBA's vport list and returns the address
6510 * of the vport with the matching @vpi.
6513 * NULL - No vport with the matching @vpi found
6514 * Otherwise - Address to the vport with the matching @vpi.
6517 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6519 struct lpfc_vport *vport;
6520 unsigned long flags;
6523 /* The physical ports are always vpi 0 - translate is unnecessary. */
6526 * Translate the physical vpi to the logical vpi. The
6527 * vport stores the logical vpi.
6529 for (i = 0; i <= phba->max_vpi; i++) {
6530 if (vpi == phba->vpi_ids[i])
6534 if (i > phba->max_vpi) {
6535 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6536 "2936 Could not find Vport mapped "
6537 "to vpi %d\n", vpi);
6542 spin_lock_irqsave(&phba->port_list_lock, flags);
6543 list_for_each_entry(vport, &phba->port_list, listentry) {
6544 if (vport->vpi == i) {
6545 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6549 spin_unlock_irqrestore(&phba->port_list_lock, flags);
6553 struct lpfc_nodelist *
6554 lpfc_nlp_init(struct lpfc_vport *vport, uint32_t did)
6556 struct lpfc_nodelist *ndlp;
6557 int rpi = LPFC_RPI_ALLOC_ERROR;
6559 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6560 rpi = lpfc_sli4_alloc_rpi(vport->phba);
6561 if (rpi == LPFC_RPI_ALLOC_ERROR)
6565 ndlp = mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
6567 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6568 lpfc_sli4_free_rpi(vport->phba, rpi);
6572 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
6574 spin_lock_init(&ndlp->lock);
6576 lpfc_initialize_node(vport, ndlp, did);
6577 INIT_LIST_HEAD(&ndlp->nlp_listp);
6578 if (vport->phba->sli_rev == LPFC_SLI_REV4) {
6579 ndlp->nlp_rpi = rpi;
6580 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE | LOG_DISCOVERY,
6581 "0007 Init New ndlp x%px, rpi:x%x DID:%x "
6582 "flg:x%x refcnt:%d\n",
6583 ndlp, ndlp->nlp_rpi, ndlp->nlp_DID,
6584 ndlp->nlp_flag, kref_read(&ndlp->kref));
6586 ndlp->active_rrqs_xri_bitmap =
6587 mempool_alloc(vport->phba->active_rrq_pool,
6589 if (ndlp->active_rrqs_xri_bitmap)
6590 memset(ndlp->active_rrqs_xri_bitmap, 0,
6591 ndlp->phba->cfg_rrq_xri_bitmap_sz);
6596 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
6597 "node init: did:x%x",
6598 ndlp->nlp_DID, 0, 0);
6603 /* This routine releases all resources associated with a specifc NPort's ndlp
6604 * and mempool_free's the nodelist.
6607 lpfc_nlp_release(struct kref *kref)
6609 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
6611 struct lpfc_vport *vport = ndlp->vport;
6613 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6614 "node release: did:x%x flg:x%x type:x%x",
6615 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
6617 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
6618 "0279 %s: ndlp: x%px did %x refcnt:%d rpi:%x\n",
6619 __func__, ndlp, ndlp->nlp_DID,
6620 kref_read(&ndlp->kref), ndlp->nlp_rpi);
6622 /* remove ndlp from action. */
6623 lpfc_cancel_retry_delay_tmo(vport, ndlp);
6624 lpfc_cleanup_node(vport, ndlp);
6626 /* Not all ELS transactions have registered the RPI with the port.
6627 * In these cases the rpi usage is temporary and the node is
6628 * released when the WQE is completed. Catch this case to free the
6629 * RPI to the pool. Because this node is in the release path, a lock
6630 * is unnecessary. All references are gone and the node has been
6633 if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
6634 if (ndlp->nlp_rpi != LPFC_RPI_ALLOC_ERROR &&
6635 !(ndlp->nlp_flag & (NLP_RPI_REGISTERED | NLP_UNREG_INP))) {
6636 lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
6637 ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
6641 /* The node is not freed back to memory, it is released to a pool so
6642 * the node fields need to be cleaned up.
6645 ndlp->nlp_state = NLP_STE_FREED_NODE;
6647 ndlp->fc4_xpt_flags = 0;
6649 /* free ndlp memory for final ndlp release */
6650 if (ndlp->phba->sli_rev == LPFC_SLI_REV4)
6651 mempool_free(ndlp->active_rrqs_xri_bitmap,
6652 ndlp->phba->active_rrq_pool);
6653 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
6656 /* This routine bumps the reference count for a ndlp structure to ensure
6657 * that one discovery thread won't free a ndlp while another discovery thread
6660 struct lpfc_nodelist *
6661 lpfc_nlp_get(struct lpfc_nodelist *ndlp)
6663 unsigned long flags;
6666 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6667 "node get: did:x%x flg:x%x refcnt:x%x",
6668 ndlp->nlp_DID, ndlp->nlp_flag,
6669 kref_read(&ndlp->kref));
6671 /* The check of ndlp usage to prevent incrementing the
6672 * ndlp reference count that is in the process of being
6675 spin_lock_irqsave(&ndlp->lock, flags);
6676 if (!kref_get_unless_zero(&ndlp->kref)) {
6677 spin_unlock_irqrestore(&ndlp->lock, flags);
6678 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
6679 "0276 %s: ndlp:x%px refcnt:%d\n",
6680 __func__, (void *)ndlp, kref_read(&ndlp->kref));
6683 spin_unlock_irqrestore(&ndlp->lock, flags);
6685 WARN_ONCE(!ndlp, "**** %s, get ref on NULL ndlp!", __func__);
6691 /* This routine decrements the reference count for a ndlp structure. If the
6692 * count goes to 0, this indicates the associated nodelist should be freed.
6695 lpfc_nlp_put(struct lpfc_nodelist *ndlp)
6698 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
6699 "node put: did:x%x flg:x%x refcnt:x%x",
6700 ndlp->nlp_DID, ndlp->nlp_flag,
6701 kref_read(&ndlp->kref));
6703 WARN_ONCE(!ndlp, "**** %s, put ref on NULL ndlp!", __func__);
6706 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
6710 * lpfc_fcf_inuse - Check if FCF can be unregistered.
6711 * @phba: Pointer to hba context object.
6713 * This function iterate through all FC nodes associated
6714 * will all vports to check if there is any node with
6715 * fc_rports associated with it. If there is an fc_rport
6716 * associated with the node, then the node is either in
6717 * discovered state or its devloss_timer is pending.
6720 lpfc_fcf_inuse(struct lpfc_hba *phba)
6722 struct lpfc_vport **vports;
6724 struct lpfc_nodelist *ndlp;
6725 struct Scsi_Host *shost;
6727 vports = lpfc_create_vport_work_array(phba);
6729 /* If driver cannot allocate memory, indicate fcf is in use */
6733 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6734 shost = lpfc_shost_from_vport(vports[i]);
6735 spin_lock_irq(shost->host_lock);
6737 * IF the CVL_RCVD bit is not set then we have sent the
6739 * If dev_loss fires while we are waiting we do not want to
6742 if (!(vports[i]->fc_flag & FC_VPORT_CVL_RCVD)) {
6743 spin_unlock_irq(shost->host_lock);
6747 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
6749 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
6751 spin_unlock_irq(shost->host_lock);
6753 } else if (ndlp->nlp_flag & NLP_RPI_REGISTERED) {
6755 lpfc_printf_log(phba, KERN_INFO,
6756 LOG_NODE | LOG_DISCOVERY,
6757 "2624 RPI %x DID %x flag %x "
6758 "still logged in\n",
6759 ndlp->nlp_rpi, ndlp->nlp_DID,
6763 spin_unlock_irq(shost->host_lock);
6766 lpfc_destroy_vport_work_array(phba, vports);
6771 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
6772 * @phba: Pointer to hba context object.
6773 * @mboxq: Pointer to mailbox object.
6775 * This function frees memory associated with the mailbox command.
6778 lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6780 struct lpfc_vport *vport = mboxq->vport;
6781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6783 if (mboxq->u.mb.mbxStatus) {
6784 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6785 "2555 UNREG_VFI mbxStatus error x%x "
6787 mboxq->u.mb.mbxStatus, vport->port_state);
6789 spin_lock_irq(shost->host_lock);
6790 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
6791 spin_unlock_irq(shost->host_lock);
6792 mempool_free(mboxq, phba->mbox_mem_pool);
6797 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
6798 * @phba: Pointer to hba context object.
6799 * @mboxq: Pointer to mailbox object.
6801 * This function frees memory associated with the mailbox command.
6804 lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
6806 struct lpfc_vport *vport = mboxq->vport;
6808 if (mboxq->u.mb.mbxStatus) {
6809 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6810 "2550 UNREG_FCFI mbxStatus error x%x "
6812 mboxq->u.mb.mbxStatus, vport->port_state);
6814 mempool_free(mboxq, phba->mbox_mem_pool);
6819 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
6820 * @phba: Pointer to hba context object.
6822 * This function prepare the HBA for unregistering the currently registered
6823 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
6827 lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
6829 struct lpfc_vport **vports;
6830 struct lpfc_nodelist *ndlp;
6831 struct Scsi_Host *shost;
6834 /* Unregister RPIs */
6835 if (lpfc_fcf_inuse(phba))
6836 lpfc_unreg_hba_rpis(phba);
6838 /* At this point, all discovery is aborted */
6839 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
6841 /* Unregister VPIs */
6842 vports = lpfc_create_vport_work_array(phba);
6843 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
6844 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6845 /* Stop FLOGI/FDISC retries */
6846 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6848 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6849 lpfc_cleanup_pending_mbox(vports[i]);
6850 if (phba->sli_rev == LPFC_SLI_REV4)
6851 lpfc_sli4_unreg_all_rpis(vports[i]);
6852 lpfc_mbx_unreg_vpi(vports[i]);
6853 shost = lpfc_shost_from_vport(vports[i]);
6854 spin_lock_irq(shost->host_lock);
6855 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6856 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
6857 spin_unlock_irq(shost->host_lock);
6859 lpfc_destroy_vport_work_array(phba, vports);
6860 if (i == 0 && (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))) {
6861 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6863 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
6864 lpfc_cleanup_pending_mbox(phba->pport);
6865 if (phba->sli_rev == LPFC_SLI_REV4)
6866 lpfc_sli4_unreg_all_rpis(phba->pport);
6867 lpfc_mbx_unreg_vpi(phba->pport);
6868 shost = lpfc_shost_from_vport(phba->pport);
6869 spin_lock_irq(shost->host_lock);
6870 phba->pport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
6871 phba->pport->vpi_state &= ~LPFC_VPI_REGISTERED;
6872 spin_unlock_irq(shost->host_lock);
6875 /* Cleanup any outstanding ELS commands */
6876 lpfc_els_flush_all_cmd(phba);
6878 /* Unregister the physical port VFI */
6879 rc = lpfc_issue_unreg_vfi(phba->pport);
6884 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
6885 * @phba: Pointer to hba context object.
6887 * This function issues synchronous unregister FCF mailbox command to HBA to
6888 * unregister the currently registered FCF record. The driver does not reset
6889 * the driver FCF usage state flags.
6891 * Return 0 if successfully issued, none-zero otherwise.
6894 lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
6899 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6901 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6902 "2551 UNREG_FCFI mbox allocation failed"
6903 "HBA state x%x\n", phba->pport->port_state);
6906 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
6907 mbox->vport = phba->pport;
6908 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
6909 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6911 if (rc == MBX_NOT_FINISHED) {
6912 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6913 "2552 Unregister FCFI command failed rc x%x "
6915 rc, phba->pport->port_state);
6922 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
6923 * @phba: Pointer to hba context object.
6925 * This function unregisters the currently reigstered FCF. This function
6926 * also tries to find another FCF for discovery by rescan the HBA FCF table.
6929 lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
6933 /* Preparation for unregistering fcf */
6934 rc = lpfc_unregister_fcf_prep(phba);
6936 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6937 "2748 Failed to prepare for unregistering "
6938 "HBA's FCF record: rc=%d\n", rc);
6942 /* Now, unregister FCF record and reset HBA FCF state */
6943 rc = lpfc_sli4_unregister_fcf(phba);
6946 /* Reset HBA FCF states after successful unregister FCF */
6947 spin_lock_irq(&phba->hbalock);
6948 phba->fcf.fcf_flag = 0;
6949 spin_unlock_irq(&phba->hbalock);
6950 phba->fcf.current_rec.flag = 0;
6953 * If driver is not unloading, check if there is any other
6954 * FCF record that can be used for discovery.
6956 if ((phba->pport->load_flag & FC_UNLOADING) ||
6957 (phba->link_state < LPFC_LINK_UP))
6960 /* This is considered as the initial FCF discovery scan */
6961 spin_lock_irq(&phba->hbalock);
6962 phba->fcf.fcf_flag |= FCF_INIT_DISC;
6963 spin_unlock_irq(&phba->hbalock);
6965 /* Reset FCF roundrobin bmask for new discovery */
6966 lpfc_sli4_clear_fcf_rr_bmask(phba);
6968 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
6971 spin_lock_irq(&phba->hbalock);
6972 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
6973 spin_unlock_irq(&phba->hbalock);
6974 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6975 "2553 lpfc_unregister_unused_fcf failed "
6976 "to read FCF record HBA state x%x\n",
6977 phba->pport->port_state);
6982 * lpfc_unregister_fcf - Unregister the currently registered fcf record
6983 * @phba: Pointer to hba context object.
6985 * This function just unregisters the currently reigstered FCF. It does not
6986 * try to find another FCF for discovery.
6989 lpfc_unregister_fcf(struct lpfc_hba *phba)
6993 /* Preparation for unregistering fcf */
6994 rc = lpfc_unregister_fcf_prep(phba);
6996 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
6997 "2749 Failed to prepare for unregistering "
6998 "HBA's FCF record: rc=%d\n", rc);
7002 /* Now, unregister FCF record and reset HBA FCF state */
7003 rc = lpfc_sli4_unregister_fcf(phba);
7006 /* Set proper HBA FCF states after successful unregister FCF */
7007 spin_lock_irq(&phba->hbalock);
7008 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
7009 spin_unlock_irq(&phba->hbalock);
7013 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
7014 * @phba: Pointer to hba context object.
7016 * This function check if there are any connected remote port for the FCF and
7017 * if all the devices are disconnected, this function unregister FCFI.
7018 * This function also tries to use another FCF for discovery.
7021 lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
7024 * If HBA is not running in FIP mode, if HBA does not support
7025 * FCoE, if FCF discovery is ongoing, or if FCF has not been
7026 * registered, do nothing.
7028 spin_lock_irq(&phba->hbalock);
7029 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
7030 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
7031 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
7032 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
7033 (phba->pport->port_state == LPFC_FLOGI)) {
7034 spin_unlock_irq(&phba->hbalock);
7037 spin_unlock_irq(&phba->hbalock);
7039 if (lpfc_fcf_inuse(phba))
7042 lpfc_unregister_fcf_rescan(phba);
7046 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
7047 * @phba: Pointer to hba context object.
7048 * @buff: Buffer containing the FCF connection table as in the config
7050 * This function create driver data structure for the FCF connection
7051 * record table read from config region 23.
7054 lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
7057 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
7058 struct lpfc_fcf_conn_hdr *conn_hdr;
7059 struct lpfc_fcf_conn_rec *conn_rec;
7060 uint32_t record_count;
7063 /* Free the current connect table */
7064 list_for_each_entry_safe(conn_entry, next_conn_entry,
7065 &phba->fcf_conn_rec_list, list) {
7066 list_del_init(&conn_entry->list);
7070 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
7071 record_count = conn_hdr->length * sizeof(uint32_t)/
7072 sizeof(struct lpfc_fcf_conn_rec);
7074 conn_rec = (struct lpfc_fcf_conn_rec *)
7075 (buff + sizeof(struct lpfc_fcf_conn_hdr));
7077 for (i = 0; i < record_count; i++) {
7078 if (!(conn_rec[i].flags & FCFCNCT_VALID))
7080 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
7083 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7084 "2566 Failed to allocate connection"
7089 memcpy(&conn_entry->conn_rec, &conn_rec[i],
7090 sizeof(struct lpfc_fcf_conn_rec));
7091 list_add_tail(&conn_entry->list,
7092 &phba->fcf_conn_rec_list);
7095 if (!list_empty(&phba->fcf_conn_rec_list)) {
7097 list_for_each_entry(conn_entry, &phba->fcf_conn_rec_list,
7099 conn_rec = &conn_entry->conn_rec;
7100 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7101 "3345 FCF connection list rec[%02d]: "
7102 "flags:x%04x, vtag:x%04x, "
7103 "fabric_name:x%02x:%02x:%02x:%02x:"
7104 "%02x:%02x:%02x:%02x, "
7105 "switch_name:x%02x:%02x:%02x:%02x:"
7106 "%02x:%02x:%02x:%02x\n", i++,
7107 conn_rec->flags, conn_rec->vlan_tag,
7108 conn_rec->fabric_name[0],
7109 conn_rec->fabric_name[1],
7110 conn_rec->fabric_name[2],
7111 conn_rec->fabric_name[3],
7112 conn_rec->fabric_name[4],
7113 conn_rec->fabric_name[5],
7114 conn_rec->fabric_name[6],
7115 conn_rec->fabric_name[7],
7116 conn_rec->switch_name[0],
7117 conn_rec->switch_name[1],
7118 conn_rec->switch_name[2],
7119 conn_rec->switch_name[3],
7120 conn_rec->switch_name[4],
7121 conn_rec->switch_name[5],
7122 conn_rec->switch_name[6],
7123 conn_rec->switch_name[7]);
7129 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
7130 * @phba: Pointer to hba context object.
7131 * @buff: Buffer containing the FCoE parameter data structure.
7133 * This function update driver data structure with config
7134 * parameters read from config region 23.
7137 lpfc_read_fcoe_param(struct lpfc_hba *phba,
7140 struct lpfc_fip_param_hdr *fcoe_param_hdr;
7141 struct lpfc_fcoe_params *fcoe_param;
7143 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
7145 fcoe_param = (struct lpfc_fcoe_params *)
7146 (buff + sizeof(struct lpfc_fip_param_hdr));
7148 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
7149 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
7152 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
7153 phba->valid_vlan = 1;
7154 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
7158 phba->fc_map[0] = fcoe_param->fc_map[0];
7159 phba->fc_map[1] = fcoe_param->fc_map[1];
7160 phba->fc_map[2] = fcoe_param->fc_map[2];
7165 * lpfc_get_rec_conf23 - Get a record type in config region data.
7166 * @buff: Buffer containing config region 23 data.
7167 * @size: Size of the data buffer.
7168 * @rec_type: Record type to be searched.
7170 * This function searches config region data to find the beginning
7171 * of the record specified by record_type. If record found, this
7172 * function return pointer to the record else return NULL.
7175 lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
7177 uint32_t offset = 0, rec_length;
7179 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
7180 (size < sizeof(uint32_t)))
7183 rec_length = buff[offset + 1];
7186 * One TLV record has one word header and number of data words
7187 * specified in the rec_length field of the record header.
7189 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
7191 if (buff[offset] == rec_type)
7192 return &buff[offset];
7194 if (buff[offset] == LPFC_REGION23_LAST_REC)
7197 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
7198 rec_length = buff[offset + 1];
7204 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
7205 * @phba: Pointer to lpfc_hba data structure.
7206 * @buff: Buffer containing config region 23 data.
7207 * @size: Size of the data buffer.
7209 * This function parses the FCoE config parameters in config region 23 and
7210 * populate driver data structure with the parameters.
7213 lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
7217 uint32_t offset = 0;
7221 * If data size is less than 2 words signature and version cannot be
7224 if (size < 2*sizeof(uint32_t))
7227 /* Check the region signature first */
7228 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
7229 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7230 "2567 Config region 23 has bad signature\n");
7236 /* Check the data structure version */
7237 if (buff[offset] != LPFC_REGION23_VERSION) {
7238 lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
7239 "2568 Config region 23 has bad version\n");
7244 /* Read FCoE param record */
7245 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7246 size - offset, FCOE_PARAM_TYPE);
7248 lpfc_read_fcoe_param(phba, rec_ptr);
7250 /* Read FCF connection table */
7251 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
7252 size - offset, FCOE_CONN_TBL_TYPE);
7254 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
7259 * lpfc_error_lost_link - IO failure from link event or FW reset check.
7261 * @vport: Pointer to lpfc_vport data structure.
7262 * @ulp_status: IO completion status.
7263 * @ulp_word4: Reason code for the ulp_status.
7265 * This function evaluates the ulp_status and ulp_word4 values
7266 * for specific error values that indicate an internal link fault
7267 * or fw reset event for the completing IO. Callers require this
7268 * common data to decide next steps on the IO.
7271 * false - No link or reset error occurred.
7272 * true - A link or reset error occurred.
7275 lpfc_error_lost_link(struct lpfc_vport *vport, u32 ulp_status, u32 ulp_word4)
7277 /* Mask off the extra port data to get just the reason code. */
7278 u32 rsn_code = IOERR_PARAM_MASK & ulp_word4;
7280 if (ulp_status == IOSTAT_LOCAL_REJECT &&
7281 (rsn_code == IOERR_SLI_ABORTED ||
7282 rsn_code == IOERR_LINK_DOWN ||
7283 rsn_code == IOERR_SLI_DOWN)) {
7284 lpfc_printf_vlog(vport, KERN_WARNING, LOG_SLI | LOG_ELS,
7285 "0408 Report link error true: <x%x:x%x>\n",
7286 ulp_status, ulp_word4);