/* Return codes 0 - success. Any other value - error.  */
int lpfc_hba_down_prep(struct lpfc_hba *phba)
/* Return codes 0 - success. Any other value - error.  */
int lpfc_hba_down_prep(struct lpfc_hba *phba)
{
	struct lpfc_vport **vports;
	int i;
	if (phba->sli_rev <= LPFC_SLI_REV3) {
		writel(0, phba->HCregaddr);
		readl(phba->HCregaddr);
	}
	if (phba->pport->load_flag & FC_UNLOADING)
		lpfc_cleanup_discovery_resources(phba->pport);
	else {
		vports = lpfc_create_vport_work_array(phba);
		if (vports != NULL)
			for (i = 0; i <= phba->max_vports &&
				vports[i] != NULL; i++)
				lpfc_cleanup_discovery_resources(vports[i]);
		lpfc_destroy_vport_work_array(phba, vports);
	}
	return 0;
}