forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/scsi/lpfc/lpfc_mem.c
....@@ -31,8 +31,6 @@
3131 #include <scsi/scsi_transport_fc.h>
3232 #include <scsi/fc/fc_fs.h>
3333
34
-#include <linux/nvme-fc-driver.h>
35
-
3634 #include "lpfc_hw4.h"
3735 #include "lpfc_hw.h"
3836 #include "lpfc_sli.h"
....@@ -41,14 +39,14 @@
4139 #include "lpfc_disc.h"
4240 #include "lpfc.h"
4341 #include "lpfc_scsi.h"
44
-#include "lpfc_nvme.h"
45
-#include "lpfc_nvmet.h"
4642 #include "lpfc_crtn.h"
4743 #include "lpfc_logmsg.h"
4844
4945 #define LPFC_MBUF_POOL_SIZE 64 /* max elements in MBUF safety pool */
5046 #define LPFC_MEM_POOL_SIZE 64 /* max elem in non-DMA safety pool */
5147 #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 */
5250
5351 int
5452 lpfc_mem_alloc_active_rrq_pool_s4(struct lpfc_hba *phba) {
....@@ -71,9 +69,10 @@
7169 /**
7270 * lpfc_mem_alloc - create and allocate all PCI and memory pools
7371 * @phba: HBA to allocate pools for
72
+ * @align: alignment requirement for blocks; must be a power of two
7473 *
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
74
+ * Description: Creates and allocates PCI pools lpfc_mbuf_pool,
75
+ * lpfc_hrb_pool. Creates and allocates kmalloc-backed mempools
7776 * for LPFC_MBOXQ_t and lpfc_nodelist. Also allocates the VPI bitmask.
7877 *
7978 * Notes: Not interrupt-safe. Must be called with no locks held. If any
....@@ -89,36 +88,12 @@
8988 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
9089 int i;
9190
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;
96
- else
97
- i = SLI4_PAGE_SIZE;
98
-
99
- phba->lpfc_sg_dma_buf_pool =
100
- dma_pool_create("lpfc_sg_dma_buf_pool",
101
- &phba->pcidev->dev,
102
- phba->cfg_sg_dma_buf_size,
103
- i, 0);
104
- if (!phba->lpfc_sg_dma_buf_pool)
105
- goto fail;
106
-
107
- } else {
108
- phba->lpfc_sg_dma_buf_pool =
109
- dma_pool_create("lpfc_sg_dma_buf_pool",
110
- &phba->pcidev->dev, phba->cfg_sg_dma_buf_size,
111
- align, 0);
112
-
113
- if (!phba->lpfc_sg_dma_buf_pool)
114
- goto fail;
115
- }
11691
11792 phba->lpfc_mbuf_pool = dma_pool_create("lpfc_mbuf_pool", &phba->pcidev->dev,
11893 LPFC_BPL_SIZE,
11994 align, 0);
12095 if (!phba->lpfc_mbuf_pool)
121
- goto fail_free_dma_buf_pool;
96
+ goto fail;
12297
12398 pool->elements = kmalloc_array(LPFC_MBUF_POOL_SIZE,
12499 sizeof(struct lpfc_dmabuf),
....@@ -137,8 +112,8 @@
137112 pool->current_count++;
138113 }
139114
140
- phba->mbox_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
141
- sizeof(LPFC_MBOXQ_t));
115
+ phba->mbox_mem_pool = mempool_create_kmalloc_pool(LPFC_MBX_POOL_SIZE,
116
+ sizeof(LPFC_MBOXQ_t));
142117 if (!phba->mbox_mem_pool)
143118 goto fail_free_mbuf_pool;
144119
....@@ -149,7 +124,7 @@
149124
150125 if (phba->sli_rev == LPFC_SLI_REV4) {
151126 phba->rrq_pool =
152
- mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
127
+ mempool_create_kmalloc_pool(LPFC_RRQ_POOL_SIZE,
153128 sizeof(struct lpfc_node_rrq));
154129 if (!phba->rrq_pool)
155130 goto fail_free_nlp_mem_pool;
....@@ -208,9 +183,6 @@
208183 fail_free_lpfc_mbuf_pool:
209184 dma_pool_destroy(phba->lpfc_mbuf_pool);
210185 phba->lpfc_mbuf_pool = NULL;
211
- fail_free_dma_buf_pool:
212
- dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
213
- phba->lpfc_sg_dma_buf_pool = NULL;
214186 fail:
215187 return -ENOMEM;
216188 }
....@@ -248,25 +220,19 @@
248220
249221 /* Free HBQ pools */
250222 lpfc_sli_hbqbuf_free_all(phba);
251
- if (phba->lpfc_nvmet_drb_pool)
252
- dma_pool_destroy(phba->lpfc_nvmet_drb_pool);
223
+ dma_pool_destroy(phba->lpfc_nvmet_drb_pool);
253224 phba->lpfc_nvmet_drb_pool = NULL;
254
- if (phba->lpfc_drb_pool)
255
- dma_pool_destroy(phba->lpfc_drb_pool);
256
- phba->lpfc_drb_pool = NULL;
257
- if (phba->lpfc_hrb_pool)
258
- dma_pool_destroy(phba->lpfc_hrb_pool);
259
- phba->lpfc_hrb_pool = NULL;
260
- if (phba->txrdy_payload_pool)
261
- dma_pool_destroy(phba->txrdy_payload_pool);
262
- phba->txrdy_payload_pool = NULL;
263225
264
- if (phba->lpfc_hbq_pool)
265
- dma_pool_destroy(phba->lpfc_hbq_pool);
226
+ dma_pool_destroy(phba->lpfc_drb_pool);
227
+ phba->lpfc_drb_pool = NULL;
228
+
229
+ dma_pool_destroy(phba->lpfc_hrb_pool);
230
+ phba->lpfc_hrb_pool = NULL;
231
+
232
+ dma_pool_destroy(phba->lpfc_hbq_pool);
266233 phba->lpfc_hbq_pool = NULL;
267234
268
- if (phba->rrq_pool)
269
- mempool_destroy(phba->rrq_pool);
235
+ mempool_destroy(phba->rrq_pool);
270236 phba->rrq_pool = NULL;
271237
272238 /* Free NLP memory pool */
....@@ -289,10 +255,6 @@
289255
290256 dma_pool_destroy(phba->lpfc_mbuf_pool);
291257 phba->lpfc_mbuf_pool = NULL;
292
-
293
- /* Free DMA buffer memory pool */
294
- dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
295
- phba->lpfc_sg_dma_buf_pool = NULL;
296258
297259 /* Free Device Data memory pool */
298260 if (phba->device_data_mem_pool) {
....@@ -330,7 +292,7 @@
330292
331293 /* Free memory used in mailbox queue back to mailbox memory pool */
332294 list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) {
333
- mp = (struct lpfc_dmabuf *) (mbox->context1);
295
+ mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
334296 if (mp) {
335297 lpfc_mbuf_free(phba, mp->virt, mp->phys);
336298 kfree(mp);
....@@ -340,7 +302,7 @@
340302 }
341303 /* Free memory used in mailbox cmpl list back to mailbox memory pool */
342304 list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq_cmpl, list) {
343
- mp = (struct lpfc_dmabuf *) (mbox->context1);
305
+ mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
344306 if (mp) {
345307 lpfc_mbuf_free(phba, mp->virt, mp->phys);
346308 kfree(mp);
....@@ -354,7 +316,7 @@
354316 spin_unlock_irq(&phba->hbalock);
355317 if (psli->mbox_active) {
356318 mbox = psli->mbox_active;
357
- mp = (struct lpfc_dmabuf *) (mbox->context1);
319
+ mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
358320 if (mp) {
359321 lpfc_mbuf_free(phba, mp->virt, mp->phys);
360322 kfree(mp);
....@@ -365,6 +327,13 @@
365327
366328 /* Free and destroy all the allocated memory pools */
367329 lpfc_mem_free(phba);
330
+
331
+ /* Free DMA buffer memory pool */
332
+ dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
333
+ phba->lpfc_sg_dma_buf_pool = NULL;
334
+
335
+ dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
336
+ phba->lpfc_cmd_rsp_buf_pool = NULL;
368337
369338 /* Free the iocb lookup array */
370339 kfree(psli->iocbq_lookup);
....@@ -560,6 +529,8 @@
560529 * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
561530 * pool along a non-DMA-mapped container for it.
562531 *
532
+ * Notes: Not interrupt-safe. Must be called with no locks held.
533
+ *
563534 * Returns:
564535 * pointer to HBQ on success
565536 * NULL on failure
....@@ -617,8 +588,6 @@
617588 *
618589 * Description: Allocates a DMA-mapped receive buffer from the lpfc_hrb_pool PCI
619590 * pool along a non-DMA-mapped container for it.
620
- *
621
- * Notes: Not interrupt-safe. Must be called with no locks held.
622591 *
623592 * Returns:
624593 * pointer to HBQ on success