Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*******************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * This file is part of the Emulex Linux Device Driver for         *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Fibre Channel Host Bus Adapters.                                *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.     *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2004-2014 Emulex.  All rights reserved.           *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * EMULEX and SLI are trademarks of Emulex.                        *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * www.broadcom.com                                                *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *                                                                 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * This program is free software; you can redistribute it and/or   *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * modify it under the terms of version 2 of the GNU General       *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * Public License as published by the Free Software Foundation.    *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * This program is distributed in the hope that it will be useful. *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * more details, a copy of which can be found in the file COPYING  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * included with this package.                                     *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *******************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/mempool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <scsi/scsi_transport_fc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <scsi/fc/fc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include "lpfc_hw4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "lpfc_hw.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include "lpfc_sli.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include "lpfc_sli4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include "lpfc_nl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "lpfc_disc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include "lpfc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include "lpfc_scsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include "lpfc_crtn.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include "lpfc_logmsg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define LPFC_MBUF_POOL_SIZE     64      /* max elements in MBUF safety pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define LPFC_MEM_POOL_SIZE      64      /* max elem in non-DMA safety pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define LPFC_DEVICE_DATA_POOL_SIZE 64   /* max elements in device data pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define LPFC_RRQ_POOL_SIZE	256	/* max elements in non-DMA  pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define LPFC_MBX_POOL_SIZE	256	/* max elements in MBX non-DMA pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) lpfc_mem_alloc_active_rrq_pool_s4(struct lpfc_hba *phba) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	size_t bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (max_xri <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	bytes = ((BITS_PER_LONG - 1 + max_xri) / BITS_PER_LONG) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		  sizeof(unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	phba->cfg_rrq_xri_bitmap_sz = bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	phba->active_rrq_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 							    bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (!phba->active_rrq_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * lpfc_mem_alloc - create and allocate all PCI and memory pools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  * @phba: HBA to allocate pools for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * @align: alignment requirement for blocks; must be a power of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Description: Creates and allocates PCI pools lpfc_mbuf_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * lpfc_hrb_pool.  Creates and allocates kmalloc-backed mempools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * for LPFC_MBOXQ_t and lpfc_nodelist.  Also allocates the VPI bitmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Notes: Not interrupt-safe.  Must be called with no locks held.  If any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * allocation fails, frees all successfully allocated memory before returning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  *   0 on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  *   -ENOMEM on failure (if any memory allocations fail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) lpfc_mem_alloc(struct lpfc_hba *phba, int align)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	phba->lpfc_mbuf_pool = dma_pool_create("lpfc_mbuf_pool", &phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 							LPFC_BPL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 							align, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (!phba->lpfc_mbuf_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	pool->elements = kmalloc_array(LPFC_MBUF_POOL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				       sizeof(struct lpfc_dmabuf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				       GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (!pool->elements)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		goto fail_free_lpfc_mbuf_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	pool->max_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	pool->current_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		pool->elements[i].virt = dma_pool_alloc(phba->lpfc_mbuf_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				       GFP_KERNEL, &pool->elements[i].phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		if (!pool->elements[i].virt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			goto fail_free_mbuf_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		pool->max_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		pool->current_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	phba->mbox_mem_pool = mempool_create_kmalloc_pool(LPFC_MBX_POOL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 							  sizeof(LPFC_MBOXQ_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (!phba->mbox_mem_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		goto fail_free_mbuf_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	phba->nlp_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 						sizeof(struct lpfc_nodelist));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (!phba->nlp_mem_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		goto fail_free_mbox_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (phba->sli_rev == LPFC_SLI_REV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		phba->rrq_pool =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			mempool_create_kmalloc_pool(LPFC_RRQ_POOL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 						sizeof(struct lpfc_node_rrq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (!phba->rrq_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			goto fail_free_nlp_mem_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		phba->lpfc_hrb_pool = dma_pool_create("lpfc_hrb_pool",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 					      &phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 					      LPFC_HDR_BUF_SIZE, align, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		if (!phba->lpfc_hrb_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			goto fail_free_rrq_mem_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		phba->lpfc_drb_pool = dma_pool_create("lpfc_drb_pool",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 					      &phba->pcidev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 					      LPFC_DATA_BUF_SIZE, align, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (!phba->lpfc_drb_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			goto fail_free_hrb_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		phba->lpfc_hbq_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		phba->lpfc_hbq_pool = dma_pool_create("lpfc_hbq_pool",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			&phba->pcidev->dev, LPFC_BPL_SIZE, align, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if (!phba->lpfc_hbq_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			goto fail_free_nlp_mem_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		phba->lpfc_hrb_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		phba->lpfc_drb_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (phba->cfg_EnableXLane) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		phba->device_data_mem_pool = mempool_create_kmalloc_pool(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					LPFC_DEVICE_DATA_POOL_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 					sizeof(struct lpfc_device_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (!phba->device_data_mem_pool)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			goto fail_free_drb_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		phba->device_data_mem_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) fail_free_drb_pool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	dma_pool_destroy(phba->lpfc_drb_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	phba->lpfc_drb_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  fail_free_hrb_pool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	dma_pool_destroy(phba->lpfc_hrb_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	phba->lpfc_hrb_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  fail_free_rrq_mem_pool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	mempool_destroy(phba->rrq_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	phba->rrq_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  fail_free_nlp_mem_pool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	mempool_destroy(phba->nlp_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	phba->nlp_mem_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  fail_free_mbox_pool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	mempool_destroy(phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	phba->mbox_mem_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  fail_free_mbuf_pool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	while (i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		dma_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 						 pool->elements[i].phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	kfree(pool->elements);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  fail_free_lpfc_mbuf_pool:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	dma_pool_destroy(phba->lpfc_mbuf_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	phba->lpfc_mbuf_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) lpfc_nvmet_mem_alloc(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	phba->lpfc_nvmet_drb_pool =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		dma_pool_create("lpfc_nvmet_drb_pool",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 				&phba->pcidev->dev, LPFC_NVMET_DATA_BUF_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 				SGL_ALIGN_SZ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!phba->lpfc_nvmet_drb_pool) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 				"6024 Can't enable NVME Target - no memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * lpfc_mem_free - Frees memory allocated by lpfc_mem_alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * @phba: HBA to free memory for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * Description: Free the memory allocated by lpfc_mem_alloc routine. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * routine is a the counterpart of lpfc_mem_alloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) lpfc_mem_free(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct lpfc_device_data *device_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	/* Free HBQ pools */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	lpfc_sli_hbqbuf_free_all(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	dma_pool_destroy(phba->lpfc_nvmet_drb_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	phba->lpfc_nvmet_drb_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	dma_pool_destroy(phba->lpfc_drb_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	phba->lpfc_drb_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	dma_pool_destroy(phba->lpfc_hrb_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	phba->lpfc_hrb_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	dma_pool_destroy(phba->lpfc_hbq_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	phba->lpfc_hbq_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	mempool_destroy(phba->rrq_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	phba->rrq_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	/* Free NLP memory pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	mempool_destroy(phba->nlp_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	phba->nlp_mem_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (phba->sli_rev == LPFC_SLI_REV4 && phba->active_rrq_pool) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		mempool_destroy(phba->active_rrq_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		phba->active_rrq_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* Free mbox memory pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	mempool_destroy(phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	phba->mbox_mem_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	/* Free MBUF memory pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	for (i = 0; i < pool->current_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		dma_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			      pool->elements[i].phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	kfree(pool->elements);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	dma_pool_destroy(phba->lpfc_mbuf_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	phba->lpfc_mbuf_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	/* Free Device Data memory pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	if (phba->device_data_mem_pool) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		/* Ensure all objects have been returned to the pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		while (!list_empty(&phba->luns)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			device_data = list_first_entry(&phba->luns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 						       struct lpfc_device_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 						       listentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			list_del(&device_data->listentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			mempool_free(device_data, phba->device_data_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		mempool_destroy(phba->device_data_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	phba->device_data_mem_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  * lpfc_mem_free_all - Frees all PCI and driver memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * @phba: HBA to free memory for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * Description: Free memory from PCI and driver memory pools and also those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  * used : lpfc_sg_dma_buf_pool, lpfc_mbuf_pool, lpfc_hrb_pool. Frees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * kmalloc-backed mempools for LPFC_MBOXQ_t and lpfc_nodelist. Also frees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * the VPI bitmask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) lpfc_mem_free_all(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	struct lpfc_sli *psli = &phba->sli;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	LPFC_MBOXQ_t *mbox, *next_mbox;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	struct lpfc_dmabuf   *mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	/* Free memory used in mailbox queue back to mailbox memory pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		if (mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		list_del(&mbox->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	/* Free memory used in mailbox cmpl list back to mailbox memory pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq_cmpl, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		if (mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 			kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		list_del(&mbox->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	/* Free the active mailbox command back to the mailbox memory pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	spin_lock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	spin_unlock_irq(&phba->hbalock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (psli->mbox_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		mbox = psli->mbox_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		if (mp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 			lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 			kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		mempool_free(mbox, phba->mbox_mem_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		psli->mbox_active = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	/* Free and destroy all the allocated memory pools */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	lpfc_mem_free(phba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	/* Free DMA buffer memory pool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	phba->lpfc_sg_dma_buf_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	phba->lpfc_cmd_rsp_buf_pool = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	/* Free the iocb lookup array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	kfree(psli->iocbq_lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	psli->iocbq_lookup = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  * lpfc_mbuf_alloc - Allocate an mbuf from the lpfc_mbuf_pool PCI pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  * @phba: HBA which owns the pool to allocate from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  * @mem_flags: indicates if this is a priority (MEM_PRI) allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * @handle: used to return the DMA-mapped address of the mbuf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  * Description: Allocates a DMA-mapped buffer from the lpfc_mbuf_pool PCI pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * Allocates from generic dma_pool_alloc function first and if that fails and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  * mem_flags has MEM_PRI set (the only defined flag), returns an mbuf from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  * HBA's pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * Notes: Not interrupt-safe.  Must be called with no locks held.  Takes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  * phba->hbalock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  *   pointer to the allocated mbuf on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  *   NULL on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	void *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	ret = dma_pool_alloc(phba->lpfc_mbuf_pool, GFP_KERNEL, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (!ret && (mem_flags & MEM_PRI) && pool->current_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		pool->current_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		ret = pool->elements[pool->current_count].virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		*handle = pool->elements[pool->current_count].phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  * __lpfc_mbuf_free - Free an mbuf from the lpfc_mbuf_pool PCI pool (locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  * @phba: HBA which owns the pool to return to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)  * @virt: mbuf to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  * it is below its max_count, frees the mbuf otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  * Notes: Must be called with phba->hbalock held to synchronize access to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  * lpfc_mbuf_safety_pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) __lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	if (pool->current_count < pool->max_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		pool->elements[pool->current_count].virt = virt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		pool->elements[pool->current_count].phys = dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		pool->current_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		dma_pool_free(phba->lpfc_mbuf_pool, virt, dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  * lpfc_mbuf_free - Free an mbuf from the lpfc_mbuf_pool PCI pool (unlocked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  * @phba: HBA which owns the pool to return to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  * @virt: mbuf to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)  * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  * it is below its max_count, frees the mbuf otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  * Notes: Takes phba->hbalock.  Can be called with or without other locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	unsigned long iflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	spin_lock_irqsave(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	__lpfc_mbuf_free(phba, virt, dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	spin_unlock_irqrestore(&phba->hbalock, iflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  * lpfc_nvmet_buf_alloc - Allocate an nvmet_buf from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  * lpfc_sg_dma_buf_pool PCI pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  * @phba: HBA which owns the pool to allocate from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  * @mem_flags: indicates if this is a priority (MEM_PRI) allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * @handle: used to return the DMA-mapped address of the nvmet_buf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * Description: Allocates a DMA-mapped buffer from the lpfc_sg_dma_buf_pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * PCI pool.  Allocates from generic dma_pool_alloc function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  *   pointer to the allocated nvmet_buf on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  *   NULL on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) void *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) lpfc_nvmet_buf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	void *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	ret = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, GFP_KERNEL, handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  * lpfc_nvmet_buf_free - Free an nvmet_buf from the lpfc_sg_dma_buf_pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  * PCI pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  * @phba: HBA which owns the pool to return to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  * @virt: nvmet_buf to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)  * @dma: the DMA-mapped address of the lpfc_sg_dma_buf_pool to be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) lpfc_nvmet_buf_free(struct lpfc_hba *phba, void *virt, dma_addr_t dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	dma_pool_free(phba->lpfc_sg_dma_buf_pool, virt, dma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)  * lpfc_els_hbq_alloc - Allocate an HBQ buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)  * @phba: HBA to allocate HBQ buffer for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  * Description: Allocates a DMA-mapped HBQ buffer from the lpfc_hrb_pool PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  * pool along a non-DMA-mapped container for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  * Notes: Not interrupt-safe.  Must be called with no locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  *   pointer to HBQ on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  *   NULL on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct hbq_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) lpfc_els_hbq_alloc(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	struct hbq_dmabuf *hbqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	hbqbp = kzalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	if (!hbqbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	hbqbp->dbuf.virt = dma_pool_alloc(phba->lpfc_hbq_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 					  &hbqbp->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	if (!hbqbp->dbuf.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		kfree(hbqbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	hbqbp->total_size = LPFC_BPL_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	return hbqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  * lpfc_els_hbq_free - Frees an HBQ buffer allocated with lpfc_els_hbq_alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  * @phba: HBA buffer was allocated for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  * @hbqbp: HBQ container returned by lpfc_els_hbq_alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)  * Description: Frees both the container and the DMA-mapped buffer returned by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)  * lpfc_els_hbq_alloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)  * Notes: Can be called with or without locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) lpfc_els_hbq_free(struct lpfc_hba *phba, struct hbq_dmabuf *hbqbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	dma_pool_free(phba->lpfc_hbq_pool, hbqbp->dbuf.virt, hbqbp->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	kfree(hbqbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)  * lpfc_sli4_rb_alloc - Allocate an SLI4 Receive buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)  * @phba: HBA to allocate a receive buffer for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)  * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  * pool along a non-DMA-mapped container for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)  * Notes: Not interrupt-safe.  Must be called with no locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)  *   pointer to HBQ on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)  *   NULL on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct hbq_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) lpfc_sli4_rb_alloc(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	struct hbq_dmabuf *dma_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	dma_buf = kzalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	if (!dma_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	dma_buf->hbuf.virt = dma_pool_alloc(phba->lpfc_hrb_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 					    &dma_buf->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	if (!dma_buf->hbuf.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		kfree(dma_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	dma_buf->dbuf.virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 					    &dma_buf->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	if (!dma_buf->dbuf.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		dma_pool_free(phba->lpfc_hrb_pool, dma_buf->hbuf.virt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 			      dma_buf->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		kfree(dma_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	dma_buf->total_size = LPFC_DATA_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	return dma_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)  * lpfc_sli4_rb_free - Frees a receive buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)  * @phba: HBA buffer was allocated for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)  * @dmab: DMA Buffer container returned by lpfc_sli4_hbq_alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)  * Description: Frees both the container and the DMA-mapped buffers returned by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)  * lpfc_sli4_rb_alloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)  * Notes: Can be called with or without locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) lpfc_sli4_rb_free(struct lpfc_hba *phba, struct hbq_dmabuf *dmab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	dma_pool_free(phba->lpfc_hrb_pool, dmab->hbuf.virt, dmab->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	dma_pool_free(phba->lpfc_drb_pool, dmab->dbuf.virt, dmab->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	kfree(dmab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)  * lpfc_sli4_nvmet_alloc - Allocate an SLI4 Receive buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)  * @phba: HBA to allocate a receive buffer for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)  * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)  * pool along a non-DMA-mapped container for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)  * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  *   pointer to HBQ on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)  *   NULL on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct rqb_dmabuf *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) lpfc_sli4_nvmet_alloc(struct lpfc_hba *phba)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	struct rqb_dmabuf *dma_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	if (!dma_buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	dma_buf->hbuf.virt = dma_pool_alloc(phba->lpfc_hrb_pool, GFP_KERNEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 					    &dma_buf->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	if (!dma_buf->hbuf.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 		kfree(dma_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	dma_buf->dbuf.virt = dma_pool_alloc(phba->lpfc_nvmet_drb_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 					    GFP_KERNEL, &dma_buf->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	if (!dma_buf->dbuf.virt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		dma_pool_free(phba->lpfc_hrb_pool, dma_buf->hbuf.virt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 			      dma_buf->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 		kfree(dma_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	dma_buf->total_size = LPFC_NVMET_DATA_BUF_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	return dma_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)  * lpfc_sli4_nvmet_free - Frees a receive buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)  * @phba: HBA buffer was allocated for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)  * @dmab: DMA Buffer container returned by lpfc_sli4_rbq_alloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)  * Description: Frees both the container and the DMA-mapped buffers returned by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)  * lpfc_sli4_nvmet_alloc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)  * Notes: Can be called with or without locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) lpfc_sli4_nvmet_free(struct lpfc_hba *phba, struct rqb_dmabuf *dmab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	dma_pool_free(phba->lpfc_hrb_pool, dmab->hbuf.virt, dmab->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	dma_pool_free(phba->lpfc_nvmet_drb_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		      dmab->dbuf.virt, dmab->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	kfree(dmab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)  * lpfc_in_buf_free - Free a DMA buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)  * @phba: HBA buffer is associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)  * @mp: Buffer to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)  * Description: Frees the given DMA buffer in the appropriate way given if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)  * HBA is running in SLI3 mode with HBQs enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)  * Notes: Takes phba->hbalock.  Can be called with or without other locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) lpfc_in_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	struct hbq_dmabuf *hbq_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	if (!mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 		hbq_entry = container_of(mp, struct hbq_dmabuf, dbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		/* Check whether HBQ is still in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 		spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		if (!phba->hbq_in_use) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 			spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		list_del(&hbq_entry->dbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		if (hbq_entry->tag == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 			(phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 				(phba, hbq_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 			lpfc_sli_free_hbq(phba, hbq_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		lpfc_mbuf_free(phba, mp->virt, mp->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		kfree(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)  * lpfc_rq_buf_free - Free a RQ DMA buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)  * @phba: HBA buffer is associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)  * @mp: Buffer to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)  * Description: Frees the given DMA buffer in the appropriate way given by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)  * reposting it to its associated RQ so it can be reused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)  * Notes: Takes phba->hbalock.  Can be called with or without other locks held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)  * Returns: None
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) lpfc_rq_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 	struct lpfc_rqb *rqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	struct lpfc_rqe hrqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	struct lpfc_rqe drqe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	struct rqb_dmabuf *rqb_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	if (!mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	rqb_entry = container_of(mp, struct rqb_dmabuf, hbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	rqbp = rqb_entry->hrq->rqbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	spin_lock_irqsave(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	list_del(&rqb_entry->hbuf.list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	hrqe.address_lo = putPaddrLow(rqb_entry->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	hrqe.address_hi = putPaddrHigh(rqb_entry->hbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	drqe.address_lo = putPaddrLow(rqb_entry->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	drqe.address_hi = putPaddrHigh(rqb_entry->dbuf.phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	rc = lpfc_sli4_rq_put(rqb_entry->hrq, rqb_entry->drq, &hrqe, &drqe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 				"6409 Cannot post to HRQ %d: %x %x %x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 				"DRQ %x %x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 				rqb_entry->hrq->queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 				rqb_entry->hrq->host_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 				rqb_entry->hrq->hba_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 				rqb_entry->hrq->entry_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 				rqb_entry->drq->host_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 				rqb_entry->drq->hba_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 		(rqbp->rqb_free_buffer)(phba, rqb_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 		list_add_tail(&rqb_entry->hbuf.list, &rqbp->rqb_buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		rqbp->buffer_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	spin_unlock_irqrestore(&phba->hbalock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }