Re: [PATCH 4/4] gdth: use generic DMA API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 18 Oct 2018, Christoph Hellwig wrote:

> Switch from the legacy PCI DMA API to the generic DMA API.  Also switch
> to dma_map_single from pci_map_page in one case where this makes the code
> simpler.
> 
> Signed-off-by: Christoph Hellwig <hch@xxxxxx>
> ---
>  drivers/scsi/gdth.c      | 111 +++++++++++++++++++--------------------
>  drivers/scsi/gdth_proc.c |   4 +-
>  2 files changed, 56 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
> index 7274d09b2a6c..3d856554b1b1 100644
> --- a/drivers/scsi/gdth.c
> +++ b/drivers/scsi/gdth.c
> @@ -2518,9 +2518,9 @@ static int gdth_fill_cache_cmd(gdth_ha_str *ha, struct scsi_cmnd *scp,
>  
>          if (scsi_bufflen(scp)) {
>              cmndinfo->dma_dir = (read_write == 1 ?
> -                PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);   
> -            sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
> -                               cmndinfo->dma_dir);
> +                DMA_TO_DEVICE : DMA_FROM_DEVICE);   
> +            sgcnt = dma_map_sg(&ha->pdev->dev, scsi_sglist(scp),
> +			       scsi_sg_count(scp), cmndinfo->dma_dir);
>              if (mode64) {
>                  struct scatterlist *sl;
>  
> @@ -2603,8 +2603,6 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct scsi_cmnd *scp, u8 b)
>      dma_addr_t sense_paddr;
>      int cmd_index, sgcnt, mode64;
>      u8 t,l;
> -    struct page *page;
> -    unsigned long offset;
>      struct gdth_cmndinfo *cmndinfo;
>  
>      t = scp->device->id;
> @@ -2649,10 +2647,8 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct scsi_cmnd *scp, u8 b)
>          }
>  
>      } else {
> -        page = virt_to_page(scp->sense_buffer);
> -        offset = (unsigned long)scp->sense_buffer & ~PAGE_MASK;
> -        sense_paddr = pci_map_page(ha->pdev,page,offset,
> -                                   16,PCI_DMA_FROMDEVICE);
> +        sense_paddr = dma_map_single(&ha->pdev->dev, scp->sense_buffer, 16,
> +				     DMA_FROM_DEVICE);
>  
>  	cmndinfo->sense_paddr  = sense_paddr;
>          cmdp->OpCode           = GDT_WRITE;             /* always */
> @@ -2693,9 +2689,9 @@ static int gdth_fill_raw_cmd(gdth_ha_str *ha, struct scsi_cmnd *scp, u8 b)
>          }
>  
>          if (scsi_bufflen(scp)) {
> -            cmndinfo->dma_dir = PCI_DMA_BIDIRECTIONAL;
> -            sgcnt = pci_map_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
> -                               cmndinfo->dma_dir);
> +            cmndinfo->dma_dir = DMA_BIDIRECTIONAL;
> +            sgcnt = dma_map_sg(&ha->pdev->dev, scsi_sglist(scp),
> +			       scsi_sg_count(scp), cmndinfo->dma_dir);
>              if (mode64) {
>                  struct scatterlist *sl;
>  
> @@ -3313,12 +3309,12 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
>              return 2;
>          }
>          if (scsi_bufflen(scp))
> -            pci_unmap_sg(ha->pdev, scsi_sglist(scp), scsi_sg_count(scp),
> +            dma_unmap_sg(&ha->pdev->dev, scsi_sglist(scp), scsi_sg_count(scp),
>                           cmndinfo->dma_dir);
>  
>          if (cmndinfo->sense_paddr)
> -            pci_unmap_page(ha->pdev, cmndinfo->sense_paddr, 16,
> -                                                           PCI_DMA_FROMDEVICE);
> +            dma_unmap_page(&ha->pdev->dev, cmndinfo->sense_paddr, 16,
> +	    		   DMA_FROM_DEVICE);
>  
>          if (ha->status == S_OK) {
>              cmndinfo->status = S_OK;
> @@ -4251,8 +4247,8 @@ static int ioc_general(void __user *arg, char *cmnd)
>  	if (gen.data_len + gen.sense_len == 0)
>  		goto execute;
>  
> -        buf = pci_alloc_consistent(ha->pdev, gen.data_len + gen.sense_len,
> -			&paddr);
> +        buf = dma_alloc_coherent(&ha->pdev->dev, gen.data_len + gen.sense_len,
> +			&paddr, GFP_KERNEL);
>  	if (!buf)
>  		return -EFAULT;
>  
> @@ -4292,7 +4288,8 @@ static int ioc_general(void __user *arg, char *cmnd)
>  
>  	rval = 0;
>  out_free_buf:
> -	pci_free_consistent(ha->pdev, gen.data_len + gen.sense_len, buf, paddr);
> +	dma_free_coherent(&ha->pdev->dev, gen.data_len + gen.sense_len, buf,
> +			paddr);
>  	return 0;
>  }
>   
> @@ -4749,22 +4746,22 @@ static int __init gdth_isa_probe_one(u32 isa_bios)
>  
>  	error = -ENOMEM;
>  
> -	ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
> -						&scratch_dma_handle);
> +	ha->pscratch = dma_alloc_coherent(&ha->pdev->dev, GDTH_SCRATCH,
> +				&scratch_dma_handle, GFP_KERNEL);
>  	if (!ha->pscratch)
>  		goto out_dec_counters;
>  	ha->scratch_phys = scratch_dma_handle;
>  
> -	ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
> -						&scratch_dma_handle);
> +	ha->pmsg = dma_alloc_coherent(&ha->pdev->dev, sizeof(gdth_msg_str),
> +				&scratch_dma_handle, GFP_KERNEL);
>  	if (!ha->pmsg)
>  		goto out_free_pscratch;
>  	ha->msg_phys = scratch_dma_handle;
>  
>  #ifdef INT_COAL
> -	ha->coal_stat = pci_alloc_consistent(ha->pdev,
> +	ha->coal_stat = dma_alloc_coherent(&ha->pdev->dev,
>  				sizeof(gdth_coal_status) * MAXOFFSETS,
> -				&scratch_dma_handle);
> +				&scratch_dma_handle, GFP_KERNEL);
>  	if (!ha->coal_stat)
>  		goto out_free_pmsg;
>  	ha->coal_stat_phys = scratch_dma_handle;
> @@ -4811,14 +4808,14 @@ static int __init gdth_isa_probe_one(u32 isa_bios)
>  
>   out_free_coal_stat:
>  #ifdef INT_COAL
> -	pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
> +	dma_free_coherent(&ha->pdev->dev, sizeof(gdth_coal_status) * MAXOFFSETS,
>  				ha->coal_stat, ha->coal_stat_phys);
>   out_free_pmsg:
>  #endif
> -	pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
> +	dma_free_coherent(&ha->pdev->dev, sizeof(gdth_msg_str),
>  				ha->pmsg, ha->msg_phys);
>   out_free_pscratch:
> -	pci_free_consistent(ha->pdev, GDTH_SCRATCH,
> +	dma_free_coherent(&ha->pdev->dev, GDTH_SCRATCH,
>  				ha->pscratch, ha->scratch_phys);
>   out_dec_counters:
>  	gdth_ctr_count--;
> @@ -4875,29 +4872,29 @@ static int __init gdth_eisa_probe_one(u16 eisa_slot)
>  	error = -ENOMEM;
>  
>  	ha->pdev = NULL;
> -	ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
> -						&scratch_dma_handle);
> +	ha->pscratch = dma_alloc_coherent(&ha->pdev->dev, GDTH_SCRATCH,
> +				&scratch_dma_handle, GFP_KERNEL);
>  	if (!ha->pscratch)
>  		goto out_free_irq;
>  	ha->scratch_phys = scratch_dma_handle;
>  
> -	ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
> -						&scratch_dma_handle);
> +	ha->pmsg = dma_alloc_coherent(&ha->pdev->dev, sizeof(gdth_msg_str),
> +				&scratch_dma_handle, GFP_KERNEL);
>  	if (!ha->pmsg)
>  		goto out_free_pscratch;
>  	ha->msg_phys = scratch_dma_handle;
>  
>  #ifdef INT_COAL
> -	ha->coal_stat = pci_alloc_consistent(ha->pdev,
> +	ha->coal_stat = dma_alloc_coherent(&ha->pdev->dev,
>  			sizeof(gdth_coal_status) * MAXOFFSETS,
> -			&scratch_dma_handle);
> +			&scratch_dma_handle, GFP_KERNEL);
>  	if (!ha->coal_stat)
>  		goto out_free_pmsg;
>  	ha->coal_stat_phys = scratch_dma_handle;
>  #endif
>  
> -	ha->ccb_phys = pci_map_single(ha->pdev,ha->pccb,
> -			sizeof(gdth_cmd_str), PCI_DMA_BIDIRECTIONAL);
> +	ha->ccb_phys = dma_map_single(&ha->pdev->dev, ha->pccb,
> +			sizeof(gdth_cmd_str), DMA_BIDIRECTIONAL);
>  	if (!ha->ccb_phys)
>  		goto out_free_coal_stat;
>  
> @@ -4941,18 +4938,18 @@ static int __init gdth_eisa_probe_one(u16 eisa_slot)
>  	return 0;
>  
>   out_free_ccb_phys:
> -	pci_unmap_single(ha->pdev,ha->ccb_phys, sizeof(gdth_cmd_str),
> -			PCI_DMA_BIDIRECTIONAL);
> +	dma_unmap_single(&ha->pdev->dev, ha->ccb_phys, sizeof(gdth_cmd_str),
> +			DMA_BIDIRECTIONAL);
>   out_free_coal_stat:
>  #ifdef INT_COAL
> -	pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
> +	dma_free_coherent(&ha->pdev->dev, sizeof(gdth_coal_status) * MAXOFFSETS,
>  				ha->coal_stat, ha->coal_stat_phys);
>   out_free_pmsg:
>  #endif
> -	pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
> +	dma_free_coherent(&ha->pdev->dev, sizeof(gdth_msg_str),
>  				ha->pmsg, ha->msg_phys);
>   out_free_pscratch:
> -	pci_free_consistent(ha->pdev, GDTH_SCRATCH,
> +	dma_free_coherent(&ha->pdev->dev, GDTH_SCRATCH,
>  				ha->pscratch, ha->scratch_phys);
>   out_free_irq:
>  	free_irq(ha->irq, ha);
> @@ -5008,22 +5005,22 @@ static int gdth_pci_probe_one(gdth_pci_str *pcistr, gdth_ha_str **ha_out)
>  
>  	error = -ENOMEM;
>  
> -	ha->pscratch = pci_alloc_consistent(ha->pdev, GDTH_SCRATCH,
> -						&scratch_dma_handle);
> +	ha->pscratch = dma_alloc_coherent(&ha->pdev->dev, GDTH_SCRATCH,
> +				&scratch_dma_handle, GFP_KERNEL);
>  	if (!ha->pscratch)
>  		goto out_free_irq;
>  	ha->scratch_phys = scratch_dma_handle;
>  
> -	ha->pmsg = pci_alloc_consistent(ha->pdev, sizeof(gdth_msg_str),
> -					&scratch_dma_handle);
> +	ha->pmsg = dma_alloc_coherent(&ha->pdev->dev, sizeof(gdth_msg_str),
> +				&scratch_dma_handle, GFP_KERNEL);
>  	if (!ha->pmsg)
>  		goto out_free_pscratch;
>  	ha->msg_phys = scratch_dma_handle;
>  
>  #ifdef INT_COAL
> -	ha->coal_stat = pci_alloc_consistent(ha->pdev,
> +	ha->coal_stat = dma_alloc_coherent(&ha->pdev->dev,
>  			sizeof(gdth_coal_status) * MAXOFFSETS,
> -			&scratch_dma_handle);
> +			&scratch_dma_handle, GFP_KERNEL
>  	if (!ha->coal_stat)
>  		goto out_free_pmsg;
>  	ha->coal_stat_phys = scratch_dma_handle;

Missing closing parenthesis and semi-colon.

-- 

> @@ -5051,16 +5048,16 @@ static int gdth_pci_probe_one(gdth_pci_str *pcistr, gdth_ha_str **ha_out)
>  	/* 64-bit DMA only supported from FW >= x.43 */
>  	if (!(ha->cache_feat & ha->raw_feat & ha->screen_feat & GDT_64BIT) ||
>  	    !ha->dma64_support) {
> -		if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
> +		if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
>  			printk(KERN_WARNING "GDT-PCI %d: "
>  				"Unable to set 32-bit DMA\n", ha->hanum);
>  				goto out_free_coal_stat;
>  		}
>  	} else {
>  		shp->max_cmd_len = 16;
> -		if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
> +		if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
>  			printk("GDT-PCI %d: 64-bit DMA enabled\n", ha->hanum);
> -		} else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
> +		} else if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
>  			printk(KERN_WARNING "GDT-PCI %d: "
>  				"Unable to set 64/32-bit DMA\n", ha->hanum);
>  			goto out_free_coal_stat;
> @@ -5090,14 +5087,14 @@ static int gdth_pci_probe_one(gdth_pci_str *pcistr, gdth_ha_str **ha_out)
>  
>   out_free_coal_stat:
>  #ifdef INT_COAL
> -	pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) * MAXOFFSETS,
> +	dma_free_coherent(&ha->pdev->dev, sizeof(gdth_coal_status) * MAXOFFSETS,
>  				ha->coal_stat, ha->coal_stat_phys);
>   out_free_pmsg:
>  #endif
> -	pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
> +	dma_free_coherent(&ha->pdev->dev, sizeof(gdth_msg_str),
>  				ha->pmsg, ha->msg_phys);
>   out_free_pscratch:
> -	pci_free_consistent(ha->pdev, GDTH_SCRATCH,
> +	dma_free_coherent(&ha->pdev->dev, GDTH_SCRATCH,
>  				ha->pscratch, ha->scratch_phys);
>   out_free_irq:
>  	free_irq(ha->irq, ha);
> @@ -5132,18 +5129,18 @@ static void gdth_remove_one(gdth_ha_str *ha)
>  #endif
>  #ifdef INT_COAL
>  	if (ha->coal_stat)
> -		pci_free_consistent(ha->pdev, sizeof(gdth_coal_status) *
> +		dma_free_coherent(&ha->pdev->dev, sizeof(gdth_coal_status) *
>  			MAXOFFSETS, ha->coal_stat, ha->coal_stat_phys);
>  #endif
>  	if (ha->pscratch)
> -		pci_free_consistent(ha->pdev, GDTH_SCRATCH,
> +		dma_free_coherent(&ha->pdev->dev, GDTH_SCRATCH,
>  			ha->pscratch, ha->scratch_phys);
>  	if (ha->pmsg)
> -		pci_free_consistent(ha->pdev, sizeof(gdth_msg_str),
> +		dma_free_coherent(&ha->pdev->dev, sizeof(gdth_msg_str),
>  			ha->pmsg, ha->msg_phys);
>  	if (ha->ccb_phys)
> -		pci_unmap_single(ha->pdev,ha->ccb_phys,
> -			sizeof(gdth_cmd_str),PCI_DMA_BIDIRECTIONAL);
> +		dma_unmap_single(&ha->pdev->dev, ha->ccb_phys,
> +			sizeof(gdth_cmd_str), DMA_BIDIRECTIONAL);
>  
>  	scsi_host_put(shp);
>  }
> diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
> index 6a6bdab748df..745bcac9a796 100644
> --- a/drivers/scsi/gdth_proc.c
> +++ b/drivers/scsi/gdth_proc.c
> @@ -244,7 +244,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host *host)
>          seq_puts(m, "\nPhysical Devices:");
>          flag = FALSE;
>              
> -        buf = pci_alloc_consistent(ha->pdev, size, &paddr);
> +        buf = dma_alloc_coherent(&ha->pdev->dev, size, &paddr, GFP_KERNEL);
>          if (!buf) 
>              goto stop_output;
>          for (i = 0; i < ha->bus_cnt; ++i) {
> @@ -514,7 +514,7 @@ int gdth_show_info(struct seq_file *m, struct Scsi_Host *host)
>                  }
>              }
>          }
> -	pci_free_consistent(ha->pdev, size, buf, paddr);
> +	dma_free_coherent(&ha->pdev->dev, size, buf, paddr);
>  
>          for (i = 0; i < MAX_HDRIVES; ++i) {
>              if (!(ha->hdr[i].present))
> 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux