ufs: fix DMA mask setting
PATCH RESEND 1/1 ufs: fix DMA mask setting
If the controller doesn't support 64-bit addressing mode, it must not set the DMA mask to 64-bit. But it's unconditionally trying to set to 64-bit without checking 64-bit addressing support in the controller capabilities.
It was correctly checked before commit 3b1d05807a9a68c6d0580e9248247a774a4d3be6 ("[SCSI] ufs: Segregate PCI Specific Code"), this aims to restores the correct behaviour.
To achieve this in a generic way, firstly we should push down the DMA mask setting routine ufshcd_set_dma_mask() from PCI glue driver to core driver in order to do it for both PCI glue driver and Platform glue driver. Secondly, we should change pci_ DMA mapping API to dma_ DMA mapping API because core driver is independent of glue drivers.
---
This patch previously required a additional change which initializes dev->dma_mask for device-tree probed device. But it is not required anymore, because of the commit 0589342c27944e50ebd7a54f5215002b6598b748 ("of: set dma_mask to point to coherent_dma_mask").
drivers/scsi/ufs/ufshcd-pci.c | 26 -------------------------- drivers/scsi/ufs/ufshcd.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 26 deletions(-)
drivers/scsi/ufs/ufshcd-pci.c +0 -26
@@ -135,26 +135,6 @@ static void ufshcd_pci_remove(struct pci_dev *pdev) }/** -* ufshcd_set_dma_mask - Set dma mask based on the controller -* addressing capability -* @pdev: PCI device structure -* -* Returns 0 for success, non-zero for failure -*/ -static int ufshcd_set_dma_mask (struct pci_dev *pdev) -{ -int err; - -if (!pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )) - && !pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 ))) -return 0 ; - err =pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )); -if (!err) - err =pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (32 )); -return err; -} - -/** * ufshcd_pci_probe - probe routine of the driver * @pdev: pointer to PCI device handle * @id: PCI device id
@@ -184,12 +164,6 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) mmio_base =pcim_iomap_table (pdev)[0 ]; - err =ufshcd_set_dma_mask (pdev); -if (err) { -dev_err (&pdev->dev,"set dma mask failed\n" ); -return err; - } - err =ufshcd_init (&pdev->dev, &hba, mmio_base, pdev->irq);if (err) {dev_err (&pdev->dev,"Initialization failed\n" );
drivers/scsi/ufs/ufshcd.c +30 -0
@@ -3110,6 +3110,30 @@ void ufshcd_remove(struct ufs_hba *hba)EXPORT_SYMBOL_GPL (ufshcd_remove);/** +* ufshcd_set_dma_mask - Set dma mask based on the controller +* addressing capability +* @hba: per adapter instance +* +* Returns 0 for success, non-zero for failure +*/ +static int ufshcd_set_dma_mask (struct ufs_hba *hba) +{ +int err; + +if (hba->capabilities &MASK_64_ADDRESSING_SUPPORT ) { +if (!dma_set_mask (hba->dev,DMA_BIT_MASK (64 ))) { +dma_set_coherent_mask (hba->dev,DMA_BIT_MASK (64 )); +return 0 ; + } + } + err =dma_set_mask (hba->dev,DMA_BIT_MASK (32 )); +if (!err) +dma_set_coherent_mask (hba->dev,DMA_BIT_MASK (32 )); + +return err; +} + +/** * ufshcd_init - Driver initialization routine * @dev: pointer to device handle * @hba_handle: driver private handle
@@ -3160,6 +3184,12 @@ int ufshcd_init(struct device *dev, struct ufs_hba **hba_handle,/* Get Interrupt bit mask per version */ hba->intr_mask =ufshcd_get_intr_mask (hba); + err =ufshcd_set_dma_mask (hba); +if (err) { +dev_err (hba->dev,"set dma mask failed\n" ); + goto out_disable; + } +/* Allocate memory for host memory space */ err =ufshcd_memory_alloc (hba);if (err) {
Signature · 1 line
1.9.1
Quoted 95 lines · Akinobu Mita
If the controller doesn't support 64-bit addressing mode, it must not set the DMA mask to 64-bit. But it's unconditionally trying to set to 64-bit without checking 64-bit addressing support in the controller capabilities.
It was correctly checked before commit
3b1d05807a9a68c6d0580e9248247a774a4d3be6("[SCSI] ufs: Segregate PCI Specific Code"), this aims to restores the correct behaviour.To achieve this in a generic way, firstly we should push down the DMA mask setting routine
ufshcd_set_dma_mask()from PCI glue driver to core driver in order to do it for both PCI glue driver and Platform glue driver. Secondly, we should changepci_DMA mapping API todma_DMA mapping API because core driver is independent of glue drivers.Signed-off-by Akinobu Mita <[email protected]>Cc Sujit Reddy Thumma <[email protected]>Cc Vinayak Holikatti <[email protected]>Cc Santosh Y <[email protected]>Cc "James E.J. Bottomley" <[email protected]>---
This patch previously required a additional change which initializesdev->dma_maskfor device-tree probed device. But it is not required anymore, because of the commit0589342c27944e50ebd7a54f5215002b6598b748("of: setdma_maskto point tocoherent_dma_mask").drivers/scsi/ufs/ufshcd-pci.c | 26 -------------------------- drivers/scsi/ufs/ufshcd.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 26 deletions(-)drivers/scsi/ufs/ufshcd-pci.c +0
-26@@ -135,26 +135,6 @@ static void ufshcd_pci_remove(struct pci_dev *pdev) }/** -* ufshcd_set_dma_mask - Set dma mask based on the controller -* addressing capability -* @pdev: PCI device structure -* -* Returns 0 for success, non-zero for failure -*/ -static int ufshcd_set_dma_mask (struct pci_dev *pdev) -{ -int err; - -if (!pci_set_dma_mask (pdev,DMA_BIT_MASK (64 )) - && !pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (64 ))) -return 0 ; - err =pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )); -if (!err) - err =pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (32 )); -return err; -} - -/** * ufshcd_pci_probe - probe routine of the driver * @pdev: pointer to PCI device handle * @id: PCI device id @@ -184,12 +164,6 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) mmio_base =pcim_iomap_table (pdev)[0 ]; - err =ufshcd_set_dma_mask (pdev); -if (err) { -dev_err (&pdev->dev,"set dma mask failed\n" ); -return err; - } - err =ufshcd_init (&pdev->dev, &hba, mmio_base, pdev->irq);if (err) {dev_err (&pdev->dev,"Initialization failed\n" );drivers/scsi/ufs/ufshcd.c +12
-0@@ -3110,6 +3110,30 @@ void ufshcd_remove(struct ufs_hba *hba)EXPORT_SYMBOL_GPL (ufshcd_remove);/** +* ufshcd_set_dma_mask - Set dma mask based on the controller +* addressing capability +* @hba: per adapter instance +* +* Returns 0 for success, non-zero for failure +*/ +static int ufshcd_set_dma_mask (struct ufs_hba *hba) +{ +int err; + +if (hba->capabilities &MASK_64_ADDRESSING_SUPPORT ) { +if (!dma_set_mask (hba->dev,DMA_BIT_MASK (64 ))) {
drivers/scsi/ufs/ufshcd.c void ufshcd_remove(struct ufs_hba *hba) · line 3134
Quoted 10 lines
drivers/scsi/ufs/ufshcd.c +10
-0+dma_set_coherent_mask (hba->dev,DMA_BIT_MASK (64 )); +return 0 ; + } + } + err =dma_set_mask (hba->dev,DMA_BIT_MASK (32 )); +if (!err) +dma_set_coherent_mask (hba->dev,DMA_BIT_MASK (32 )); + +return err; +}
We can use dma_set_mask_and_coherent() here.
Quoted 21 lines
drivers/scsi/ufs/ufshcd.c +8
-1+ +/** * ufshcd_init - Driver initialization routine * @dev: pointer to device handle * @hba_handle: driver private handle @@ -3160,6 +3184,12 @@ int ufshcd_init(struct device *dev, struct ufs_hba **hba_handle,/* Get Interrupt bit mask per version */ hba->intr_mask =ufshcd_get_intr_mask (hba); + err =ufshcd_set_dma_mask (hba); +if (err) { +dev_err (hba->dev,"set dma mask failed\n" ); + goto out_disable; + } +/* Allocate memory for host memory space */ err =ufshcd_memory_alloc (hba);if (err) { --1.9.1
Signature · 1 line
~Santosh