1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2023 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2014 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/mempool.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_transport_fc.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
41 #include "lpfc_scsi.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_logmsg.h"
45 #define LPFC_MBUF_POOL_SIZE 64 /* max elements in MBUF safety pool */
46 #define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */
47 #define LPFC_DEVICE_DATA_POOL_SIZE 64 /* max elements in device data pool */
48 #define LPFC_RRQ_POOL_SIZE 256 /* max elements in non-DMA pool */
49 #define LPFC_MBX_POOL_SIZE 256 /* max elements in MBX non-DMA pool */
51 /* lpfc_mbox_free_sli_mbox
53 * @phba: HBA to free memory for
54 * @mbox: mailbox command to free
56 * This routine detects the mbox type and calls the correct
57 * free routine to fully release all associated memory.
60 lpfc_mem_free_sli_mbox(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
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.
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
);
70 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
75 lpfc_mem_alloc_active_rrq_pool_s4(struct lpfc_hba
*phba
) {
77 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
81 bytes
= ((BITS_PER_LONG
- 1 + max_xri
) / BITS_PER_LONG
) *
82 sizeof(unsigned long);
83 phba
->cfg_rrq_xri_bitmap_sz
= bytes
;
84 phba
->active_rrq_pool
= mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE
,
86 if (!phba
->active_rrq_pool
)
93 * lpfc_mem_alloc - create and allocate all PCI and memory pools
94 * @phba: HBA to allocate pools for
95 * @align: alignment requirement for blocks; must be a power of two
97 * Description: Creates and allocates PCI pools lpfc_mbuf_pool,
98 * lpfc_hrb_pool. Creates and allocates kmalloc-backed mempools
99 * for LPFC_MBOXQ_t and lpfc_nodelist. Also allocates the VPI bitmask.
101 * Notes: Not interrupt-safe. Must be called with no locks held. If any
102 * allocation fails, frees all successfully allocated memory before returning.
106 * -ENOMEM on failure (if any memory allocations fail)
109 lpfc_mem_alloc(struct lpfc_hba
*phba
, int align
)
111 struct lpfc_dma_pool
*pool
= &phba
->lpfc_mbuf_safety_pool
;
115 phba
->lpfc_mbuf_pool
= dma_pool_create("lpfc_mbuf_pool", &phba
->pcidev
->dev
,
118 if (!phba
->lpfc_mbuf_pool
)
121 pool
->elements
= kmalloc_array(LPFC_MBUF_POOL_SIZE
,
122 sizeof(struct lpfc_dmabuf
),
125 goto fail_free_lpfc_mbuf_pool
;
128 pool
->current_count
= 0;
129 for ( i
= 0; i
< LPFC_MBUF_POOL_SIZE
; i
++) {
130 pool
->elements
[i
].virt
= dma_pool_alloc(phba
->lpfc_mbuf_pool
,
131 GFP_KERNEL
, &pool
->elements
[i
].phys
);
132 if (!pool
->elements
[i
].virt
)
133 goto fail_free_mbuf_pool
;
135 pool
->current_count
++;
138 phba
->mbox_mem_pool
= mempool_create_kmalloc_pool(LPFC_MBX_POOL_SIZE
,
139 sizeof(LPFC_MBOXQ_t
));
140 if (!phba
->mbox_mem_pool
)
141 goto fail_free_mbuf_pool
;
143 phba
->nlp_mem_pool
= mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE
,
144 sizeof(struct lpfc_nodelist
));
145 if (!phba
->nlp_mem_pool
)
146 goto fail_free_mbox_pool
;
148 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
150 mempool_create_kmalloc_pool(LPFC_RRQ_POOL_SIZE
,
151 sizeof(struct lpfc_node_rrq
));
153 goto fail_free_nlp_mem_pool
;
154 phba
->lpfc_hrb_pool
= dma_pool_create("lpfc_hrb_pool",
156 LPFC_HDR_BUF_SIZE
, align
, 0);
157 if (!phba
->lpfc_hrb_pool
)
158 goto fail_free_rrq_mem_pool
;
160 phba
->lpfc_drb_pool
= dma_pool_create("lpfc_drb_pool",
162 LPFC_DATA_BUF_SIZE
, align
, 0);
163 if (!phba
->lpfc_drb_pool
)
164 goto fail_free_hrb_pool
;
165 phba
->lpfc_hbq_pool
= NULL
;
167 phba
->lpfc_hbq_pool
= dma_pool_create("lpfc_hbq_pool",
168 &phba
->pcidev
->dev
, LPFC_BPL_SIZE
, align
, 0);
169 if (!phba
->lpfc_hbq_pool
)
170 goto fail_free_nlp_mem_pool
;
171 phba
->lpfc_hrb_pool
= NULL
;
172 phba
->lpfc_drb_pool
= NULL
;
175 if (phba
->cfg_EnableXLane
) {
176 phba
->device_data_mem_pool
= mempool_create_kmalloc_pool(
177 LPFC_DEVICE_DATA_POOL_SIZE
,
178 sizeof(struct lpfc_device_data
));
179 if (!phba
->device_data_mem_pool
)
180 goto fail_free_drb_pool
;
182 phba
->device_data_mem_pool
= NULL
;
187 dma_pool_destroy(phba
->lpfc_drb_pool
);
188 phba
->lpfc_drb_pool
= NULL
;
190 dma_pool_destroy(phba
->lpfc_hrb_pool
);
191 phba
->lpfc_hrb_pool
= NULL
;
192 fail_free_rrq_mem_pool
:
193 mempool_destroy(phba
->rrq_pool
);
194 phba
->rrq_pool
= NULL
;
195 fail_free_nlp_mem_pool
:
196 mempool_destroy(phba
->nlp_mem_pool
);
197 phba
->nlp_mem_pool
= NULL
;
199 mempool_destroy(phba
->mbox_mem_pool
);
200 phba
->mbox_mem_pool
= NULL
;
203 dma_pool_free(phba
->lpfc_mbuf_pool
, pool
->elements
[i
].virt
,
204 pool
->elements
[i
].phys
);
205 kfree(pool
->elements
);
206 fail_free_lpfc_mbuf_pool
:
207 dma_pool_destroy(phba
->lpfc_mbuf_pool
);
208 phba
->lpfc_mbuf_pool
= NULL
;
214 lpfc_nvmet_mem_alloc(struct lpfc_hba
*phba
)
216 phba
->lpfc_nvmet_drb_pool
=
217 dma_pool_create("lpfc_nvmet_drb_pool",
218 &phba
->pcidev
->dev
, LPFC_NVMET_DATA_BUF_SIZE
,
220 if (!phba
->lpfc_nvmet_drb_pool
) {
221 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
222 "6024 Can't enable NVME Target - no memory\n");
229 * lpfc_mem_free - Frees memory allocated by lpfc_mem_alloc
230 * @phba: HBA to free memory for
232 * Description: Free the memory allocated by lpfc_mem_alloc routine. This
233 * routine is a the counterpart of lpfc_mem_alloc.
238 lpfc_mem_free(struct lpfc_hba
*phba
)
241 struct lpfc_dma_pool
*pool
= &phba
->lpfc_mbuf_safety_pool
;
242 struct lpfc_device_data
*device_data
;
245 lpfc_sli_hbqbuf_free_all(phba
);
246 dma_pool_destroy(phba
->lpfc_nvmet_drb_pool
);
247 phba
->lpfc_nvmet_drb_pool
= NULL
;
249 dma_pool_destroy(phba
->lpfc_drb_pool
);
250 phba
->lpfc_drb_pool
= NULL
;
252 dma_pool_destroy(phba
->lpfc_hrb_pool
);
253 phba
->lpfc_hrb_pool
= NULL
;
255 dma_pool_destroy(phba
->lpfc_hbq_pool
);
256 phba
->lpfc_hbq_pool
= NULL
;
258 mempool_destroy(phba
->rrq_pool
);
259 phba
->rrq_pool
= NULL
;
261 /* Free NLP memory pool */
262 mempool_destroy(phba
->nlp_mem_pool
);
263 phba
->nlp_mem_pool
= NULL
;
264 if (phba
->sli_rev
== LPFC_SLI_REV4
&& phba
->active_rrq_pool
) {
265 mempool_destroy(phba
->active_rrq_pool
);
266 phba
->active_rrq_pool
= NULL
;
269 /* Free mbox memory pool */
270 mempool_destroy(phba
->mbox_mem_pool
);
271 phba
->mbox_mem_pool
= NULL
;
273 /* Free MBUF memory pool */
274 for (i
= 0; i
< pool
->current_count
; i
++)
275 dma_pool_free(phba
->lpfc_mbuf_pool
, pool
->elements
[i
].virt
,
276 pool
->elements
[i
].phys
);
277 kfree(pool
->elements
);
279 dma_pool_destroy(phba
->lpfc_mbuf_pool
);
280 phba
->lpfc_mbuf_pool
= NULL
;
282 /* Free Device Data memory pool */
283 if (phba
->device_data_mem_pool
) {
284 /* Ensure all objects have been returned to the pool */
285 while (!list_empty(&phba
->luns
)) {
286 device_data
= list_first_entry(&phba
->luns
,
287 struct lpfc_device_data
,
289 list_del(&device_data
->listentry
);
290 mempool_free(device_data
, phba
->device_data_mem_pool
);
292 mempool_destroy(phba
->device_data_mem_pool
);
294 phba
->device_data_mem_pool
= NULL
;
299 * lpfc_mem_free_all - Frees all PCI and driver memory
300 * @phba: HBA to free memory for
302 * Description: Free memory from PCI and driver memory pools and also those
303 * used : lpfc_sg_dma_buf_pool, lpfc_mbuf_pool, lpfc_hrb_pool. Frees
304 * kmalloc-backed mempools for LPFC_MBOXQ_t and lpfc_nodelist. Also frees
310 lpfc_mem_free_all(struct lpfc_hba
*phba
)
312 struct lpfc_sli
*psli
= &phba
->sli
;
313 LPFC_MBOXQ_t
*mbox
, *next_mbox
;
315 /* Free memory used in mailbox queue back to mailbox memory pool */
316 list_for_each_entry_safe(mbox
, next_mbox
, &psli
->mboxq
, list
) {
317 list_del(&mbox
->list
);
318 lpfc_mem_free_sli_mbox(phba
, mbox
);
320 /* Free memory used in mailbox cmpl list back to mailbox memory pool */
321 list_for_each_entry_safe(mbox
, next_mbox
, &psli
->mboxq_cmpl
, list
) {
322 list_del(&mbox
->list
);
323 lpfc_mem_free_sli_mbox(phba
, mbox
);
325 /* Free the active mailbox command back to the mailbox memory pool */
326 spin_lock_irq(&phba
->hbalock
);
327 psli
->sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
328 spin_unlock_irq(&phba
->hbalock
);
329 if (psli
->mbox_active
) {
330 mbox
= psli
->mbox_active
;
331 lpfc_mem_free_sli_mbox(phba
, mbox
);
332 psli
->mbox_active
= NULL
;
335 /* Free and destroy all the allocated memory pools */
338 /* Free DMA buffer memory pool */
339 dma_pool_destroy(phba
->lpfc_sg_dma_buf_pool
);
340 phba
->lpfc_sg_dma_buf_pool
= NULL
;
342 dma_pool_destroy(phba
->lpfc_cmd_rsp_buf_pool
);
343 phba
->lpfc_cmd_rsp_buf_pool
= NULL
;
345 /* Free Congestion Data buffer */
347 dma_free_coherent(&phba
->pcidev
->dev
,
348 sizeof(struct lpfc_cgn_info
),
349 phba
->cgn_i
->virt
, phba
->cgn_i
->phys
);
354 /* Free RX Monitor */
355 if (phba
->rx_monitor
) {
356 lpfc_rx_monitor_destroy_ring(phba
->rx_monitor
);
357 kfree(phba
->rx_monitor
);
358 phba
->rx_monitor
= NULL
;
361 /* Free the iocb lookup array */
362 kfree(psli
->iocbq_lookup
);
363 psli
->iocbq_lookup
= NULL
;
369 * lpfc_mbuf_alloc - Allocate an mbuf from the lpfc_mbuf_pool PCI pool
370 * @phba: HBA which owns the pool to allocate from
371 * @mem_flags: indicates if this is a priority (MEM_PRI) allocation
372 * @handle: used to return the DMA-mapped address of the mbuf
374 * Description: Allocates a DMA-mapped buffer from the lpfc_mbuf_pool PCI pool.
375 * Allocates from generic dma_pool_alloc function first and if that fails and
376 * mem_flags has MEM_PRI set (the only defined flag), returns an mbuf from the
379 * Notes: Not interrupt-safe. Must be called with no locks held. Takes
383 * pointer to the allocated mbuf on success
387 lpfc_mbuf_alloc(struct lpfc_hba
*phba
, int mem_flags
, dma_addr_t
*handle
)
389 struct lpfc_dma_pool
*pool
= &phba
->lpfc_mbuf_safety_pool
;
390 unsigned long iflags
;
393 ret
= dma_pool_alloc(phba
->lpfc_mbuf_pool
, GFP_KERNEL
, handle
);
395 spin_lock_irqsave(&phba
->hbalock
, iflags
);
396 if (!ret
&& (mem_flags
& MEM_PRI
) && pool
->current_count
) {
397 pool
->current_count
--;
398 ret
= pool
->elements
[pool
->current_count
].virt
;
399 *handle
= pool
->elements
[pool
->current_count
].phys
;
401 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
406 * __lpfc_mbuf_free - Free an mbuf from the lpfc_mbuf_pool PCI pool (locked)
407 * @phba: HBA which owns the pool to return to
408 * @virt: mbuf to free
409 * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
411 * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
412 * it is below its max_count, frees the mbuf otherwise.
414 * Notes: Must be called with phba->hbalock held to synchronize access to
415 * lpfc_mbuf_safety_pool.
420 __lpfc_mbuf_free(struct lpfc_hba
* phba
, void *virt
, dma_addr_t dma
)
422 struct lpfc_dma_pool
*pool
= &phba
->lpfc_mbuf_safety_pool
;
424 if (pool
->current_count
< pool
->max_count
) {
425 pool
->elements
[pool
->current_count
].virt
= virt
;
426 pool
->elements
[pool
->current_count
].phys
= dma
;
427 pool
->current_count
++;
429 dma_pool_free(phba
->lpfc_mbuf_pool
, virt
, dma
);
435 * lpfc_mbuf_free - Free an mbuf from the lpfc_mbuf_pool PCI pool (unlocked)
436 * @phba: HBA which owns the pool to return to
437 * @virt: mbuf to free
438 * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
440 * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
441 * it is below its max_count, frees the mbuf otherwise.
443 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
448 lpfc_mbuf_free(struct lpfc_hba
* phba
, void *virt
, dma_addr_t dma
)
450 unsigned long iflags
;
452 spin_lock_irqsave(&phba
->hbalock
, iflags
);
453 __lpfc_mbuf_free(phba
, virt
, dma
);
454 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
459 * lpfc_nvmet_buf_alloc - Allocate an nvmet_buf from the
460 * lpfc_sg_dma_buf_pool PCI pool
461 * @phba: HBA which owns the pool to allocate from
462 * @mem_flags: indicates if this is a priority (MEM_PRI) allocation
463 * @handle: used to return the DMA-mapped address of the nvmet_buf
465 * Description: Allocates a DMA-mapped buffer from the lpfc_sg_dma_buf_pool
466 * PCI pool. Allocates from generic dma_pool_alloc function.
469 * pointer to the allocated nvmet_buf on success
473 lpfc_nvmet_buf_alloc(struct lpfc_hba
*phba
, int mem_flags
, dma_addr_t
*handle
)
477 ret
= dma_pool_alloc(phba
->lpfc_sg_dma_buf_pool
, GFP_KERNEL
, handle
);
482 * lpfc_nvmet_buf_free - Free an nvmet_buf from the lpfc_sg_dma_buf_pool
484 * @phba: HBA which owns the pool to return to
485 * @virt: nvmet_buf to free
486 * @dma: the DMA-mapped address of the lpfc_sg_dma_buf_pool to be freed
491 lpfc_nvmet_buf_free(struct lpfc_hba
*phba
, void *virt
, dma_addr_t dma
)
493 dma_pool_free(phba
->lpfc_sg_dma_buf_pool
, virt
, dma
);
497 * lpfc_els_hbq_alloc - Allocate an HBQ buffer
498 * @phba: HBA to allocate HBQ buffer for
500 * Description: Allocates a DMA-mapped HBQ buffer from the lpfc_hrb_pool PCI
501 * pool along a non-DMA-mapped container for it.
503 * Notes: Not interrupt-safe. Must be called with no locks held.
506 * pointer to HBQ on success
510 lpfc_els_hbq_alloc(struct lpfc_hba
*phba
)
512 struct hbq_dmabuf
*hbqbp
;
514 hbqbp
= kzalloc(sizeof(struct hbq_dmabuf
), GFP_KERNEL
);
518 hbqbp
->dbuf
.virt
= dma_pool_alloc(phba
->lpfc_hbq_pool
, GFP_KERNEL
,
520 if (!hbqbp
->dbuf
.virt
) {
524 hbqbp
->total_size
= LPFC_BPL_SIZE
;
529 * lpfc_els_hbq_free - Frees an HBQ buffer allocated with lpfc_els_hbq_alloc
530 * @phba: HBA buffer was allocated for
531 * @hbqbp: HBQ container returned by lpfc_els_hbq_alloc
533 * Description: Frees both the container and the DMA-mapped buffer returned by
534 * lpfc_els_hbq_alloc.
536 * Notes: Can be called with or without locks held.
541 lpfc_els_hbq_free(struct lpfc_hba
*phba
, struct hbq_dmabuf
*hbqbp
)
543 dma_pool_free(phba
->lpfc_hbq_pool
, hbqbp
->dbuf
.virt
, hbqbp
->dbuf
.phys
);
549 * lpfc_sli4_rb_alloc - Allocate an SLI4 Receive buffer
550 * @phba: HBA to allocate a receive buffer for
552 * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
553 * pool along a non-DMA-mapped container for it.
555 * Notes: Not interrupt-safe. Must be called with no locks held.
558 * pointer to HBQ on success
562 lpfc_sli4_rb_alloc(struct lpfc_hba
*phba
)
564 struct hbq_dmabuf
*dma_buf
;
566 dma_buf
= kzalloc(sizeof(struct hbq_dmabuf
), GFP_KERNEL
);
570 dma_buf
->hbuf
.virt
= dma_pool_alloc(phba
->lpfc_hrb_pool
, GFP_KERNEL
,
571 &dma_buf
->hbuf
.phys
);
572 if (!dma_buf
->hbuf
.virt
) {
576 dma_buf
->dbuf
.virt
= dma_pool_alloc(phba
->lpfc_drb_pool
, GFP_KERNEL
,
577 &dma_buf
->dbuf
.phys
);
578 if (!dma_buf
->dbuf
.virt
) {
579 dma_pool_free(phba
->lpfc_hrb_pool
, dma_buf
->hbuf
.virt
,
584 dma_buf
->total_size
= LPFC_DATA_BUF_SIZE
;
589 * lpfc_sli4_rb_free - Frees a receive buffer
590 * @phba: HBA buffer was allocated for
591 * @dmab: DMA Buffer container returned by lpfc_sli4_hbq_alloc
593 * Description: Frees both the container and the DMA-mapped buffers returned by
594 * lpfc_sli4_rb_alloc.
596 * Notes: Can be called with or without locks held.
601 lpfc_sli4_rb_free(struct lpfc_hba
*phba
, struct hbq_dmabuf
*dmab
)
603 dma_pool_free(phba
->lpfc_hrb_pool
, dmab
->hbuf
.virt
, dmab
->hbuf
.phys
);
604 dma_pool_free(phba
->lpfc_drb_pool
, dmab
->dbuf
.virt
, dmab
->dbuf
.phys
);
609 * lpfc_sli4_nvmet_alloc - Allocate an SLI4 Receive buffer
610 * @phba: HBA to allocate a receive buffer for
612 * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
613 * pool along a non-DMA-mapped container for it.
616 * pointer to HBQ on success
620 lpfc_sli4_nvmet_alloc(struct lpfc_hba
*phba
)
622 struct rqb_dmabuf
*dma_buf
;
624 dma_buf
= kzalloc(sizeof(*dma_buf
), GFP_KERNEL
);
628 dma_buf
->hbuf
.virt
= dma_pool_alloc(phba
->lpfc_hrb_pool
, GFP_KERNEL
,
629 &dma_buf
->hbuf
.phys
);
630 if (!dma_buf
->hbuf
.virt
) {
634 dma_buf
->dbuf
.virt
= dma_pool_alloc(phba
->lpfc_nvmet_drb_pool
,
635 GFP_KERNEL
, &dma_buf
->dbuf
.phys
);
636 if (!dma_buf
->dbuf
.virt
) {
637 dma_pool_free(phba
->lpfc_hrb_pool
, dma_buf
->hbuf
.virt
,
642 dma_buf
->total_size
= LPFC_NVMET_DATA_BUF_SIZE
;
647 * lpfc_sli4_nvmet_free - Frees a receive buffer
648 * @phba: HBA buffer was allocated for
649 * @dmab: DMA Buffer container returned by lpfc_sli4_rbq_alloc
651 * Description: Frees both the container and the DMA-mapped buffers returned by
652 * lpfc_sli4_nvmet_alloc.
654 * Notes: Can be called with or without locks held.
659 lpfc_sli4_nvmet_free(struct lpfc_hba
*phba
, struct rqb_dmabuf
*dmab
)
661 dma_pool_free(phba
->lpfc_hrb_pool
, dmab
->hbuf
.virt
, dmab
->hbuf
.phys
);
662 dma_pool_free(phba
->lpfc_nvmet_drb_pool
,
663 dmab
->dbuf
.virt
, dmab
->dbuf
.phys
);
668 * lpfc_in_buf_free - Free a DMA buffer
669 * @phba: HBA buffer is associated with
670 * @mp: Buffer to free
672 * Description: Frees the given DMA buffer in the appropriate way given if the
673 * HBA is running in SLI3 mode with HBQs enabled.
675 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
680 lpfc_in_buf_free(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*mp
)
682 struct hbq_dmabuf
*hbq_entry
;
688 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
689 hbq_entry
= container_of(mp
, struct hbq_dmabuf
, dbuf
);
690 /* Check whether HBQ is still in use */
691 spin_lock_irqsave(&phba
->hbalock
, flags
);
692 if (!phba
->hbq_in_use
) {
693 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
696 list_del(&hbq_entry
->dbuf
.list
);
697 if (hbq_entry
->tag
== -1) {
698 (phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
)
701 lpfc_sli_free_hbq(phba
, hbq_entry
);
703 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
705 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
712 * lpfc_rq_buf_free - Free a RQ DMA buffer
713 * @phba: HBA buffer is associated with
714 * @mp: Buffer to free
716 * Description: Frees the given DMA buffer in the appropriate way given by
717 * reposting it to its associated RQ so it can be reused.
719 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
724 lpfc_rq_buf_free(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*mp
)
726 struct lpfc_rqb
*rqbp
;
727 struct lpfc_rqe hrqe
;
728 struct lpfc_rqe drqe
;
729 struct rqb_dmabuf
*rqb_entry
;
736 rqb_entry
= container_of(mp
, struct rqb_dmabuf
, hbuf
);
737 rqbp
= rqb_entry
->hrq
->rqbp
;
739 spin_lock_irqsave(&phba
->hbalock
, flags
);
740 list_del(&rqb_entry
->hbuf
.list
);
741 hrqe
.address_lo
= putPaddrLow(rqb_entry
->hbuf
.phys
);
742 hrqe
.address_hi
= putPaddrHigh(rqb_entry
->hbuf
.phys
);
743 drqe
.address_lo
= putPaddrLow(rqb_entry
->dbuf
.phys
);
744 drqe
.address_hi
= putPaddrHigh(rqb_entry
->dbuf
.phys
);
745 rc
= lpfc_sli4_rq_put(rqb_entry
->hrq
, rqb_entry
->drq
, &hrqe
, &drqe
);
747 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
748 "6409 Cannot post to HRQ %d: %x %x %x "
750 rqb_entry
->hrq
->queue_id
,
751 rqb_entry
->hrq
->host_index
,
752 rqb_entry
->hrq
->hba_index
,
753 rqb_entry
->hrq
->entry_count
,
754 rqb_entry
->drq
->host_index
,
755 rqb_entry
->drq
->hba_index
);
756 (rqbp
->rqb_free_buffer
)(phba
, rqb_entry
);
758 list_add_tail(&rqb_entry
->hbuf
.list
, &rqbp
->rqb_buffer_list
);
759 rqbp
->buffer_count
++;
762 spin_unlock_irqrestore(&phba
->hbalock
, flags
);