This source file includes following definitions.
- lpfc_mem_alloc_active_rrq_pool_s4
- lpfc_mem_alloc
- lpfc_nvmet_mem_alloc
- lpfc_mem_free
- lpfc_mem_free_all
- lpfc_mbuf_alloc
- __lpfc_mbuf_free
- lpfc_mbuf_free
- lpfc_nvmet_buf_alloc
- lpfc_nvmet_buf_free
- lpfc_els_hbq_alloc
- lpfc_els_hbq_free
- lpfc_sli4_rb_alloc
- lpfc_sli4_rb_free
- lpfc_sli4_nvmet_alloc
- lpfc_sli4_nvmet_free
- lpfc_in_buf_free
- lpfc_rq_buf_free
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <linux/mempool.h>
25 #include <linux/slab.h>
26 #include <linux/pci.h>
27 #include <linux/interrupt.h>
28
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>
33
34 #include <linux/nvme-fc-driver.h>
35
36 #include "lpfc_hw4.h"
37 #include "lpfc_hw.h"
38 #include "lpfc_sli.h"
39 #include "lpfc_sli4.h"
40 #include "lpfc_nl.h"
41 #include "lpfc_disc.h"
42 #include "lpfc.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"
48
49 #define LPFC_MBUF_POOL_SIZE 64
50 #define LPFC_MEM_POOL_SIZE 64
51 #define LPFC_DEVICE_DATA_POOL_SIZE 64
52
53 int
54 lpfc_mem_alloc_active_rrq_pool_s4(struct lpfc_hba *phba) {
55 size_t bytes;
56 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
57
58 if (max_xri <= 0)
59 return -ENOMEM;
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,
64 bytes);
65 if (!phba->active_rrq_pool)
66 return -ENOMEM;
67 else
68 return 0;
69 }
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 int
87 lpfc_mem_alloc(struct lpfc_hba *phba, int align)
88 {
89 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
90 int i;
91
92
93 phba->lpfc_mbuf_pool = dma_pool_create("lpfc_mbuf_pool", &phba->pcidev->dev,
94 LPFC_BPL_SIZE,
95 align, 0);
96 if (!phba->lpfc_mbuf_pool)
97 goto fail;
98
99 pool->elements = kmalloc_array(LPFC_MBUF_POOL_SIZE,
100 sizeof(struct lpfc_dmabuf),
101 GFP_KERNEL);
102 if (!pool->elements)
103 goto fail_free_lpfc_mbuf_pool;
104
105 pool->max_count = 0;
106 pool->current_count = 0;
107 for ( i = 0; i < LPFC_MBUF_POOL_SIZE; i++) {
108 pool->elements[i].virt = dma_pool_alloc(phba->lpfc_mbuf_pool,
109 GFP_KERNEL, &pool->elements[i].phys);
110 if (!pool->elements[i].virt)
111 goto fail_free_mbuf_pool;
112 pool->max_count++;
113 pool->current_count++;
114 }
115
116 phba->mbox_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
117 sizeof(LPFC_MBOXQ_t));
118 if (!phba->mbox_mem_pool)
119 goto fail_free_mbuf_pool;
120
121 phba->nlp_mem_pool = mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
122 sizeof(struct lpfc_nodelist));
123 if (!phba->nlp_mem_pool)
124 goto fail_free_mbox_pool;
125
126 if (phba->sli_rev == LPFC_SLI_REV4) {
127 phba->rrq_pool =
128 mempool_create_kmalloc_pool(LPFC_MEM_POOL_SIZE,
129 sizeof(struct lpfc_node_rrq));
130 if (!phba->rrq_pool)
131 goto fail_free_nlp_mem_pool;
132 phba->lpfc_hrb_pool = dma_pool_create("lpfc_hrb_pool",
133 &phba->pcidev->dev,
134 LPFC_HDR_BUF_SIZE, align, 0);
135 if (!phba->lpfc_hrb_pool)
136 goto fail_free_rrq_mem_pool;
137
138 phba->lpfc_drb_pool = dma_pool_create("lpfc_drb_pool",
139 &phba->pcidev->dev,
140 LPFC_DATA_BUF_SIZE, align, 0);
141 if (!phba->lpfc_drb_pool)
142 goto fail_free_hrb_pool;
143 phba->lpfc_hbq_pool = NULL;
144 } else {
145 phba->lpfc_hbq_pool = dma_pool_create("lpfc_hbq_pool",
146 &phba->pcidev->dev, LPFC_BPL_SIZE, align, 0);
147 if (!phba->lpfc_hbq_pool)
148 goto fail_free_nlp_mem_pool;
149 phba->lpfc_hrb_pool = NULL;
150 phba->lpfc_drb_pool = NULL;
151 }
152
153 if (phba->cfg_EnableXLane) {
154 phba->device_data_mem_pool = mempool_create_kmalloc_pool(
155 LPFC_DEVICE_DATA_POOL_SIZE,
156 sizeof(struct lpfc_device_data));
157 if (!phba->device_data_mem_pool)
158 goto fail_free_drb_pool;
159 } else {
160 phba->device_data_mem_pool = NULL;
161 }
162
163 return 0;
164 fail_free_drb_pool:
165 dma_pool_destroy(phba->lpfc_drb_pool);
166 phba->lpfc_drb_pool = NULL;
167 fail_free_hrb_pool:
168 dma_pool_destroy(phba->lpfc_hrb_pool);
169 phba->lpfc_hrb_pool = NULL;
170 fail_free_rrq_mem_pool:
171 mempool_destroy(phba->rrq_pool);
172 phba->rrq_pool = NULL;
173 fail_free_nlp_mem_pool:
174 mempool_destroy(phba->nlp_mem_pool);
175 phba->nlp_mem_pool = NULL;
176 fail_free_mbox_pool:
177 mempool_destroy(phba->mbox_mem_pool);
178 phba->mbox_mem_pool = NULL;
179 fail_free_mbuf_pool:
180 while (i--)
181 dma_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
182 pool->elements[i].phys);
183 kfree(pool->elements);
184 fail_free_lpfc_mbuf_pool:
185 dma_pool_destroy(phba->lpfc_mbuf_pool);
186 phba->lpfc_mbuf_pool = NULL;
187 fail:
188 return -ENOMEM;
189 }
190
191 int
192 lpfc_nvmet_mem_alloc(struct lpfc_hba *phba)
193 {
194 phba->lpfc_nvmet_drb_pool =
195 dma_pool_create("lpfc_nvmet_drb_pool",
196 &phba->pcidev->dev, LPFC_NVMET_DATA_BUF_SIZE,
197 SGL_ALIGN_SZ, 0);
198 if (!phba->lpfc_nvmet_drb_pool) {
199 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
200 "6024 Can't enable NVME Target - no memory\n");
201 return -ENOMEM;
202 }
203 return 0;
204 }
205
206
207
208
209
210
211
212
213
214
215 void
216 lpfc_mem_free(struct lpfc_hba *phba)
217 {
218 int i;
219 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
220 struct lpfc_device_data *device_data;
221
222
223 lpfc_sli_hbqbuf_free_all(phba);
224 dma_pool_destroy(phba->lpfc_nvmet_drb_pool);
225 phba->lpfc_nvmet_drb_pool = NULL;
226
227 dma_pool_destroy(phba->lpfc_drb_pool);
228 phba->lpfc_drb_pool = NULL;
229
230 dma_pool_destroy(phba->lpfc_hrb_pool);
231 phba->lpfc_hrb_pool = NULL;
232
233 dma_pool_destroy(phba->txrdy_payload_pool);
234 phba->txrdy_payload_pool = NULL;
235
236 dma_pool_destroy(phba->lpfc_hbq_pool);
237 phba->lpfc_hbq_pool = NULL;
238
239 mempool_destroy(phba->rrq_pool);
240 phba->rrq_pool = NULL;
241
242
243 mempool_destroy(phba->nlp_mem_pool);
244 phba->nlp_mem_pool = NULL;
245 if (phba->sli_rev == LPFC_SLI_REV4 && phba->active_rrq_pool) {
246 mempool_destroy(phba->active_rrq_pool);
247 phba->active_rrq_pool = NULL;
248 }
249
250
251 mempool_destroy(phba->mbox_mem_pool);
252 phba->mbox_mem_pool = NULL;
253
254
255 for (i = 0; i < pool->current_count; i++)
256 dma_pool_free(phba->lpfc_mbuf_pool, pool->elements[i].virt,
257 pool->elements[i].phys);
258 kfree(pool->elements);
259
260 dma_pool_destroy(phba->lpfc_mbuf_pool);
261 phba->lpfc_mbuf_pool = NULL;
262
263
264 if (phba->device_data_mem_pool) {
265
266 while (!list_empty(&phba->luns)) {
267 device_data = list_first_entry(&phba->luns,
268 struct lpfc_device_data,
269 listentry);
270 list_del(&device_data->listentry);
271 mempool_free(device_data, phba->device_data_mem_pool);
272 }
273 mempool_destroy(phba->device_data_mem_pool);
274 }
275 phba->device_data_mem_pool = NULL;
276 return;
277 }
278
279
280
281
282
283
284
285
286
287
288
289
290 void
291 lpfc_mem_free_all(struct lpfc_hba *phba)
292 {
293 struct lpfc_sli *psli = &phba->sli;
294 LPFC_MBOXQ_t *mbox, *next_mbox;
295 struct lpfc_dmabuf *mp;
296
297
298 list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq, list) {
299 mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
300 if (mp) {
301 lpfc_mbuf_free(phba, mp->virt, mp->phys);
302 kfree(mp);
303 }
304 list_del(&mbox->list);
305 mempool_free(mbox, phba->mbox_mem_pool);
306 }
307
308 list_for_each_entry_safe(mbox, next_mbox, &psli->mboxq_cmpl, list) {
309 mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
310 if (mp) {
311 lpfc_mbuf_free(phba, mp->virt, mp->phys);
312 kfree(mp);
313 }
314 list_del(&mbox->list);
315 mempool_free(mbox, phba->mbox_mem_pool);
316 }
317
318 spin_lock_irq(&phba->hbalock);
319 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
320 spin_unlock_irq(&phba->hbalock);
321 if (psli->mbox_active) {
322 mbox = psli->mbox_active;
323 mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
324 if (mp) {
325 lpfc_mbuf_free(phba, mp->virt, mp->phys);
326 kfree(mp);
327 }
328 mempool_free(mbox, phba->mbox_mem_pool);
329 psli->mbox_active = NULL;
330 }
331
332
333 lpfc_mem_free(phba);
334
335
336 dma_pool_destroy(phba->lpfc_sg_dma_buf_pool);
337 phba->lpfc_sg_dma_buf_pool = NULL;
338
339 dma_pool_destroy(phba->lpfc_cmd_rsp_buf_pool);
340 phba->lpfc_cmd_rsp_buf_pool = NULL;
341
342
343 kfree(psli->iocbq_lookup);
344 psli->iocbq_lookup = NULL;
345
346 return;
347 }
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367 void *
368 lpfc_mbuf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
369 {
370 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
371 unsigned long iflags;
372 void *ret;
373
374 ret = dma_pool_alloc(phba->lpfc_mbuf_pool, GFP_KERNEL, handle);
375
376 spin_lock_irqsave(&phba->hbalock, iflags);
377 if (!ret && (mem_flags & MEM_PRI) && pool->current_count) {
378 pool->current_count--;
379 ret = pool->elements[pool->current_count].virt;
380 *handle = pool->elements[pool->current_count].phys;
381 }
382 spin_unlock_irqrestore(&phba->hbalock, iflags);
383 return ret;
384 }
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400 void
401 __lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
402 {
403 struct lpfc_dma_pool *pool = &phba->lpfc_mbuf_safety_pool;
404
405 if (pool->current_count < pool->max_count) {
406 pool->elements[pool->current_count].virt = virt;
407 pool->elements[pool->current_count].phys = dma;
408 pool->current_count++;
409 } else {
410 dma_pool_free(phba->lpfc_mbuf_pool, virt, dma);
411 }
412 return;
413 }
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428 void
429 lpfc_mbuf_free(struct lpfc_hba * phba, void *virt, dma_addr_t dma)
430 {
431 unsigned long iflags;
432
433 spin_lock_irqsave(&phba->hbalock, iflags);
434 __lpfc_mbuf_free(phba, virt, dma);
435 spin_unlock_irqrestore(&phba->hbalock, iflags);
436 return;
437 }
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453 void *
454 lpfc_nvmet_buf_alloc(struct lpfc_hba *phba, int mem_flags, dma_addr_t *handle)
455 {
456 void *ret;
457
458 ret = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool, GFP_KERNEL, handle);
459 return ret;
460 }
461
462
463
464
465
466
467
468
469
470
471 void
472 lpfc_nvmet_buf_free(struct lpfc_hba *phba, void *virt, dma_addr_t dma)
473 {
474 dma_pool_free(phba->lpfc_sg_dma_buf_pool, virt, dma);
475 }
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490 struct hbq_dmabuf *
491 lpfc_els_hbq_alloc(struct lpfc_hba *phba)
492 {
493 struct hbq_dmabuf *hbqbp;
494
495 hbqbp = kzalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL);
496 if (!hbqbp)
497 return NULL;
498
499 hbqbp->dbuf.virt = dma_pool_alloc(phba->lpfc_hbq_pool, GFP_KERNEL,
500 &hbqbp->dbuf.phys);
501 if (!hbqbp->dbuf.virt) {
502 kfree(hbqbp);
503 return NULL;
504 }
505 hbqbp->total_size = LPFC_BPL_SIZE;
506 return hbqbp;
507 }
508
509
510
511
512
513
514
515
516
517
518
519
520
521 void
522 lpfc_els_hbq_free(struct lpfc_hba *phba, struct hbq_dmabuf *hbqbp)
523 {
524 dma_pool_free(phba->lpfc_hbq_pool, hbqbp->dbuf.virt, hbqbp->dbuf.phys);
525 kfree(hbqbp);
526 return;
527 }
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542 struct hbq_dmabuf *
543 lpfc_sli4_rb_alloc(struct lpfc_hba *phba)
544 {
545 struct hbq_dmabuf *dma_buf;
546
547 dma_buf = kzalloc(sizeof(struct hbq_dmabuf), GFP_KERNEL);
548 if (!dma_buf)
549 return NULL;
550
551 dma_buf->hbuf.virt = dma_pool_alloc(phba->lpfc_hrb_pool, GFP_KERNEL,
552 &dma_buf->hbuf.phys);
553 if (!dma_buf->hbuf.virt) {
554 kfree(dma_buf);
555 return NULL;
556 }
557 dma_buf->dbuf.virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
558 &dma_buf->dbuf.phys);
559 if (!dma_buf->dbuf.virt) {
560 dma_pool_free(phba->lpfc_hrb_pool, dma_buf->hbuf.virt,
561 dma_buf->hbuf.phys);
562 kfree(dma_buf);
563 return NULL;
564 }
565 dma_buf->total_size = LPFC_DATA_BUF_SIZE;
566 return dma_buf;
567 }
568
569
570
571
572
573
574
575
576
577
578
579
580
581 void
582 lpfc_sli4_rb_free(struct lpfc_hba *phba, struct hbq_dmabuf *dmab)
583 {
584 dma_pool_free(phba->lpfc_hrb_pool, dmab->hbuf.virt, dmab->hbuf.phys);
585 dma_pool_free(phba->lpfc_drb_pool, dmab->dbuf.virt, dmab->dbuf.phys);
586 kfree(dmab);
587 }
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602 struct rqb_dmabuf *
603 lpfc_sli4_nvmet_alloc(struct lpfc_hba *phba)
604 {
605 struct rqb_dmabuf *dma_buf;
606
607 dma_buf = kzalloc(sizeof(struct rqb_dmabuf), GFP_KERNEL);
608 if (!dma_buf)
609 return NULL;
610
611 dma_buf->hbuf.virt = dma_pool_alloc(phba->lpfc_hrb_pool, GFP_KERNEL,
612 &dma_buf->hbuf.phys);
613 if (!dma_buf->hbuf.virt) {
614 kfree(dma_buf);
615 return NULL;
616 }
617 dma_buf->dbuf.virt = dma_pool_alloc(phba->lpfc_nvmet_drb_pool,
618 GFP_KERNEL, &dma_buf->dbuf.phys);
619 if (!dma_buf->dbuf.virt) {
620 dma_pool_free(phba->lpfc_hrb_pool, dma_buf->hbuf.virt,
621 dma_buf->hbuf.phys);
622 kfree(dma_buf);
623 return NULL;
624 }
625 dma_buf->total_size = LPFC_NVMET_DATA_BUF_SIZE;
626 return dma_buf;
627 }
628
629
630
631
632
633
634
635
636
637
638
639
640
641 void
642 lpfc_sli4_nvmet_free(struct lpfc_hba *phba, struct rqb_dmabuf *dmab)
643 {
644 dma_pool_free(phba->lpfc_hrb_pool, dmab->hbuf.virt, dmab->hbuf.phys);
645 dma_pool_free(phba->lpfc_nvmet_drb_pool,
646 dmab->dbuf.virt, dmab->dbuf.phys);
647 kfree(dmab);
648 }
649
650
651
652
653
654
655
656
657
658
659
660
661
662 void
663 lpfc_in_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp)
664 {
665 struct hbq_dmabuf *hbq_entry;
666 unsigned long flags;
667
668 if (!mp)
669 return;
670
671 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
672 hbq_entry = container_of(mp, struct hbq_dmabuf, dbuf);
673
674 spin_lock_irqsave(&phba->hbalock, flags);
675 if (!phba->hbq_in_use) {
676 spin_unlock_irqrestore(&phba->hbalock, flags);
677 return;
678 }
679 list_del(&hbq_entry->dbuf.list);
680 if (hbq_entry->tag == -1) {
681 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
682 (phba, hbq_entry);
683 } else {
684 lpfc_sli_free_hbq(phba, hbq_entry);
685 }
686 spin_unlock_irqrestore(&phba->hbalock, flags);
687 } else {
688 lpfc_mbuf_free(phba, mp->virt, mp->phys);
689 kfree(mp);
690 }
691 return;
692 }
693
694
695
696
697
698
699
700
701
702
703
704
705
706 void
707 lpfc_rq_buf_free(struct lpfc_hba *phba, struct lpfc_dmabuf *mp)
708 {
709 struct lpfc_rqb *rqbp;
710 struct lpfc_rqe hrqe;
711 struct lpfc_rqe drqe;
712 struct rqb_dmabuf *rqb_entry;
713 unsigned long flags;
714 int rc;
715
716 if (!mp)
717 return;
718
719 rqb_entry = container_of(mp, struct rqb_dmabuf, hbuf);
720 rqbp = rqb_entry->hrq->rqbp;
721
722 spin_lock_irqsave(&phba->hbalock, flags);
723 list_del(&rqb_entry->hbuf.list);
724 hrqe.address_lo = putPaddrLow(rqb_entry->hbuf.phys);
725 hrqe.address_hi = putPaddrHigh(rqb_entry->hbuf.phys);
726 drqe.address_lo = putPaddrLow(rqb_entry->dbuf.phys);
727 drqe.address_hi = putPaddrHigh(rqb_entry->dbuf.phys);
728 rc = lpfc_sli4_rq_put(rqb_entry->hrq, rqb_entry->drq, &hrqe, &drqe);
729 if (rc < 0) {
730 (rqbp->rqb_free_buffer)(phba, rqb_entry);
731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
732 "6409 Cannot post to HRQ %d: %x %x %x "
733 "DRQ %x %x\n",
734 rqb_entry->hrq->queue_id,
735 rqb_entry->hrq->host_index,
736 rqb_entry->hrq->hba_index,
737 rqb_entry->hrq->entry_count,
738 rqb_entry->drq->host_index,
739 rqb_entry->drq->hba_index);
740 } else {
741 list_add_tail(&rqb_entry->hbuf.list, &rqbp->rqb_buffer_list);
742 rqbp->buffer_count++;
743 }
744
745 spin_unlock_irqrestore(&phba->hbalock, flags);
746 }