|
48 | 48 | #define LPFC_RRQ_POOL_SIZE 256 /* max elements in non-DMA pool */ |
49 | 49 | #define LPFC_MBX_POOL_SIZE 256 /* max elements in MBX non-DMA pool */ |
50 | 50 |
|
| 51 | +/* lpfc_mbox_free_sli_mbox |
| 52 | + * |
| 53 | + * @phba: HBA to free memory for |
| 54 | + * @mbox: mailbox command to free |
| 55 | + * |
| 56 | + * This routine detects the mbox type and calls the correct |
| 57 | + * free routine to fully release all associated memory. |
| 58 | + */ |
| 59 | +static void |
| 60 | +lpfc_mem_free_sli_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 61 | +{ |
| 62 | + /* Detect if the caller's mbox is an SLI4_CONFIG type. If so, this |
| 63 | + * mailbox type requires a different cleanup routine. Otherwise, the |
| 64 | + * mailbox is just an mbuf and mem_pool release. |
| 65 | + */ |
| 66 | + if (phba->sli_rev == LPFC_SLI_REV4 && |
| 67 | + bf_get(lpfc_mqe_command, &mbox->u.mqe) == MBX_SLI4_CONFIG) { |
| 68 | + lpfc_sli4_mbox_cmd_free(phba, mbox); |
| 69 | + } else { |
| 70 | + lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED); |
| 71 | + } |
| 72 | +} |
| 73 | + |
51 | 74 | int |
52 | 75 | lpfc_mem_alloc_active_rrq_pool_s4(struct lpfc_hba *phba) { |
53 | 76 | size_t bytes; |
@@ -288,40 +311,24 @@ lpfc_mem_free_all(struct lpfc_hba *phba) |
288 | 311 | { |
289 | 312 | struct lpfc_sli *psli = &phba->sli; |
290 | 313 | LPFC_MBOXQ_t *mbox, *next_mbox; |
291 | | - struct lpfc_dmabuf *mp; |
292 | 314 |
|
293 | 315 | /* Free memory used in mailbox queue back to mailbox memory pool */ |
294 | 316 | list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) { |
295 | | - mp = (struct lpfc_dmabuf *)(mbox->ctx_buf); |
296 | | - if (mp) { |
297 | | - lpfc_mbuf_free(phba, mp->virt, mp->phys); |
298 | | - kfree(mp); |
299 | | - } |
300 | 317 | list_del(&mbox->list); |
301 | | - mempool_free(mbox, phba->mbox_mem_pool); |
| 318 | + lpfc_mem_free_sli_mbox(phba, mbox); |
302 | 319 | } |
303 | 320 | /* Free memory used in mailbox cmpl list back to mailbox memory pool */ |
304 | 321 | list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq_cmpl, list) { |
305 | | - mp = (struct lpfc_dmabuf *)(mbox->ctx_buf); |
306 | | - if (mp) { |
307 | | - lpfc_mbuf_free(phba, mp->virt, mp->phys); |
308 | | - kfree(mp); |
309 | | - } |
310 | 322 | list_del(&mbox->list); |
311 | | - mempool_free(mbox, phba->mbox_mem_pool); |
| 323 | + lpfc_mem_free_sli_mbox(phba, mbox); |
312 | 324 | } |
313 | 325 | /* Free the active mailbox command back to the mailbox memory pool */ |
314 | 326 | spin_lock_irq(&phba->hbalock); |
315 | 327 | psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; |
316 | 328 | spin_unlock_irq(&phba->hbalock); |
317 | 329 | if (psli->mbox_active) { |
318 | 330 | mbox = psli->mbox_active; |
319 | | - mp = (struct lpfc_dmabuf *)(mbox->ctx_buf); |
320 | | - if (mp) { |
321 | | - lpfc_mbuf_free(phba, mp->virt, mp->phys); |
322 | | - kfree(mp); |
323 | | - } |
324 | | - mempool_free(mbox, phba->mbox_mem_pool); |
| 331 | + lpfc_mem_free_sli_mbox(phba, mbox); |
325 | 332 | psli->mbox_active = NULL; |
326 | 333 | } |
327 | 334 |
|
|
0 commit comments