/******************************************************************* * This file is part of the Emulex Linux Device Driver for * * Fibre Channel Host Bus Adapters. * * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term * * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * * Copyright (C) 2004-2016 Emulex. All rights reserved. * * EMULEX and SLI are trademarks of Emulex. * * www.broadcom.com * * Portions Copyright (C) 2004-2005 Christoph Hellwig * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of version 2 of the GNU General * * Public License as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful. * * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * * TO BE LEGALLY INVALID. See the GNU General Public License for * * more details, a copy of which can be found in the file COPYING * * included with this package. *
*******************************************************************/
if (fc_vport) { /* * When the transport defines fc_vport_set state we will replace * this code with the following line
*/ /* fc_vport_set_state(fc_vport, new_state); */ if (new_state != FC_VPORT_INITIALIZING)
fc_vport->vport_last_state = fc_vport->vport_state;
fc_vport->vport_state = new_state;
}
/* for all the error states we will set the invternal state to FAILED */ switch (new_state) { case FC_VPORT_NO_FABRIC_SUPP: case FC_VPORT_NO_FABRIC_RSCS: case FC_VPORT_FABRIC_LOGOUT: case FC_VPORT_FABRIC_REJ_WWN: case FC_VPORT_FAILED:
vport->port_state = LPFC_VPORT_FAILED; break; case FC_VPORT_LINKDOWN:
vport->port_state = LPFC_VPORT_UNKNOWN; break; default: /* do nothing */ break;
}
}
int
lpfc_alloc_vpi(struct lpfc_hba *phba)
{ unsignedlong vpi;
spin_lock_irq(&phba->hbalock); /* Start at bit 1 because vpi zero is reserved for the physical port */
vpi = find_next_zero_bit(phba->vpi_bmask, (phba->max_vpi + 1), 1); if (vpi > phba->max_vpi)
vpi = 0; else
set_bit(vpi, phba->vpi_bmask); if (phba->sli_rev == LPFC_SLI_REV4)
phba->sli4_hba.max_cfg_param.vpi_used++;
spin_unlock_irq(&phba->hbalock); return vpi;
}
staticvoid
lpfc_free_vpi(struct lpfc_hba *phba, int vpi)
{ if (vpi == 0) return;
spin_lock_irq(&phba->hbalock);
clear_bit(vpi, phba->vpi_bmask); if (phba->sli_rev == LPFC_SLI_REV4)
phba->sli4_hba.max_cfg_param.vpi_used--;
spin_unlock_irq(&phba->hbalock);
}
/* * Wait for the read_sparams mailbox to complete. Driver needs * this per vport to start the FDISC. If the mailbox fails, * just cleanup and return an error unless the failure is a * mailbox timeout. For MBX_TIMEOUT, allow the default * mbox completion handler to take care of the cleanup. This * is safe as the mailbox command isn't one that triggers * another mailbox.
*/
pmb->vport = vport;
rc = lpfc_sli_issue_mbox_wait(phba, pmb, phba->fc_ratov * 2); if (rc != MBX_SUCCESS) { if (signal_pending(current)) {
lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, "1830 Signal aborted mbxCmd x%x\n",
mb->mbxCommand); if (rc != MBX_TIMEOUT)
lpfc_mbox_rsrc_cleanup(phba, pmb,
MBOX_THD_UNLOCKED); return -EINTR;
} else {
lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, "1818 VPort failed init, mbxCmd x%x " "READ_SPARM mbxStatus x%x, rc = x%x\n",
mb->mbxCommand, mb->mbxStatus, rc); if (rc != MBX_TIMEOUT)
lpfc_mbox_rsrc_cleanup(phba, pmb,
MBOX_THD_UNLOCKED); return -EIO;
}
}
spin_lock_irqsave(&phba->port_list_lock, flags);
list_for_each_entry(vport, &phba->port_list, listentry) { if (vport == new_vport) continue; /* If they match, return not unique */ if (memcmp(&vport->fc_sparam.portName,
&new_vport->fc_sparam.portName, sizeof(struct lpfc_name)) == 0) {
spin_unlock_irqrestore(&phba->port_list_lock, flags); return 0;
}
}
spin_unlock_irqrestore(&phba->port_list_lock, flags); return 1;
}
/** * lpfc_discovery_wait - Wait for driver discovery to quiesce * @vport: The virtual port for which this call is being executed. * * This driver calls this routine specifically from lpfc_vport_delete * to enforce a synchronous execution of vport * delete relative to discovery activities. The * lpfc_vport_delete routine should not return until it * can reasonably guarantee that discovery has quiesced. * Post FDISC LOGO, the driver must wait until its SAN teardown is * complete and all resources recovered before allowing * cleanup. * * This routine does not require any locks held.
**/ staticvoid lpfc_discovery_wait(struct lpfc_vport *vport)
{ struct lpfc_hba *phba = vport->phba; unsignedlong wait_time_max; unsignedlong start_time;
/* * The time constraint on this loop is a balance between the * fabric RA_TOV value and dev_loss tmo. The driver's * devloss_tmo is 10 giving this loop a 3x multiplier minimally.
*/
wait_time_max = secs_to_jiffies((phba->fc_ratov * 3) + 3);
wait_time_max += jiffies;
start_time = jiffies; while (time_before(jiffies, wait_time_max)) { if ((vport->num_disc_nodes > 0) ||
test_bit(FC_RSCN_MODE, &vport->fc_flag) ||
test_bit(FC_RSCN_DISCOVERY, &vport->fc_flag) ||
test_bit(FC_NLP_MORE, &vport->fc_flag) ||
test_bit(FC_RSCN_DEFERRED, &vport->fc_flag) ||
test_bit(FC_NDISC_ACTIVE, &vport->fc_flag) ||
test_bit(FC_DISC_TMO, &vport->fc_flag) ||
((vport->port_state > LPFC_VPORT_FAILED) &&
(vport->port_state < LPFC_VPORT_READY))) {
lpfc_printf_vlog(vport, KERN_INFO, LOG_VPORT, "1833 Vport discovery quiesce Wait: " "state x%x fc_flags x%lx " "num_nodes x%x, waiting 1000 msecs " "total wait msecs x%x\n",
vport->port_state, vport->fc_flag,
vport->num_disc_nodes,
jiffies_to_msecs(jiffies - start_time));
msleep(1000);
} else { /* Base case. Wait variants satisfied. Break out */
lpfc_printf_vlog(vport, KERN_INFO, LOG_VPORT, "1834 Vport discovery quiesced: " "state x%x fc_flags x%lx " "wait msecs x%x\n",
vport->port_state, vport->fc_flag,
jiffies_to_msecs(jiffies
- start_time)); break;
}
}
int
lpfc_vport_create(struct fc_vport *fc_vport, bool disable)
{ struct lpfc_nodelist *ndlp; struct Scsi_Host *shost = fc_vport->shost; struct lpfc_vport *pport = (struct lpfc_vport *) shost->hostdata; struct lpfc_hba *phba = pport->phba; struct lpfc_vport *vport = NULL; int instance; int vpi; int rc = VPORT_ERROR; int status;
if ((phba->sli_rev < 3) || !(phba->cfg_enable_npiv)) {
lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, "1808 Create VPORT failed: " "NPIV is not enabled: SLImode:%d\n",
phba->sli_rev);
rc = VPORT_INVAL; goto error_out;
}
/* NPIV is not supported if HBA has NVME Target enabled */ if (phba->nvmet_support) {
lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, "3189 Create VPORT failed: " "NPIV is not supported on NVME Target\n");
rc = VPORT_INVAL; goto error_out;
}
/* At this point we are fully registered with SCSI Layer. */
set_bit(FC_ALLOW_FDMI, &vport->load_flag); if (phba->cfg_enable_SmartSAN ||
(phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { /* Setup appropriate attribute masks */
vport->fdmi_hba_mask = phba->pport->fdmi_hba_mask;
vport->fdmi_port_mask = phba->pport->fdmi_port_mask;
}
/* * In SLI4, the vpi must be activated before it can be used * by the port.
*/ if ((phba->sli_rev == LPFC_SLI_REV4) &&
test_bit(FC_VFI_REGISTERED, &pport->fc_flag)) {
rc = lpfc_sli4_init_vpi(vport); if (rc) {
lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT, "1838 Failed to INIT_VPI on vpi %d " "status %d\n", vpi, rc);
rc = VPORT_NORESOURCES;
lpfc_free_vpi(phba, vpi); goto error_out;
}
} elseif (phba->sli_rev == LPFC_SLI_REV4) { /* * Driver cannot INIT_VPI now. Set the flags to * init_vpi when reg_vfi complete.
*/
set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag);
lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
rc = VPORT_OK; goto out;
}
/* Use the Physical nodes Fabric NDLP to determine if the link is * up and ready to FDISC.
*/
ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); if (ndlp &&
ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
lpfc_set_disctmo(vport);
lpfc_initial_fdisc(vport);
} else {
lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, "0262 No NPIV Fabric support\n");
}
} else {
lpfc_vport_set_state(vport, FC_VPORT_FAILED);
}
rc = VPORT_OK;
lpfc_stop_vport_timers(vport);
lpfc_unreg_all_rpis(vport);
lpfc_unreg_default_rpis(vport); /* * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) does the * scsi_host_put() to release the vport.
*/
lpfc_mbx_unreg_vpi(vport); if (phba->sli_rev == LPFC_SLI_REV4)
set_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag);
set_bit(FC_LOADING, &vport->load_flag); if (test_bit(FC_VPORT_NEEDS_INIT_VPI, &vport->fc_flag)) {
lpfc_issue_init_vpi(vport); goto out;
}
set_bit(FC_VPORT_NEEDS_REG_VPI, &vport->fc_flag);
/* Use the Physical nodes Fabric NDLP to determine if the link is * up and ready to FDISC.
*/
ndlp = lpfc_findnode_did(phba->pport, Fabric_DID); if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) { if (phba->link_flag & LS_NPIV_FAB_SUPPORTED) {
lpfc_set_disctmo(vport);
lpfc_initial_fdisc(vport);
} else {
lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, "0264 No NPIV Fabric support\n");
}
} else {
lpfc_vport_set_state(vport, FC_VPORT_FAILED);
}
/* If the vport is a static vport fail the deletion. */ if ((vport->vport_flag & STATIC_VPORT) &&
!test_bit(FC_UNLOADING, &phba->pport->load_flag)) {
lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT, "1837 vport_delete failed: Cannot delete " "static vport.\n"); return VPORT_ERROR;
}
set_bit(FC_UNLOADING, &vport->load_flag);
/* * If we are not unloading the driver then prevent the vport_delete * from happening until after this vport's discovery is finished.
*/ if (!test_bit(FC_UNLOADING, &phba->pport->load_flag)) { int check_count = 0; while (check_count < ((phba->fc_ratov * 3) + 3) &&
vport->port_state > LPFC_VPORT_FAILED &&
vport->port_state < LPFC_VPORT_READY) {
check_count++;
msleep(1000);
} if (vport->port_state > LPFC_VPORT_FAILED &&
vport->port_state < LPFC_VPORT_READY) return -EAGAIN;
}
/* * Take early refcount for outstanding I/O requests we schedule during * delete processing for unreg_vpi. Always keep this before * scsi_remove_host() as we can no longer obtain a reference through * scsi_host_get() after scsi_remove_host as shost is set to SHOST_DEL.
*/ if (!scsi_host_get(shost)) return VPORT_INVAL;
/* Send the DA_ID and Fabric LOGO to cleanup Nameserver entries. */
ndlp = lpfc_findnode_did(vport, Fabric_DID); if (!ndlp) goto skip_logo;
/* Send the DA_ID and Fabric LOGO to cleanup the NPIV fabric entries. */ if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE &&
phba->link_state >= LPFC_LINK_UP &&
phba->fc_topology != LPFC_TOPOLOGY_LOOP) { if (vport->cfg_enable_da_id) { /* Send DA_ID and wait for a completion. This is best * effort. If the DA_ID fails, likely the fabric will * "leak" NportIDs but at least the driver issued the * command.
*/
ndlp = lpfc_findnode_did(vport, NameServer_DID); if (!ndlp) goto issue_logo;
/* Remove the waitq and save_flags. It no * longer matters if the wake happened.
*/
spin_lock_irq(&ndlp->lock);
ndlp->da_id_waitq = NULL;
spin_unlock_irq(&ndlp->lock);
clear_bit(NLP_WAIT_FOR_DA_ID, &ndlp->save_flags);
}
issue_logo: /* * If the vpi is not registered, then a valid FDISC doesn't * exist and there is no need for a ELS LOGO. Just cleanup * the ndlp.
*/ if (!(vport->vpi_state & LPFC_VPI_REGISTERED)) goto skip_logo;
/* Issue a Fabric LOGO to cleanup fabric resources. */
ndlp = lpfc_findnode_did(vport, Fabric_DID); if (!ndlp) goto skip_logo;
rc = lpfc_send_npiv_logo(vport, ndlp); if (rc) goto skip_logo;
}
if (!test_bit(FC_UNLOADING, &phba->pport->load_flag))
lpfc_discovery_wait(vport);
skip_logo:
/* Remove FC host to break driver binding. */
fc_remove_host(shost);
scsi_remove_host(shost);
lpfc_cleanup(vport);
/* Remove scsi host now. The nodes are cleaned up. */
lpfc_sli_host_down(vport);
lpfc_stop_vport_timers(vport);
if (!test_bit(FC_UNLOADING, &phba->pport->load_flag)) {
lpfc_unreg_all_rpis(vport);
lpfc_unreg_default_rpis(vport); /* * Completion of unreg_vpi (lpfc_mbx_cmpl_unreg_vpi) * does the scsi_host_put() to release the vport.
*/ if (!(vport->vpi_state & LPFC_VPI_REGISTERED) ||
lpfc_mbx_unreg_vpi(vport))
scsi_host_put(shost);
} else {
scsi_host_put(shost);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.