Skip to content

Commit 27bc43b

Browse files
Viswas Gmartinkpetersen
authored andcommitted
scsi: pm80xx: Remove DMA memory allocation for ccb and device structures
Remove DMA memory allocation for Devices and CCB structure. Instead allocate memory outside of DMA memory. DMA memory is a limited system resource and it is better to allocate memory outside of DMA memory when possible. Link: https://lore.kernel.org/r/20201005145011.23674-3-Viswas.G@microchip.com.com Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com> Signed-off-by: Viswas G <Viswas.G@microchip.com> Signed-off-by: Ruksar Devadi <Ruksar.devadi@microchip.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 05c6c02 commit 27bc43b

2 files changed

Lines changed: 33 additions & 23 deletions

File tree

drivers/scsi/pm8001/pm8001_defs.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,23 @@ enum port_type {
9191
#define PM8001_MAX_DEVICES 2048 /* max supported device */
9292
#define PM8001_MAX_MSIX_VEC 64 /* max msi-x int for spcv/ve */
9393

94-
#define USI_MAX_MEMCNT_BASE 5
9594
#define CONFIG_SCSI_PM8001_MAX_DMA_SG 528
9695
#define PM8001_MAX_DMA_SG CONFIG_SCSI_PM8001_MAX_DMA_SG
9796
enum memory_region_num {
9897
AAP1 = 0x0, /* application acceleration processor */
9998
IOP, /* IO processor */
10099
NVMD, /* NVM device */
101-
DEV_MEM, /* memory for devices */
102-
CCB_MEM, /* memory for command control block */
103100
FW_FLASH, /* memory for fw flash update */
104-
FORENSIC_MEM /* memory for fw forensic data */
101+
FORENSIC_MEM, /* memory for fw forensic data */
102+
USI_MAX_MEMCNT_BASE
105103
};
106104
#define PM8001_EVENT_LOG_SIZE (128 * 1024)
107105

108106
/**
109107
* maximum DMA memory regions(number of IBQ + number of IBQ CI
110108
* + number of OBQ + number of OBQ PI)
111109
*/
112-
#define USI_MAX_MEMCNT (USI_MAX_MEMCNT_BASE + 1 + ((2 * PM8001_MAX_INB_NUM) \
110+
#define USI_MAX_MEMCNT (USI_MAX_MEMCNT_BASE + ((2 * PM8001_MAX_INB_NUM) \
113111
+ (2 * PM8001_MAX_OUTB_NUM)))
114112
/*error code*/
115113
enum mpi_err {

drivers/scsi/pm8001/pm8001_init.c

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
288288

289289
count = pm8001_ha->max_q_num;
290290
/* Queues are chosen based on the number of cores/msix availability */
291-
ib_offset = pm8001_ha->ib_offset = USI_MAX_MEMCNT_BASE + 1;
291+
ib_offset = pm8001_ha->ib_offset = USI_MAX_MEMCNT_BASE;
292292
ci_offset = pm8001_ha->ci_offset = ib_offset + count;
293293
ob_offset = pm8001_ha->ob_offset = ci_offset + count;
294294
pi_offset = pm8001_ha->pi_offset = ob_offset + count;
@@ -380,19 +380,6 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
380380
pm8001_ha->memoryMap.region[NVMD].num_elements = 1;
381381
pm8001_ha->memoryMap.region[NVMD].element_size = 4096;
382382
pm8001_ha->memoryMap.region[NVMD].total_len = 4096;
383-
/* Memory region for devices*/
384-
pm8001_ha->memoryMap.region[DEV_MEM].num_elements = 1;
385-
pm8001_ha->memoryMap.region[DEV_MEM].element_size = PM8001_MAX_DEVICES *
386-
sizeof(struct pm8001_device);
387-
pm8001_ha->memoryMap.region[DEV_MEM].total_len = PM8001_MAX_DEVICES *
388-
sizeof(struct pm8001_device);
389-
390-
/* Memory region for ccb_info*/
391-
pm8001_ha->memoryMap.region[CCB_MEM].num_elements = 1;
392-
pm8001_ha->memoryMap.region[CCB_MEM].element_size = PM8001_MAX_CCB *
393-
sizeof(struct pm8001_ccb_info);
394-
pm8001_ha->memoryMap.region[CCB_MEM].total_len = PM8001_MAX_CCB *
395-
sizeof(struct pm8001_ccb_info);
396383

397384
/* Memory region for fw flash */
398385
pm8001_ha->memoryMap.region[FW_FLASH].total_len = 4096;
@@ -416,18 +403,30 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
416403
}
417404
}
418405

419-
pm8001_ha->devices = pm8001_ha->memoryMap.region[DEV_MEM].virt_ptr;
406+
/* Memory region for devices*/
407+
pm8001_ha->devices = kzalloc(PM8001_MAX_DEVICES
408+
* sizeof(struct pm8001_device), GFP_KERNEL);
409+
if (!pm8001_ha->devices) {
410+
rc = -ENOMEM;
411+
goto err_out_nodev;
412+
}
420413
for (i = 0; i < PM8001_MAX_DEVICES; i++) {
421414
pm8001_ha->devices[i].dev_type = SAS_PHY_UNUSED;
422415
pm8001_ha->devices[i].id = i;
423416
pm8001_ha->devices[i].device_id = PM8001_MAX_DEVICES;
424417
pm8001_ha->devices[i].running_req = 0;
425418
}
426-
pm8001_ha->ccb_info = pm8001_ha->memoryMap.region[CCB_MEM].virt_ptr;
419+
/* Memory region for ccb_info*/
420+
pm8001_ha->ccb_info = kzalloc(PM8001_MAX_CCB
421+
* sizeof(struct pm8001_ccb_info), GFP_KERNEL);
422+
if (!pm8001_ha->ccb_info) {
423+
rc = -ENOMEM;
424+
goto err_out_noccb;
425+
}
427426
for (i = 0; i < PM8001_MAX_CCB; i++) {
428427
pm8001_ha->ccb_info[i].ccb_dma_handle =
429-
pm8001_ha->memoryMap.region[CCB_MEM].phys_addr +
430-
i * sizeof(struct pm8001_ccb_info);
428+
virt_to_phys(pm8001_ha->ccb_info) +
429+
(i * sizeof(struct pm8001_ccb_info));
431430
pm8001_ha->ccb_info[i].task = NULL;
432431
pm8001_ha->ccb_info[i].ccb_tag = 0xffffffff;
433432
pm8001_ha->ccb_info[i].device = NULL;
@@ -437,8 +436,21 @@ static int pm8001_alloc(struct pm8001_hba_info *pm8001_ha,
437436
/* Initialize tags */
438437
pm8001_tag_init(pm8001_ha);
439438
return 0;
439+
440+
err_out_noccb:
441+
kfree(pm8001_ha->devices);
440442
err_out_shost:
441443
scsi_remove_host(pm8001_ha->shost);
444+
err_out_nodev:
445+
for (i = 0; i < pm8001_ha->max_memcnt; i++) {
446+
if (pm8001_ha->memoryMap.region[i].virt_ptr != NULL) {
447+
pci_free_consistent(pm8001_ha->pdev,
448+
(pm8001_ha->memoryMap.region[i].total_len +
449+
pm8001_ha->memoryMap.region[i].alignment),
450+
pm8001_ha->memoryMap.region[i].virt_ptr,
451+
pm8001_ha->memoryMap.region[i].phys_addr);
452+
}
453+
}
442454
err_out:
443455
return 1;
444456
}

0 commit comments

Comments
 (0)