1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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>
34 #include <linux/nvme-fc-driver.h>
39 #include "lpfc_sli4.h"
41 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
44 #include "lpfc_nvme.h"
45 #include "lpfc_nvmet.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_logmsg.h"
49 #define LPFC_MBUF_POOL_SIZE 64 /* max elements in MBUF safety pool */
50 #define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */
51 #define LPFC_DEVICE_DATA_POOL_SIZE 64 /* max elements in device data pool */
54 lpfc_mem_alloc_active_rrq_pool_s4(struct lpfc_hba *phba) {
56 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
60 bytes = ((BITS_PER_LONG - 1 + max_xri) / BITS_PER_LONG) *
61 sizeof(unsigned long);
62 phba->cfg_rrq_xri_bitmap_sz = bytes;
63 phba->active_rrq_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
65 if (!phba->active_rrq_pool)
72 * lpfc_mem_alloc - create and allocate all PCI and memory pools
73 * @phba: HBA to allocate pools for
75 * Description: Creates and allocates PCI pools lpfc_sg_dma_buf_pool,
76 * lpfc_mbuf_pool, lpfc_hrb_pool. Creates and allocates kmalloc-backed mempools
77 * for LPFC_MBOXQ_t and lpfc_nodelist. Also allocates the VPI bitmask.
79 * Notes: Not interrupt-safe. Must be called with no locks held. If any
80 * allocation fails, frees all successfully allocated memory before returning.
84 * -ENOMEM on failure (if any memory allocations fail)
87 lpfc_mem_alloc(struct lpfc_hba *phba, int align)
89 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
92 if (phba->sli_rev == LPFC_SLI_REV4) {
93 /* Calculate alignment */
94 if (phba->cfg_sg_dma_buf_size < SLI4_PAGE_SIZE)
95 i = phba->cfg_sg_dma_buf_size;
99 phba->lpfc_sg_dma_buf_pool =
100 pci_pool_create("lpfc_sg_dma_buf_pool",
102 phba->cfg_sg_dma_buf_size,
104 if (!phba->lpfc_sg_dma_buf_pool)
108 phba->lpfc_sg_dma_buf_pool =
109 pci_pool_create("lpfc_sg_dma_buf_pool",
110 phba->pcidev, phba->cfg_sg_dma_buf_size,
113 if (!phba->lpfc_sg_dma_buf_pool)
117 phba->lpfc_mbuf_pool = pci_pool_create("lpfc_mbuf_pool", phba->pcidev,
120 if (!phba->lpfc_mbuf_pool)
121 goto fail_free_dma_buf_pool;
123 pool->elements = kmalloc(sizeof(struct lpfc_dmabuf) *
124 LPFC_MBUF_POOL_SIZE, GFP_KERNEL);
126 goto fail_free_lpfc_mbuf_pool;
129 pool->current_count = 0;
130 for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) {
131 pool->elements[i].virt = pci_pool_alloc(phba->lpfc_mbuf_pool,
132 GFP_KERNEL, &pool->elements[i].phys);
133 if (!pool->elements[i].virt)
134 goto fail_free_mbuf_pool;
136 pool->current_count++;
139 phba->mbox_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
140 sizeof(LPFC_MBOXQ_t));
141 if (!phba->mbox_mem_pool)
142 goto fail_free_mbuf_pool;
144 phba->nlp_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
145 sizeof(struct lpfc_nodelist));
146 if (!phba->nlp_mem_pool)
147 goto fail_free_mbox_pool;
149 if (phba->sli_rev == LPFC_SLI_REV4) {
151 mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
152 sizeof(struct lpfc_node_rrq));
154 goto fail_free_nlp_mem_pool;
155 phba->lpfc_hrb_pool = pci_pool_create("lpfc_hrb_pool",
157 LPFC_HDR_BUF_SIZE, align, 0);
158 if (!phba->lpfc_hrb_pool)
159 goto fail_free_rrq_mem_pool;
161 phba->lpfc_drb_pool = pci_pool_create("lpfc_drb_pool",
163 LPFC_DATA_BUF_SIZE, align, 0);
164 if (!phba->lpfc_drb_pool)
165 goto fail_free_hrb_pool;
166 phba->lpfc_hbq_pool = NULL;
168 phba->lpfc_hbq_pool = pci_pool_create("lpfc_hbq_pool",
169 phba->pcidev, LPFC_BPL_SIZE, align, 0);
170 if (!phba->lpfc_hbq_pool)
171 goto fail_free_nlp_mem_pool;
172 phba->lpfc_hrb_pool = NULL;
173 phba->lpfc_drb_pool = NULL;
176 if (phba->cfg_EnableXLane) {
177 phba->device_data_mem_pool = mempool_create_kmalloc_pool(
178 LPFC_DEVICE_DATA_POOL_SIZE,
179 sizeof(struct lpfc_device_data));
180 if (!phba->device_data_mem_pool)
181 goto fail_free_drb_pool;
183 phba->device_data_mem_pool = NULL;
188 pci_pool_destroy(phba->lpfc_drb_pool);
189 phba->lpfc_drb_pool = NULL;
191 pci_pool_destroy(phba->lpfc_hrb_pool);
192 phba->lpfc_hrb_pool = NULL;
193 fail_free_rrq_mem_pool:
194 mempool_destroy(phba->rrq_pool);
195 phba->rrq_pool = NULL;
196 fail_free_nlp_mem_pool:
197 mempool_destroy(phba->nlp_mem_pool);
198 phba->nlp_mem_pool = NULL;
200 mempool_destroy(phba->mbox_mem_pool);
201 phba->mbox_mem_pool = NULL;
204 pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
205 pool->elements[i].phys);
206 kfree(pool->elements);
207 fail_free_lpfc_mbuf_pool:
208 pci_pool_destroy(phba->lpfc_mbuf_pool);
209 phba->lpfc_mbuf_pool = NULL;
210 fail_free_dma_buf_pool:
211 pci_pool_destroy(phba->lpfc_sg_dma_buf_pool);
212 phba->lpfc_sg_dma_buf_pool = NULL;
218 lpfc_nvmet_mem_alloc(struct lpfc_hba *phba)
220 phba->lpfc_nvmet_drb_pool =
221 pci_pool_create("lpfc_nvmet_drb_pool",
222 phba->pcidev, LPFC_NVMET_DATA_BUF_SIZE,
224 if (!phba->lpfc_nvmet_drb_pool) {
225 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
226 "6024 Can't enable NVME Target - no memory\n");
233 * lpfc_mem_free - Frees memory allocated by lpfc_mem_alloc
234 * @phba: HBA to free memory for
236 * Description: Free the memory allocated by lpfc_mem_alloc routine. This
237 * routine is a the counterpart of lpfc_mem_alloc.
242 lpfc_mem_free(struct lpfc_hba *phba)
245 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
246 struct lpfc_device_data *device_data;
249 lpfc_sli_hbqbuf_free_all(phba);
250 if (phba->lpfc_nvmet_drb_pool)
251 pci_pool_destroy(phba->lpfc_nvmet_drb_pool);
252 phba->lpfc_nvmet_drb_pool = NULL;
253 if (phba->lpfc_drb_pool)
254 pci_pool_destroy(phba->lpfc_drb_pool);
255 phba->lpfc_drb_pool = NULL;
256 if (phba->lpfc_hrb_pool)
257 pci_pool_destroy(phba->lpfc_hrb_pool);
258 phba->lpfc_hrb_pool = NULL;
259 if (phba->txrdy_payload_pool)
260 pci_pool_destroy(phba->txrdy_payload_pool);
261 phba->txrdy_payload_pool = NULL;
263 if (phba->lpfc_hbq_pool)
264 pci_pool_destroy(phba->lpfc_hbq_pool);
265 phba->lpfc_hbq_pool = NULL;
268 mempool_destroy(phba->rrq_pool);
269 phba->rrq_pool = NULL;
271 /* Free NLP memory pool */
272 mempool_destroy(phba->nlp_mem_pool);
273 phba->nlp_mem_pool = NULL;
274 if (phba->sli_rev == LPFC_SLI_REV4 && phba->active_rrq_pool) {
275 mempool_destroy(phba->active_rrq_pool);
276 phba->active_rrq_pool = NULL;
279 /* Free mbox memory pool */
280 mempool_destroy(phba->mbox_mem_pool);
281 phba->mbox_mem_pool = NULL;
283 /* Free MBUF memory pool */
284 for (i = 0; i < pool->current_count; i++)
285 pci_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
286 pool->elements[i].phys);
287 kfree(pool->elements);
289 pci_pool_destroy(phba->lpfc_mbuf_pool);
290 phba->lpfc_mbuf_pool = NULL;
292 /* Free DMA buffer memory pool */
293 pci_pool_destroy(phba->lpfc_sg_dma_buf_pool);
294 phba->lpfc_sg_dma_buf_pool = NULL;
296 /* Free Device Data memory pool */
297 if (phba->device_data_mem_pool) {
298 /* Ensure all objects have been returned to the pool */
299 while (!list_empty(&phba->luns)) {
300 device_data = list_first_entry(&phba->luns,
301 struct lpfc_device_data,
303 list_del(&device_data->listentry);
304 mempool_free(device_data, phba->device_data_mem_pool);
306 mempool_destroy(phba->device_data_mem_pool);
308 phba->device_data_mem_pool = NULL;
313 * lpfc_mem_free_all - Frees all PCI and driver memory
314 * @phba: HBA to free memory for
316 * Description: Free memory from PCI and driver memory pools and also those
317 * used : lpfc_sg_dma_buf_pool, lpfc_mbuf_pool, lpfc_hrb_pool. Frees
318 * kmalloc-backed mempools for LPFC_MBOXQ_t and lpfc_nodelist. Also frees
324 lpfc_mem_free_all(struct lpfc_hba *phba)
326 struct lpfc_sli *psli = &phba->sli;
327 LPFC_MBOXQ_t *mbox, *next_mbox;
328 struct lpfc_dmabuf *mp;
330 /* Free memory used in mailbox queue back to mailbox memory pool */
331 list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) {
332 mp = (struct lpfc_dmabuf *) (mbox->context1);
334 lpfc_mbuf_free(phba, mp->virt, mp->phys);
337 list_del(&mbox->list);
338 mempool_free(mbox, phba->mbox_mem_pool);
340 /* Free memory used in mailbox cmpl list back to mailbox memory pool */
341 list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq_cmpl, list) {
342 mp = (struct lpfc_dmabuf *) (mbox->context1);
344 lpfc_mbuf_free(phba, mp->virt, mp->phys);
347 list_del(&mbox->list);
348 mempool_free(mbox, phba->mbox_mem_pool);
350 /* Free the active mailbox command back to the mailbox memory pool */
351 spin_lock_irq(&phba->hbalock);
352 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
353 spin_unlock_irq(&phba->hbalock);
354 if (psli->mbox_active) {
355 mbox = psli->mbox_active;
356 mp = (struct lpfc_dmabuf *) (mbox->context1);
358 lpfc_mbuf_free(phba, mp->virt, mp->phys);
361 mempool_free(mbox, phba->mbox_mem_pool);
362 psli->mbox_active = NULL;
365 /* Free and destroy all the allocated memory pools */
368 /* Free the iocb lookup array */
369 kfree(psli->iocbq_lookup);
370 psli->iocbq_lookup = NULL;
376 * lpfc_mbuf_alloc - Allocate an mbuf from the lpfc_mbuf_pool PCI pool
377 * @phba: HBA which owns the pool to allocate from
378 * @mem_flags: indicates if this is a priority (MEM_PRI) allocation
379 * @handle: used to return the DMA-mapped address of the mbuf
381 * Description: Allocates a DMA-mapped buffer from the lpfc_mbuf_pool PCI pool.
382 * Allocates from generic pci_pool_alloc function first and if that fails and
383 * mem_flags has MEM_PRI set (the only defined flag), returns an mbuf from the
386 * Notes: Not interrupt-safe. Must be called with no locks held. Takes
390 * pointer to the allocated mbuf on success
394 lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
396 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
397 unsigned long iflags;
400 ret = pci_pool_alloc(phba->lpfc_mbuf_pool, GFP_KERNEL, handle);
402 spin_lock_irqsave(&phba->hbalock, iflags);
403 if (!ret && (mem_flags & MEM_PRI) && pool->current_count) {
404 pool->current_count--;
405 ret = pool->elements[pool->current_count].virt;
406 *handle = pool->elements[pool->current_count].phys;
408 spin_unlock_irqrestore(&phba->hbalock, iflags);
413 * __lpfc_mbuf_free - Free an mbuf from the lpfc_mbuf_pool PCI pool (locked)
414 * @phba: HBA which owns the pool to return to
415 * @virt: mbuf to free
416 * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
418 * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
419 * it is below its max_count, frees the mbuf otherwise.
421 * Notes: Must be called with phba->hbalock held to synchronize access to
422 * lpfc_mbuf_safety_pool.
427 __lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
429 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
431 if (pool->current_count < pool->max_count) {
432 pool->elements[pool->current_count].virt = virt;
433 pool->elements[pool->current_count].phys = dma;
434 pool->current_count++;
436 pci_pool_free(phba->lpfc_mbuf_pool, virt, dma);
442 * lpfc_mbuf_free - Free an mbuf from the lpfc_mbuf_pool PCI pool (unlocked)
443 * @phba: HBA which owns the pool to return to
444 * @virt: mbuf to free
445 * @dma: the DMA-mapped address of the lpfc_mbuf_pool to be freed
447 * Description: Returns an mbuf lpfc_mbuf_pool to the lpfc_mbuf_safety_pool if
448 * it is below its max_count, frees the mbuf otherwise.
450 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
455 lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
457 unsigned long iflags;
459 spin_lock_irqsave(&phba->hbalock, iflags);
460 __lpfc_mbuf_free(phba, virt, dma);
461 spin_unlock_irqrestore(&phba->hbalock, iflags);
466 * lpfc_nvmet_buf_alloc - Allocate an nvmet_buf from the
467 * lpfc_sg_dma_buf_pool PCI pool
468 * @phba: HBA which owns the pool to allocate from
469 * @mem_flags: indicates if this is a priority (MEM_PRI) allocation
470 * @handle: used to return the DMA-mapped address of the nvmet_buf
472 * Description: Allocates a DMA-mapped buffer from the lpfc_sg_dma_buf_pool
473 * PCI pool. Allocates from generic pci_pool_alloc function.
476 * pointer to the allocated nvmet_buf on success
480 lpfc_nvmet_buf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
484 ret = pci_pool_alloc(phba->lpfc_sg_dma_buf_pool, GFP_KERNEL, handle);
489 * lpfc_nvmet_buf_free - Free an nvmet_buf from the lpfc_sg_dma_buf_pool
491 * @phba: HBA which owns the pool to return to
492 * @virt: nvmet_buf to free
493 * @dma: the DMA-mapped address of the lpfc_sg_dma_buf_pool to be freed
498 lpfc_nvmet_buf_free(struct lpfc_hba *phba, void *virt, dma_addr_t dma)
500 pci_pool_free(phba->lpfc_sg_dma_buf_pool, virt, dma);
504 * lpfc_els_hbq_alloc - Allocate an HBQ buffer
505 * @phba: HBA to allocate HBQ buffer for
507 * Description: Allocates a DMA-mapped HBQ buffer from the lpfc_hrb_pool PCI
508 * pool along a non-DMA-mapped container for it.
510 * Notes: Not interrupt-safe. Must be called with no locks held.
513 * pointer to HBQ on success
517 lpfc_els_hbq_alloc(struct lpfc_hba *phba)
519 struct hbq_dmabuf *hbqbp;
521 hbqbp = kzalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL);
525 hbqbp->dbuf.virt = pci_pool_alloc(phba->lpfc_hbq_pool, GFP_KERNEL,
527 if (!hbqbp->dbuf.virt) {
531 hbqbp->total_size = LPFC_BPL_SIZE;
536 * lpfc_els_hbq_free - Frees an HBQ buffer allocated with lpfc_els_hbq_alloc
537 * @phba: HBA buffer was allocated for
538 * @hbqbp: HBQ container returned by lpfc_els_hbq_alloc
540 * Description: Frees both the container and the DMA-mapped buffer returned by
541 * lpfc_els_hbq_alloc.
543 * Notes: Can be called with or without locks held.
548 lpfc_els_hbq_free(struct lpfc_hba *phba, struct hbq_dmabuf *hbqbp)
550 pci_pool_free(phba->lpfc_hbq_pool, hbqbp->dbuf.virt, hbqbp->dbuf.phys);
556 * lpfc_sli4_rb_alloc - Allocate an SLI4 Receive buffer
557 * @phba: HBA to allocate a receive buffer for
559 * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
560 * pool along a non-DMA-mapped container for it.
562 * Notes: Not interrupt-safe. Must be called with no locks held.
565 * pointer to HBQ on success
569 lpfc_sli4_rb_alloc(struct lpfc_hba *phba)
571 struct hbq_dmabuf *dma_buf;
573 dma_buf = kzalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL);
577 dma_buf->hbuf.virt = pci_pool_alloc(phba->lpfc_hrb_pool, GFP_KERNEL,
578 &dma_buf->hbuf.phys);
579 if (!dma_buf->hbuf.virt) {
583 dma_buf->dbuf.virt = pci_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
584 &dma_buf->dbuf.phys);
585 if (!dma_buf->dbuf.virt) {
586 pci_pool_free(phba->lpfc_hrb_pool, dma_buf->hbuf.virt,
591 dma_buf->total_size = LPFC_DATA_BUF_SIZE;
596 * lpfc_sli4_rb_free - Frees a receive buffer
597 * @phba: HBA buffer was allocated for
598 * @dmab: DMA Buffer container returned by lpfc_sli4_hbq_alloc
600 * Description: Frees both the container and the DMA-mapped buffers returned by
601 * lpfc_sli4_rb_alloc.
603 * Notes: Can be called with or without locks held.
608 lpfc_sli4_rb_free(struct lpfc_hba *phba, struct hbq_dmabuf *dmab)
610 pci_pool_free(phba->lpfc_hrb_pool, dmab->hbuf.virt, dmab->hbuf.phys);
611 pci_pool_free(phba->lpfc_drb_pool, dmab->dbuf.virt, dmab->dbuf.phys);
616 * lpfc_sli4_nvmet_alloc - Allocate an SLI4 Receive buffer
617 * @phba: HBA to allocate a receive buffer for
619 * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
620 * pool along a non-DMA-mapped container for it.
622 * Notes: Not interrupt-safe. Must be called with no locks held.
625 * pointer to HBQ on success
629 lpfc_sli4_nvmet_alloc(struct lpfc_hba *phba)
631 struct rqb_dmabuf *dma_buf;
633 dma_buf = kzalloc(sizeof(struct rqb_dmabuf), GFP_KERNEL);
637 dma_buf->hbuf.virt = pci_pool_alloc(phba->lpfc_hrb_pool, GFP_KERNEL,
638 &dma_buf->hbuf.phys);
639 if (!dma_buf->hbuf.virt) {
643 dma_buf->dbuf.virt = pci_pool_alloc(phba->lpfc_nvmet_drb_pool,
644 GFP_KERNEL, &dma_buf->dbuf.phys);
645 if (!dma_buf->dbuf.virt) {
646 pci_pool_free(phba->lpfc_hrb_pool, dma_buf->hbuf.virt,
651 dma_buf->total_size = LPFC_NVMET_DATA_BUF_SIZE;
656 * lpfc_sli4_nvmet_free - Frees a receive buffer
657 * @phba: HBA buffer was allocated for
658 * @dmab: DMA Buffer container returned by lpfc_sli4_rbq_alloc
660 * Description: Frees both the container and the DMA-mapped buffers returned by
661 * lpfc_sli4_nvmet_alloc.
663 * Notes: Can be called with or without locks held.
668 lpfc_sli4_nvmet_free(struct lpfc_hba *phba, struct rqb_dmabuf *dmab)
670 pci_pool_free(phba->lpfc_hrb_pool, dmab->hbuf.virt, dmab->hbuf.phys);
671 pci_pool_free(phba->lpfc_nvmet_drb_pool,
672 dmab->dbuf.virt, dmab->dbuf.phys);
677 * lpfc_in_buf_free - Free a DMA buffer
678 * @phba: HBA buffer is associated with
679 * @mp: Buffer to free
681 * Description: Frees the given DMA buffer in the appropriate way given if the
682 * HBA is running in SLI3 mode with HBQs enabled.
684 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
689 lpfc_in_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp)
691 struct hbq_dmabuf *hbq_entry;
697 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
698 hbq_entry = container_of(mp, struct hbq_dmabuf, dbuf);
699 /* Check whether HBQ is still in use */
700 spin_lock_irqsave(&phba->hbalock, flags);
701 if (!phba->hbq_in_use) {
702 spin_unlock_irqrestore(&phba->hbalock, flags);
705 list_del(&hbq_entry->dbuf.list);
706 if (hbq_entry->tag == -1) {
707 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
710 lpfc_sli_free_hbq(phba, hbq_entry);
712 spin_unlock_irqrestore(&phba->hbalock, flags);
714 lpfc_mbuf_free(phba, mp->virt, mp->phys);
721 * lpfc_rq_buf_free - Free a RQ DMA buffer
722 * @phba: HBA buffer is associated with
723 * @mp: Buffer to free
725 * Description: Frees the given DMA buffer in the appropriate way given by
726 * reposting it to its associated RQ so it can be reused.
728 * Notes: Takes phba->hbalock. Can be called with or without other locks held.
733 lpfc_rq_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp)
735 struct lpfc_rqb *rqbp;
736 struct lpfc_rqe hrqe;
737 struct lpfc_rqe drqe;
738 struct rqb_dmabuf *rqb_entry;
745 rqb_entry = container_of(mp, struct rqb_dmabuf, hbuf);
746 rqbp = rqb_entry->hrq->rqbp;
748 spin_lock_irqsave(&phba->hbalock, flags);
749 list_del(&rqb_entry->hbuf.list);
750 hrqe.address_lo = putPaddrLow(rqb_entry->hbuf.phys);
751 hrqe.address_hi = putPaddrHigh(rqb_entry->hbuf.phys);
752 drqe.address_lo = putPaddrLow(rqb_entry->dbuf.phys);
753 drqe.address_hi = putPaddrHigh(rqb_entry->dbuf.phys);
754 rc = lpfc_sli4_rq_put(rqb_entry->hrq, rqb_entry->drq, &hrqe, &drqe);
756 (rqbp->rqb_free_buffer)(phba, rqb_entry);
757 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
758 "6409 Cannot post to RQ %d: %x %x\n",
759 rqb_entry->hrq->queue_id,
760 rqb_entry->hrq->host_index,
761 rqb_entry->hrq->hba_index);
763 list_add_tail(&rqb_entry->hbuf.list, &rqbp->rqb_buffer_list);
764 rqbp->buffer_count++;
767 spin_unlock_irqrestore(&phba->hbalock, flags);