Commit c3aa570d authored by Shivasharan S's avatar Shivasharan S Committed by Greg Kroah-Hartman

scsi: megaraid_sas: Create separate functions to allocate ctrl memory

commit 49a7a4ad upstream.

No functional change. Code refactoring to improve readability.  Move the
code to allocate and free controller memory into separate functions.
Signed-off-by: default avatarKashyap Desai <kashyap.desai@broadcom.com>
Signed-off-by: default avatarShivasharan S <shivasharan.srikanteshwara@broadcom.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fda0eab8
......@@ -6016,6 +6016,75 @@ static inline void megasas_set_adapter_type(struct megasas_instance *instance)
}
}
static inline int megasas_alloc_mfi_ctrl_mem(struct megasas_instance *instance)
{
instance->producer = pci_alloc_consistent(instance->pdev, sizeof(u32),
&instance->producer_h);
instance->consumer = pci_alloc_consistent(instance->pdev, sizeof(u32),
&instance->consumer_h);
if (!instance->producer || !instance->consumer) {
dev_err(&instance->pdev->dev,
"Failed to allocate memory for producer, consumer\n");
return -1;
}
*instance->producer = 0;
*instance->consumer = 0;
return 0;
}
/**
* megasas_alloc_ctrl_mem - Allocate per controller memory for core data
* structures which are not common across MFI
* adapters and fusion adapters.
* For MFI based adapters, allocate producer and
* consumer buffers. For fusion adapters, allocate
* memory for fusion context.
* @instance: Adapter soft state
* return: 0 for SUCCESS
*/
static int megasas_alloc_ctrl_mem(struct megasas_instance *instance)
{
switch (instance->adapter_type) {
case MFI_SERIES:
if (megasas_alloc_mfi_ctrl_mem(instance))
return -ENOMEM;
break;
case VENTURA_SERIES:
case THUNDERBOLT_SERIES:
case INVADER_SERIES:
if (megasas_alloc_fusion_context(instance))
return -ENOMEM;
break;
}
return 0;
}
/*
* megasas_free_ctrl_mem - Free fusion context for fusion adapters and
* producer, consumer buffers for MFI adapters
*
* @instance - Adapter soft instance
*
*/
static inline void megasas_free_ctrl_mem(struct megasas_instance *instance)
{
if (instance->adapter_type == MFI_SERIES) {
if (instance->producer)
pci_free_consistent(instance->pdev, sizeof(u32),
instance->producer,
instance->producer_h);
if (instance->consumer)
pci_free_consistent(instance->pdev, sizeof(u32),
instance->consumer,
instance->consumer_h);
} else {
megasas_free_fusion_context(instance);
}
}
/**
* megasas_probe_one - PCI hotplug entry point
* @pdev: PCI device structure
......@@ -6074,33 +6143,8 @@ static int megasas_probe_one(struct pci_dev *pdev,
megasas_set_adapter_type(instance);
switch (instance->adapter_type) {
case MFI_SERIES:
instance->producer =
pci_alloc_consistent(pdev, sizeof(u32),
&instance->producer_h);
instance->consumer =
pci_alloc_consistent(pdev, sizeof(u32),
&instance->consumer_h);
if (!instance->producer || !instance->consumer) {
dev_printk(KERN_DEBUG, &pdev->dev, "Failed to allocate "
"memory for producer, consumer\n");
if (megasas_alloc_ctrl_mem(instance))
goto fail_alloc_dma_buf;
}
*instance->producer = 0;
*instance->consumer = 0;
break;
case VENTURA_SERIES:
case THUNDERBOLT_SERIES:
case INVADER_SERIES:
if (megasas_alloc_fusion_context(instance)) {
megasas_free_fusion_context(instance);
goto fail_alloc_dma_buf;
}
}
/* Crash dump feature related initialisation*/
instance->drv_buf_index = 0;
......@@ -6296,12 +6340,7 @@ static int megasas_probe_one(struct pci_dev *pdev,
pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
instance->tgt_prop,
instance->tgt_prop_h);
if (instance->producer)
pci_free_consistent(pdev, sizeof(u32), instance->producer,
instance->producer_h);
if (instance->consumer)
pci_free_consistent(pdev, sizeof(u32), instance->consumer,
instance->consumer_h);
megasas_free_ctrl_mem(instance);
scsi_host_put(host);
fail_alloc_instance:
......@@ -6572,12 +6611,8 @@ megasas_resume(struct pci_dev *pdev)
pci_free_consistent(pdev, sizeof(struct MR_TARGET_PROPERTIES),
instance->tgt_prop,
instance->tgt_prop_h);
if (instance->producer)
pci_free_consistent(pdev, sizeof(u32), instance->producer,
instance->producer_h);
if (instance->consumer)
pci_free_consistent(pdev, sizeof(u32), instance->consumer,
instance->consumer_h);
megasas_free_ctrl_mem(instance);
scsi_host_put(host);
fail_set_dma_mask:
......@@ -6718,15 +6753,8 @@ static void megasas_detach_one(struct pci_dev *pdev)
fusion->pd_seq_sync[i],
fusion->pd_seq_phys[i]);
}
megasas_free_fusion_context(instance);
} else {
megasas_release_mfi(instance);
pci_free_consistent(pdev, sizeof(u32),
instance->producer,
instance->producer_h);
pci_free_consistent(pdev, sizeof(u32),
instance->consumer,
instance->consumer_h);
}
kfree(instance->ctrl_info);
......@@ -6767,6 +6795,8 @@ static void megasas_detach_one(struct pci_dev *pdev)
pci_free_consistent(pdev, sizeof(struct MR_DRV_SYSTEM_INFO),
instance->system_info_buf, instance->system_info_h);
megasas_free_ctrl_mem(instance);
scsi_host_put(host);
pci_disable_device(pdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment