Commit d9973871 authored by Oded Gabbay's avatar Oded Gabbay

habanalabs: keep track of the device's dma mask

This patch refactors the code that is responsible to set the DMA mask for
the device.

Upon each change of the dma mask, the driver will save the new value that
was set. This is needed in order to make sure we don't try to increase the
mask a second time, in case we failed in the first time. This is
especially relevant for Power machines, as that may cause a change in
configuration of the TVT which will break the device.

Goya will first try to set the device's dma mask to 39 bits, so that the
memory that is allocated on the host machine for communication with the
device's cpu will be in a bus address which is lower then 39 bits. Later,
Goya will try to increase that mask to 48 bits, but only if setting the
mask to 39 bits was successful.
Signed-off-by: default avatarOded Gabbay <oded.gabbay@gmail.com>
parent 66542c3b
...@@ -482,7 +482,7 @@ static int goya_early_init(struct hl_device *hdev) ...@@ -482,7 +482,7 @@ static int goya_early_init(struct hl_device *hdev)
prop->dram_pci_bar_size = pci_resource_len(pdev, DDR_BAR_ID); prop->dram_pci_bar_size = pci_resource_len(pdev, DDR_BAR_ID);
rc = hl_pci_init(hdev); rc = hl_pci_init(hdev, 39);
if (rc) if (rc)
return rc; return rc;
...@@ -2445,28 +2445,16 @@ static int goya_hw_init(struct hl_device *hdev) ...@@ -2445,28 +2445,16 @@ static int goya_hw_init(struct hl_device *hdev)
goto disable_msix; goto disable_msix;
} }
/* CPU initialization is finished, we can now move to 48 bit DMA mask */ /*
rc = pci_set_dma_mask(hdev->pdev, DMA_BIT_MASK(48)); * Check if we managed to set the DMA mask to more then 32 bits. If so,
if (rc) { * let's try to increase it again because in Goya we set the initial
dev_warn(hdev->dev, "Unable to set pci dma mask to 48 bits\n"); * dma mask to less then 39 bits so that the allocation of the memory
rc = pci_set_dma_mask(hdev->pdev, DMA_BIT_MASK(32)); * area for the device's cpu will be under 39 bits
if (rc) { */
dev_err(hdev->dev, if (hdev->dma_mask > 32) {
"Unable to set pci dma mask to 32 bits\n"); rc = hl_pci_set_dma_mask(hdev, 48);
goto disable_pci_access; if (rc)
}
}
rc = pci_set_consistent_dma_mask(hdev->pdev, DMA_BIT_MASK(48));
if (rc) {
dev_warn(hdev->dev,
"Unable to set pci consistent dma mask to 48 bits\n");
rc = pci_set_consistent_dma_mask(hdev->pdev, DMA_BIT_MASK(32));
if (rc) {
dev_err(hdev->dev,
"Unable to set pci consistent dma mask to 32 bits\n");
goto disable_pci_access; goto disable_pci_access;
}
} }
/* Perform read from the device to flush all MSI-X configuration */ /* Perform read from the device to flush all MSI-X configuration */
......
...@@ -1106,6 +1106,7 @@ struct hl_device_reset_work { ...@@ -1106,6 +1106,7 @@ struct hl_device_reset_work {
* @init_done: is the initialization of the device done. * @init_done: is the initialization of the device done.
* @mmu_enable: is MMU enabled. * @mmu_enable: is MMU enabled.
* @device_cpu_disabled: is the device CPU disabled (due to timeouts) * @device_cpu_disabled: is the device CPU disabled (due to timeouts)
* @dma_mask: the dma mask that was set for this device
*/ */
struct hl_device { struct hl_device {
struct pci_dev *pdev; struct pci_dev *pdev;
...@@ -1176,6 +1177,7 @@ struct hl_device { ...@@ -1176,6 +1177,7 @@ struct hl_device {
u8 dram_default_page_mapping; u8 dram_default_page_mapping;
u8 init_done; u8 init_done;
u8 device_cpu_disabled; u8 device_cpu_disabled;
u8 dma_mask;
/* Parameters for bring-up */ /* Parameters for bring-up */
u8 mmu_enable; u8 mmu_enable;
...@@ -1397,8 +1399,9 @@ int hl_pci_set_dram_bar_base(struct hl_device *hdev, u8 inbound_region, u8 bar, ...@@ -1397,8 +1399,9 @@ int hl_pci_set_dram_bar_base(struct hl_device *hdev, u8 inbound_region, u8 bar,
u64 addr); u64 addr);
int hl_pci_init_iatu(struct hl_device *hdev, u64 sram_base_address, int hl_pci_init_iatu(struct hl_device *hdev, u64 sram_base_address,
u64 dram_base_address, u64 host_phys_size); u64 dram_base_address, u64 host_phys_size);
int hl_pci_init(struct hl_device *hdev); int hl_pci_init(struct hl_device *hdev, u8 dma_mask);
void hl_pci_fini(struct hl_device *hdev); void hl_pci_fini(struct hl_device *hdev);
int hl_pci_set_dma_mask(struct hl_device *hdev, u8 dma_mask);
long hl_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr); long hl_get_frequency(struct hl_device *hdev, u32 pll_index, bool curr);
void hl_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq); void hl_set_frequency(struct hl_device *hdev, u32 pll_index, u64 freq);
......
...@@ -229,6 +229,9 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, ...@@ -229,6 +229,9 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev,
hdev->asic_type = asic_type; hdev->asic_type = asic_type;
} }
/* Set default DMA mask to 32 bits */
hdev->dma_mask = 32;
mutex_lock(&hl_devs_idr_lock); mutex_lock(&hl_devs_idr_lock);
if (minor == -1) { if (minor == -1) {
......
...@@ -287,42 +287,74 @@ int hl_pci_init_iatu(struct hl_device *hdev, u64 sram_base_address, ...@@ -287,42 +287,74 @@ int hl_pci_init_iatu(struct hl_device *hdev, u64 sram_base_address,
} }
/** /**
* hl_pci_init() - PCI initialization code. * hl_pci_set_dma_mask() - Set DMA masks for the device.
* @hdev: Pointer to hl_device structure. * @hdev: Pointer to hl_device structure.
* @dma_mask: number of bits for the requested dma mask.
* *
* Set DMA masks, initialize the PCI controller and map the PCI BARs. * This function sets the DMA masks (regular and consistent) for a specified
* value. If it doesn't succeed, it tries to set it to a fall-back value
* *
* Return: 0 on success, non-zero for failure. * Return: 0 on success, non-zero for failure.
*/ */
int hl_pci_init(struct hl_device *hdev) int hl_pci_set_dma_mask(struct hl_device *hdev, u8 dma_mask)
{ {
struct pci_dev *pdev = hdev->pdev; struct pci_dev *pdev = hdev->pdev;
int rc; int rc;
/* set DMA mask */ /* set DMA mask */
rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(39)); rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(dma_mask));
if (rc) { if (rc) {
dev_warn(hdev->dev, "Unable to set pci dma mask to 39 bits\n"); dev_warn(hdev->dev,
rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); "Failed to set pci dma mask to %d bits, error %d\n",
dma_mask, rc);
dma_mask = hdev->dma_mask;
rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(dma_mask));
if (rc) { if (rc) {
dev_err(hdev->dev, dev_err(hdev->dev,
"Unable to set pci dma mask to 32 bits\n"); "Failed to set pci dma mask to %d bits, error %d\n",
dma_mask, rc);
return rc; return rc;
} }
} }
rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(39)); /*
* We managed to set the dma mask, so update the dma mask field. If
* the set to the coherent mask will fail with that mask, we will
* fail the entire function
*/
hdev->dma_mask = dma_mask;
rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(dma_mask));
if (rc) { if (rc) {
dev_warn(hdev->dev, dev_err(hdev->dev,
"Unable to set pci consistent dma mask to 39 bits\n"); "Failed to set pci consistent dma mask to %d bits, error %d\n",
rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); dma_mask, rc);
if (rc) { return rc;
dev_err(hdev->dev,
"Unable to set pci consistent dma mask to 32 bits\n");
return rc;
}
} }
return 0;
}
/**
* hl_pci_init() - PCI initialization code.
* @hdev: Pointer to hl_device structure.
* @dma_mask: number of bits for the requested dma mask.
*
* Set DMA masks, initialize the PCI controller and map the PCI BARs.
*
* Return: 0 on success, non-zero for failure.
*/
int hl_pci_init(struct hl_device *hdev, u8 dma_mask)
{
struct pci_dev *pdev = hdev->pdev;
int rc;
rc = hl_pci_set_dma_mask(hdev, dma_mask);
if (rc)
return rc;
if (hdev->reset_pcilink) if (hdev->reset_pcilink)
hl_pci_reset_link_through_bridge(hdev); hl_pci_reset_link_through_bridge(hdev);
......
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