diff options
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_mem.c')
-rw-r--r-- | drivers/scsi/lpfc/lpfc_mem.c | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/drivers/scsi/lpfc/lpfc_mem.c b/drivers/scsi/lpfc/lpfc_mem.c index 89cbeba06a..2697da3248 100644 --- a/drivers/scsi/lpfc/lpfc_mem.c +++ b/drivers/scsi/lpfc/lpfc_mem.c @@ -1,7 +1,7 @@ /******************************************************************* * This file is part of the Emulex Linux Device Driver for * * Fibre Channel Host Bus Adapters. * - * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term * + * Copyright (C) 2017-2023 Broadcom. All Rights Reserved. The term * * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. * * Copyright (C) 2004-2014 Emulex. All rights reserved. * * EMULEX and SLI are trademarks of Emulex. * @@ -48,6 +48,29 @@ #define LPFC_RRQ_POOL_SIZE 256 /* max elements in non-DMA pool */ #define LPFC_MBX_POOL_SIZE 256 /* max elements in MBX non-DMA pool */ +/* lpfc_mbox_free_sli_mbox + * + * @phba: HBA to free memory for + * @mbox: mailbox command to free + * + * This routine detects the mbox type and calls the correct + * free routine to fully release all associated memory. + */ +static void +lpfc_mem_free_sli_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) +{ + /* Detect if the caller's mbox is an SLI4_CONFIG type. If so, this + * mailbox type requires a different cleanup routine. Otherwise, the + * mailbox is just an mbuf and mem_pool release. + */ + if (phba->sli_rev == LPFC_SLI_REV4 && + bf_get(lpfc_mqe_command, &mbox->u.mqe) == MBX_SLI4_CONFIG) { + lpfc_sli4_mbox_cmd_free(phba, mbox); + } else { + lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); + } +} + int lpfc_mem_alloc_active_rrq_pool_s4(struct lpfc_hba *phba) { size_t bytes; @@ -288,27 +311,16 @@ lpfc_mem_free_all(struct lpfc_hba *phba) { struct lpfc_sli *psli = &phba->sli; LPFC_MBOXQ_t *mbox, *next_mbox; - struct lpfc_dmabuf *mp; /* Free memory used in mailbox queue back to mailbox memory pool */ list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) { - mp = (struct lpfc_dmabuf *)(mbox->ctx_buf); - if (mp) { - lpfc_mbuf_free(phba, mp->virt, mp->phys); - kfree(mp); - } list_del(&mbox->list); - mempool_free(mbox, phba->mbox_mem_pool); + lpfc_mem_free_sli_mbox(phba, mbox); } /* Free memory used in mailbox cmpl list back to mailbox memory pool */ list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq_cmpl, list) { - mp = (struct lpfc_dmabuf *)(mbox->ctx_buf); - if (mp) { - lpfc_mbuf_free(phba, mp->virt, mp->phys); - kfree(mp); - } list_del(&mbox->list); - mempool_free(mbox, phba->mbox_mem_pool); + lpfc_mem_free_sli_mbox(phba, mbox); } /* Free the active mailbox command back to the mailbox memory pool */ spin_lock_irq(&phba->hbalock); @@ -316,12 +328,7 @@ lpfc_mem_free_all(struct lpfc_hba *phba) spin_unlock_irq(&phba->hbalock); if (psli->mbox_active) { mbox = psli->mbox_active; - mp = (struct lpfc_dmabuf *)(mbox->ctx_buf); - if (mp) { - lpfc_mbuf_free(phba, mp->virt, mp->phys); - kfree(mp); - } - mempool_free(mbox, phba->mbox_mem_pool); + lpfc_mem_free_sli_mbox(phba, mbox); psli->mbox_active = NULL; } |