lpfc_mem.c revision 51ef4c26891a734bc8416b639ad460a8162926bc
1dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>/******************************************************************* 2dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> * This file is part of the Emulex Linux Device Driver for * 3c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * Fibre Channel Host Bus Adapters. * 42e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart * Copyright (C) 2004-2006 Emulex. All rights reserved. * 5c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * EMULEX and SLI are trademarks of Emulex. * 6dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> * www.emulex.com * 7c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * Portions Copyright (C) 2004-2005 Christoph Hellwig * 8dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> * * 9dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> * This program is free software; you can redistribute it and/or * 10c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * modify it under the terms of version 2 of the GNU General * 11c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * Public License as published by the Free Software Foundation. * 12c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * This program is distributed in the hope that it will be useful. * 13c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * 14c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * 15c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * 16c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * 17c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * TO BE LEGALLY INVALID. See the GNU General Public License for * 18c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * more details, a copy of which can be found in the file COPYING * 19c44ce1737438d20ac58e808897e3f8eb015c66d3James.Smart@Emulex.Com * included with this package. * 20dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> *******************************************************************/ 21dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 22dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include <linux/mempool.h> 23dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include <linux/pci.h> 24dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include <linux/interrupt.h> 25dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 26f888ba3ce77c66bece3d804caf7d559838209a4aJames.Smart@Emulex.Com#include <scsi/scsi_device.h> 27f888ba3ce77c66bece3d804caf7d559838209a4aJames.Smart@Emulex.Com#include <scsi/scsi_transport_fc.h> 28f888ba3ce77c66bece3d804caf7d559838209a4aJames.Smart@Emulex.Com 29918865230e55b1fece2d8edec39d46c00626590bJames.Smart@Emulex.Com#include <scsi/scsi.h> 30918865230e55b1fece2d8edec39d46c00626590bJames.Smart@Emulex.Com 31dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include "lpfc_hw.h" 32dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include "lpfc_sli.h" 33dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include "lpfc_disc.h" 34dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include "lpfc_scsi.h" 35dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include "lpfc.h" 36dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#include "lpfc_crtn.h" 37dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 38dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#define LPFC_MBUF_POOL_SIZE 64 /* max elements in MBUF safety pool */ 39dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>#define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */ 40dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 412e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart 422e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart 43dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>int 44dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>lpfc_mem_alloc(struct lpfc_hba * phba) 45dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>{ 46dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool; 4792d7f7b0cde3ad2260e7462b40867b57efd49851James Smart int longs; 48dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> int i; 49dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 50dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> phba->lpfc_scsi_dma_buf_pool = pci_pool_create("lpfc_scsi_dma_buf_pool", 51dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> phba->pcidev, phba->cfg_sg_dma_buf_size, 8, 0); 52dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (!phba->lpfc_scsi_dma_buf_pool) 53dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> goto fail; 54dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 55dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> phba->lpfc_mbuf_pool = pci_pool_create("lpfc_mbuf_pool", phba->pcidev, 56dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> LPFC_BPL_SIZE, 8,0); 57dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (!phba->lpfc_mbuf_pool) 58dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> goto fail_free_dma_buf_pool; 59dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 60dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) * 61dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> LPFC_MBUF_POOL_SIZE, GFP_KERNEL); 62a96e0c7798057dd8055d0263c076fed975c10237Mariusz Kozlowski if (!pool->elements) 63a96e0c7798057dd8055d0263c076fed975c10237Mariusz Kozlowski goto fail_free_lpfc_mbuf_pool; 64a96e0c7798057dd8055d0263c076fed975c10237Mariusz Kozlowski 65dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->max_count = 0; 66dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->current_count = 0; 67dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) { 68dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->elements[i].virt = pci_pool_alloc(phba->lpfc_mbuf_pool, 69dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> GFP_KERNEL, &pool->elements[i].phys); 70dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (!pool->elements[i].virt) 71dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> goto fail_free_mbuf_pool; 72dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->max_count++; 73dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->current_count++; 74dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> } 75dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 760eaae62abaa1ad1f231932b6cdd9fb1b91df6651Matthew Dobson phba->mbox_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE, 770eaae62abaa1ad1f231932b6cdd9fb1b91df6651Matthew Dobson sizeof(LPFC_MBOXQ_t)); 78dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (!phba->mbox_mem_pool) 79dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> goto fail_free_mbuf_pool; 80dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 810eaae62abaa1ad1f231932b6cdd9fb1b91df6651Matthew Dobson phba->nlp_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE, 820eaae62abaa1ad1f231932b6cdd9fb1b91df6651Matthew Dobson sizeof(struct lpfc_nodelist)); 83dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (!phba->nlp_mem_pool) 84dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> goto fail_free_mbox_pool; 85dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 86ed957684294618602b48f1950b0c9bbcb036583fJames Smart phba->lpfc_hbq_pool = pci_pool_create("lpfc_hbq_pool",phba->pcidev, 87ed957684294618602b48f1950b0c9bbcb036583fJames Smart LPFC_BPL_SIZE, 8, 0); 88ed957684294618602b48f1950b0c9bbcb036583fJames Smart if (!phba->lpfc_hbq_pool) 89ed957684294618602b48f1950b0c9bbcb036583fJames Smart goto fail_free_nlp_mem_pool; 90ed957684294618602b48f1950b0c9bbcb036583fJames Smart 91858c9f6c19c6f9bf86cbbc64ce0d17c61d6131b8James Smart /* vpi zero is reserved for the physical port so add 1 to max */ 92858c9f6c19c6f9bf86cbbc64ce0d17c61d6131b8James Smart longs = ((phba->max_vpi + 1) + BITS_PER_LONG - 1) / BITS_PER_LONG; 9392d7f7b0cde3ad2260e7462b40867b57efd49851James Smart phba->vpi_bmask = kzalloc(longs * sizeof(unsigned long), GFP_KERNEL); 9492d7f7b0cde3ad2260e7462b40867b57efd49851James Smart if (!phba->vpi_bmask) 9592d7f7b0cde3ad2260e7462b40867b57efd49851James Smart goto fail_free_hbq_pool; 9692d7f7b0cde3ad2260e7462b40867b57efd49851James Smart 97dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> return 0; 98dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 9992d7f7b0cde3ad2260e7462b40867b57efd49851James Smart fail_free_hbq_pool: 10092d7f7b0cde3ad2260e7462b40867b57efd49851James Smart lpfc_sli_hbqbuf_free_all(phba); 101ed957684294618602b48f1950b0c9bbcb036583fJames Smart fail_free_nlp_mem_pool: 102ed957684294618602b48f1950b0c9bbcb036583fJames Smart mempool_destroy(phba->nlp_mem_pool); 103ed957684294618602b48f1950b0c9bbcb036583fJames Smart phba->nlp_mem_pool = NULL; 104dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> fail_free_mbox_pool: 105dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> mempool_destroy(phba->mbox_mem_pool); 1062e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart phba->mbox_mem_pool = NULL; 107dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> fail_free_mbuf_pool: 108a96e0c7798057dd8055d0263c076fed975c10237Mariusz Kozlowski while (i--) 109dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt, 110dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->elements[i].phys); 111dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> kfree(pool->elements); 112a96e0c7798057dd8055d0263c076fed975c10237Mariusz Kozlowski fail_free_lpfc_mbuf_pool: 113dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pci_pool_destroy(phba->lpfc_mbuf_pool); 1142e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart phba->lpfc_mbuf_pool = NULL; 115dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> fail_free_dma_buf_pool: 116dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool); 1172e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart phba->lpfc_scsi_dma_buf_pool = NULL; 118dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> fail: 119dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> return -ENOMEM; 120dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>} 121dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 122dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>void 123dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>lpfc_mem_free(struct lpfc_hba * phba) 124dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>{ 125dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> struct lpfc_sli *psli = &phba->sli; 126dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool; 127dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> LPFC_MBOXQ_t *mbox, *next_mbox; 128dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> struct lpfc_dmabuf *mp; 129dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> int i; 130dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 13192d7f7b0cde3ad2260e7462b40867b57efd49851James Smart kfree(phba->vpi_bmask); 132ed957684294618602b48f1950b0c9bbcb036583fJames Smart lpfc_sli_hbqbuf_free_all(phba); 133ed957684294618602b48f1950b0c9bbcb036583fJames Smart 134dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) { 135dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> mp = (struct lpfc_dmabuf *) (mbox->context1); 136dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (mp) { 137dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> lpfc_mbuf_free(phba, mp->virt, mp->phys); 138dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> kfree(mp); 139dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> } 140dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> list_del(&mbox->list); 141dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> mempool_free(mbox, phba->mbox_mem_pool); 142dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> } 14392d7f7b0cde3ad2260e7462b40867b57efd49851James Smart list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq_cmpl, list) { 14492d7f7b0cde3ad2260e7462b40867b57efd49851James Smart mp = (struct lpfc_dmabuf *) (mbox->context1); 14592d7f7b0cde3ad2260e7462b40867b57efd49851James Smart if (mp) { 14692d7f7b0cde3ad2260e7462b40867b57efd49851James Smart lpfc_mbuf_free(phba, mp->virt, mp->phys); 14792d7f7b0cde3ad2260e7462b40867b57efd49851James Smart kfree(mp); 14892d7f7b0cde3ad2260e7462b40867b57efd49851James Smart } 14992d7f7b0cde3ad2260e7462b40867b57efd49851James Smart list_del(&mbox->list); 15092d7f7b0cde3ad2260e7462b40867b57efd49851James Smart mempool_free(mbox, phba->mbox_mem_pool); 15192d7f7b0cde3ad2260e7462b40867b57efd49851James Smart } 152dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 153dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 154dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (psli->mbox_active) { 155dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> mbox = psli->mbox_active; 156dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> mp = (struct lpfc_dmabuf *) (mbox->context1); 157dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (mp) { 158dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> lpfc_mbuf_free(phba, mp->virt, mp->phys); 159dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> kfree(mp); 160dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> } 161dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> mempool_free(mbox, phba->mbox_mem_pool); 162dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> psli->mbox_active = NULL; 163dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> } 164dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 165dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> for (i = 0; i < pool->current_count; i++) 166dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt, 167dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->elements[i].phys); 168dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> kfree(pool->elements); 1692e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart 170ed957684294618602b48f1950b0c9bbcb036583fJames Smart pci_pool_destroy(phba->lpfc_hbq_pool); 171dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> mempool_destroy(phba->nlp_mem_pool); 172dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> mempool_destroy(phba->mbox_mem_pool); 173dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 174dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pci_pool_destroy(phba->lpfc_scsi_dma_buf_pool); 175dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pci_pool_destroy(phba->lpfc_mbuf_pool); 1769f49d3b05f092b89e774be20c654ceb0c64a7d19James Smart 177ed957684294618602b48f1950b0c9bbcb036583fJames Smart phba->lpfc_hbq_pool = NULL; 1782e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart phba->nlp_mem_pool = NULL; 1792e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart phba->mbox_mem_pool = NULL; 1802e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart phba->lpfc_scsi_dma_buf_pool = NULL; 1812e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart phba->lpfc_mbuf_pool = NULL; 1822e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart 18392d7f7b0cde3ad2260e7462b40867b57efd49851James Smart /* Free the iocb lookup array */ 1849f49d3b05f092b89e774be20c654ceb0c64a7d19James Smart kfree(psli->iocbq_lookup); 1859f49d3b05f092b89e774be20c654ceb0c64a7d19James Smart psli->iocbq_lookup = NULL; 1869f49d3b05f092b89e774be20c654ceb0c64a7d19James Smart 187dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>} 188dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 189dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>void * 190dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle) 191dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>{ 192dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool; 1932e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart unsigned long iflags; 194dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> void *ret; 195dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 196dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> ret = pci_pool_alloc(phba->lpfc_mbuf_pool, GFP_KERNEL, handle); 197dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 1982e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart spin_lock_irqsave(&phba->hbalock, iflags); 19992d7f7b0cde3ad2260e7462b40867b57efd49851James Smart if (!ret && (mem_flags & MEM_PRI) && pool->current_count) { 200dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->current_count--; 201dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> ret = pool->elements[pool->current_count].virt; 202dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> *handle = pool->elements[pool->current_count].phys; 203dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> } 2042e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart spin_unlock_irqrestore(&phba->hbalock, iflags); 205dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> return ret; 206dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>} 207dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 208dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>void 2092e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart__lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma) 210dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>{ 211dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool; 212dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> 213dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> if (pool->current_count < pool->max_count) { 214dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->elements[pool->current_count].virt = virt; 215dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->elements[pool->current_count].phys = dma; 216dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pool->current_count++; 217dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> } else { 218dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> pci_pool_free(phba->lpfc_mbuf_pool, virt, dma); 219dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> } 220dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com> return; 221dea3101e0a5c897d2c9351a7444e139db9f40247<jejb@titanic.il.steeleye.com>} 2222e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart 2232e0fef85e098f6794956b8b80b111179fbb4cbb7James Smartvoid 2242e0fef85e098f6794956b8b80b111179fbb4cbb7James Smartlpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma) 2252e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart{ 2262e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart unsigned long iflags; 2272e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart 2282e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart spin_lock_irqsave(&phba->hbalock, iflags); 2292e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart __lpfc_mbuf_free(phba, virt, dma); 2302e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart spin_unlock_irqrestore(&phba->hbalock, iflags); 2312e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart return; 2322e0fef85e098f6794956b8b80b111179fbb4cbb7James Smart} 233ed957684294618602b48f1950b0c9bbcb036583fJames Smart 23451ef4c26891a734bc8416b639ad460a8162926bcJames Smartstruct hbq_dmabuf * 23551ef4c26891a734bc8416b639ad460a8162926bcJames Smartlpfc_els_hbq_alloc(struct lpfc_hba *phba) 236ed957684294618602b48f1950b0c9bbcb036583fJames Smart{ 23751ef4c26891a734bc8416b639ad460a8162926bcJames Smart struct hbq_dmabuf *hbqbp; 23851ef4c26891a734bc8416b639ad460a8162926bcJames Smart 23951ef4c26891a734bc8416b639ad460a8162926bcJames Smart hbqbp = kmalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL); 24051ef4c26891a734bc8416b639ad460a8162926bcJames Smart if (!hbqbp) 24151ef4c26891a734bc8416b639ad460a8162926bcJames Smart return NULL; 24251ef4c26891a734bc8416b639ad460a8162926bcJames Smart 24351ef4c26891a734bc8416b639ad460a8162926bcJames Smart hbqbp->dbuf.virt = pci_pool_alloc(phba->lpfc_hbq_pool, GFP_KERNEL, 24451ef4c26891a734bc8416b639ad460a8162926bcJames Smart &hbqbp->dbuf.phys); 24551ef4c26891a734bc8416b639ad460a8162926bcJames Smart if (!hbqbp->dbuf.virt) { 24651ef4c26891a734bc8416b639ad460a8162926bcJames Smart kfree(hbqbp); 24751ef4c26891a734bc8416b639ad460a8162926bcJames Smart return NULL; 24851ef4c26891a734bc8416b639ad460a8162926bcJames Smart } 24951ef4c26891a734bc8416b639ad460a8162926bcJames Smart hbqbp->size = LPFC_BPL_SIZE; 25051ef4c26891a734bc8416b639ad460a8162926bcJames Smart return hbqbp; 251ed957684294618602b48f1950b0c9bbcb036583fJames Smart} 252ed957684294618602b48f1950b0c9bbcb036583fJames Smart 253ed957684294618602b48f1950b0c9bbcb036583fJames Smartvoid 25451ef4c26891a734bc8416b639ad460a8162926bcJames Smartlpfc_els_hbq_free(struct lpfc_hba *phba, struct hbq_dmabuf *hbqbp) 255ed957684294618602b48f1950b0c9bbcb036583fJames Smart{ 25651ef4c26891a734bc8416b639ad460a8162926bcJames Smart pci_pool_free(phba->lpfc_hbq_pool, hbqbp->dbuf.virt, hbqbp->dbuf.phys); 25751ef4c26891a734bc8416b639ad460a8162926bcJames Smart kfree(hbqbp); 258ed957684294618602b48f1950b0c9bbcb036583fJames Smart return; 259ed957684294618602b48f1950b0c9bbcb036583fJames Smart} 260ed957684294618602b48f1950b0c9bbcb036583fJames Smart 26151ef4c26891a734bc8416b639ad460a8162926bcJames Smart/* This is ONLY called for the LPFC_ELS_HBQ */ 26292d7f7b0cde3ad2260e7462b40867b57efd49851James Smartvoid 26392d7f7b0cde3ad2260e7462b40867b57efd49851James Smartlpfc_in_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp) 26492d7f7b0cde3ad2260e7462b40867b57efd49851James Smart{ 26592d7f7b0cde3ad2260e7462b40867b57efd49851James Smart struct hbq_dmabuf *hbq_entry; 26692d7f7b0cde3ad2260e7462b40867b57efd49851James Smart 26792d7f7b0cde3ad2260e7462b40867b57efd49851James Smart if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 26892d7f7b0cde3ad2260e7462b40867b57efd49851James Smart hbq_entry = container_of(mp, struct hbq_dmabuf, dbuf); 26992d7f7b0cde3ad2260e7462b40867b57efd49851James Smart if (hbq_entry->tag == -1) { 27051ef4c26891a734bc8416b639ad460a8162926bcJames Smart (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer) 27151ef4c26891a734bc8416b639ad460a8162926bcJames Smart (phba, hbq_entry); 27292d7f7b0cde3ad2260e7462b40867b57efd49851James Smart } else { 27392d7f7b0cde3ad2260e7462b40867b57efd49851James Smart lpfc_sli_free_hbq(phba, hbq_entry); 27492d7f7b0cde3ad2260e7462b40867b57efd49851James Smart } 27592d7f7b0cde3ad2260e7462b40867b57efd49851James Smart } else { 27692d7f7b0cde3ad2260e7462b40867b57efd49851James Smart lpfc_mbuf_free(phba, mp->virt, mp->phys); 27792d7f7b0cde3ad2260e7462b40867b57efd49851James Smart kfree(mp); 27892d7f7b0cde3ad2260e7462b40867b57efd49851James Smart } 27992d7f7b0cde3ad2260e7462b40867b57efd49851James Smart return; 28092d7f7b0cde3ad2260e7462b40867b57efd49851James Smart} 28192d7f7b0cde3ad2260e7462b40867b57efd49851James Smart 282