diff options
author | Stephen M. Cameron <scameron@beardog.cce.hp.com> | 2011-05-03 15:59:20 -0400 |
---|---|---|
committer | James Bottomley <jbottomley@parallels.com> | 2011-05-17 03:05:03 -0400 |
commit | 2e9d1b3626c4383362df30bb853a1b57c2798300 (patch) | |
tree | 21804bd688afc2cd8815ca67cf078cb90084dbd6 /drivers/scsi/hpsa.c | |
parent | 516fda49e8596904a741693059c8746f11ce579c (diff) |
[SCSI] hpsa: factor out cmd pool allocation functions
Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: James Bottomley <jbottomley@parallels.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/hpsa.c')
-rw-r--r-- | drivers/scsi/hpsa.c | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c index 2aeb21094b45..7336f3ce0d10 100644 --- a/drivers/scsi/hpsa.c +++ b/drivers/scsi/hpsa.c | |||
@@ -3847,6 +3847,40 @@ static __devinit int hpsa_init_reset_devices(struct pci_dev *pdev) | |||
3847 | return 0; | 3847 | return 0; |
3848 | } | 3848 | } |
3849 | 3849 | ||
3850 | static __devinit int hpsa_allocate_cmd_pool(struct ctlr_info *h) | ||
3851 | { | ||
3852 | h->cmd_pool_bits = kzalloc( | ||
3853 | DIV_ROUND_UP(h->nr_cmds, BITS_PER_LONG) * | ||
3854 | sizeof(unsigned long), GFP_KERNEL); | ||
3855 | h->cmd_pool = pci_alloc_consistent(h->pdev, | ||
3856 | h->nr_cmds * sizeof(*h->cmd_pool), | ||
3857 | &(h->cmd_pool_dhandle)); | ||
3858 | h->errinfo_pool = pci_alloc_consistent(h->pdev, | ||
3859 | h->nr_cmds * sizeof(*h->errinfo_pool), | ||
3860 | &(h->errinfo_pool_dhandle)); | ||
3861 | if ((h->cmd_pool_bits == NULL) | ||
3862 | || (h->cmd_pool == NULL) | ||
3863 | || (h->errinfo_pool == NULL)) { | ||
3864 | dev_err(&h->pdev->dev, "out of memory in %s", __func__); | ||
3865 | return -ENOMEM; | ||
3866 | } | ||
3867 | return 0; | ||
3868 | } | ||
3869 | |||
3870 | static void hpsa_free_cmd_pool(struct ctlr_info *h) | ||
3871 | { | ||
3872 | kfree(h->cmd_pool_bits); | ||
3873 | if (h->cmd_pool) | ||
3874 | pci_free_consistent(h->pdev, | ||
3875 | h->nr_cmds * sizeof(struct CommandList), | ||
3876 | h->cmd_pool, h->cmd_pool_dhandle); | ||
3877 | if (h->errinfo_pool) | ||
3878 | pci_free_consistent(h->pdev, | ||
3879 | h->nr_cmds * sizeof(struct ErrorInfo), | ||
3880 | h->errinfo_pool, | ||
3881 | h->errinfo_pool_dhandle); | ||
3882 | } | ||
3883 | |||
3850 | static int __devinit hpsa_init_one(struct pci_dev *pdev, | 3884 | static int __devinit hpsa_init_one(struct pci_dev *pdev, |
3851 | const struct pci_device_id *ent) | 3885 | const struct pci_device_id *ent) |
3852 | { | 3886 | { |
@@ -3917,33 +3951,14 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev, | |||
3917 | dev_info(&pdev->dev, "%s: <0x%x> at IRQ %d%s using DAC\n", | 3951 | dev_info(&pdev->dev, "%s: <0x%x> at IRQ %d%s using DAC\n", |
3918 | h->devname, pdev->device, | 3952 | h->devname, pdev->device, |
3919 | h->intr[h->intr_mode], dac ? "" : " not"); | 3953 | h->intr[h->intr_mode], dac ? "" : " not"); |
3920 | 3954 | if (hpsa_allocate_cmd_pool(h)) | |
3921 | h->cmd_pool_bits = | ||
3922 | kmalloc(((h->nr_cmds + BITS_PER_LONG - | ||
3923 | 1) / BITS_PER_LONG) * sizeof(unsigned long), GFP_KERNEL); | ||
3924 | h->cmd_pool = pci_alloc_consistent(h->pdev, | ||
3925 | h->nr_cmds * sizeof(*h->cmd_pool), | ||
3926 | &(h->cmd_pool_dhandle)); | ||
3927 | h->errinfo_pool = pci_alloc_consistent(h->pdev, | ||
3928 | h->nr_cmds * sizeof(*h->errinfo_pool), | ||
3929 | &(h->errinfo_pool_dhandle)); | ||
3930 | if ((h->cmd_pool_bits == NULL) | ||
3931 | || (h->cmd_pool == NULL) | ||
3932 | || (h->errinfo_pool == NULL)) { | ||
3933 | dev_err(&pdev->dev, "out of memory"); | ||
3934 | rc = -ENOMEM; | ||
3935 | goto clean4; | 3955 | goto clean4; |
3936 | } | ||
3937 | if (hpsa_allocate_sg_chain_blocks(h)) | 3956 | if (hpsa_allocate_sg_chain_blocks(h)) |
3938 | goto clean4; | 3957 | goto clean4; |
3939 | init_waitqueue_head(&h->scan_wait_queue); | 3958 | init_waitqueue_head(&h->scan_wait_queue); |
3940 | h->scan_finished = 1; /* no scan currently in progress */ | 3959 | h->scan_finished = 1; /* no scan currently in progress */ |
3941 | 3960 | ||
3942 | pci_set_drvdata(pdev, h); | 3961 | pci_set_drvdata(pdev, h); |
3943 | memset(h->cmd_pool_bits, 0, | ||
3944 | ((h->nr_cmds + BITS_PER_LONG - | ||
3945 | 1) / BITS_PER_LONG) * sizeof(unsigned long)); | ||
3946 | |||
3947 | hpsa_scsi_setup(h); | 3962 | hpsa_scsi_setup(h); |
3948 | 3963 | ||
3949 | /* Turn the interrupts on so we can service requests */ | 3964 | /* Turn the interrupts on so we can service requests */ |
@@ -3957,16 +3972,7 @@ static int __devinit hpsa_init_one(struct pci_dev *pdev, | |||
3957 | 3972 | ||
3958 | clean4: | 3973 | clean4: |
3959 | hpsa_free_sg_chain_blocks(h); | 3974 | hpsa_free_sg_chain_blocks(h); |
3960 | kfree(h->cmd_pool_bits); | 3975 | hpsa_free_cmd_pool(h); |
3961 | if (h->cmd_pool) | ||
3962 | pci_free_consistent(h->pdev, | ||
3963 | h->nr_cmds * sizeof(struct CommandList), | ||
3964 | h->cmd_pool, h->cmd_pool_dhandle); | ||
3965 | if (h->errinfo_pool) | ||
3966 | pci_free_consistent(h->pdev, | ||
3967 | h->nr_cmds * sizeof(struct ErrorInfo), | ||
3968 | h->errinfo_pool, | ||
3969 | h->errinfo_pool_dhandle); | ||
3970 | free_irq(h->intr[h->intr_mode], h); | 3976 | free_irq(h->intr[h->intr_mode], h); |
3971 | clean2: | 3977 | clean2: |
3972 | clean1: | 3978 | clean1: |