Skip to content

Commit 377182a

Browse files
committed
habanalabs: adjust pci controller init to new firmware
When the firmware security is enabled, the pcie_aux_dbi_reg_addr register in the PCI controller is blocked. Therefore, ignore the result of writing to this register and assume it worked. Also remove the prints on errors in the internal ELBI write function. If the security is enabled, the firmware is responsible for setting this register correctly so we won't have any problem. If the security is disabled, the write will work (unless something is totally broken at the PCI level and then the whole sequence will fail). In addition, remove a write to register pcie_aux_dbi_reg_addr+4, which was never actually needed. Moreover, PCIE_DBI registers are blocked to access from host when firmware security is enabled. Use a different register to flush the writes. Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
1 parent 90ffe17 commit 377182a

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

drivers/misc/habanalabs/common/pci.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ static int hl_pci_elbi_write(struct hl_device *hdev, u64 addr, u32 data)
130130
if ((val & PCI_CONFIG_ELBI_STS_MASK) == PCI_CONFIG_ELBI_STS_DONE)
131131
return 0;
132132

133-
if (val & PCI_CONFIG_ELBI_STS_ERR) {
134-
dev_err(hdev->dev, "Error writing to ELBI\n");
133+
if (val & PCI_CONFIG_ELBI_STS_ERR)
135134
return -EIO;
136-
}
137135

138136
if (!(val & PCI_CONFIG_ELBI_STS_MASK)) {
139137
dev_err(hdev->dev, "ELBI write didn't finish in time\n");
@@ -160,8 +158,12 @@ int hl_pci_iatu_write(struct hl_device *hdev, u32 addr, u32 data)
160158

161159
dbi_offset = addr & 0xFFF;
162160

163-
rc = hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0x00300000);
164-
rc |= hl_pci_elbi_write(hdev, prop->pcie_dbi_base_address + dbi_offset,
161+
/* Ignore result of writing to pcie_aux_dbi_reg_addr as it could fail
162+
* in case the firmware security is enabled
163+
*/
164+
hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0x00300000);
165+
166+
rc = hl_pci_elbi_write(hdev, prop->pcie_dbi_base_address + dbi_offset,
165167
data);
166168

167169
if (rc)
@@ -244,9 +246,11 @@ int hl_pci_set_inbound_region(struct hl_device *hdev, u8 region,
244246

245247
rc |= hl_pci_iatu_write(hdev, offset + 0x4, ctrl_reg_val);
246248

247-
/* Return the DBI window to the default location */
248-
rc |= hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0);
249-
rc |= hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr + 4, 0);
249+
/* Return the DBI window to the default location
250+
* Ignore result of writing to pcie_aux_dbi_reg_addr as it could fail
251+
* in case the firmware security is enabled
252+
*/
253+
hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0);
250254

251255
if (rc)
252256
dev_err(hdev->dev, "failed to map bar %u to 0x%08llx\n",
@@ -294,9 +298,11 @@ int hl_pci_set_outbound_region(struct hl_device *hdev,
294298
/* Enable */
295299
rc |= hl_pci_iatu_write(hdev, 0x004, 0x80000000);
296300

297-
/* Return the DBI window to the default location */
298-
rc |= hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0);
299-
rc |= hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr + 4, 0);
301+
/* Return the DBI window to the default location
302+
* Ignore result of writing to pcie_aux_dbi_reg_addr as it could fail
303+
* in case the firmware security is enabled
304+
*/
305+
hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0);
300306

301307
return rc;
302308
}

drivers/misc/habanalabs/gaudi/gaudi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,7 +3761,7 @@ static int gaudi_init_cpu_queues(struct hl_device *hdev, u32 cpu_timeout)
37613761
static void gaudi_pre_hw_init(struct hl_device *hdev)
37623762
{
37633763
/* Perform read from the device to make sure device is up */
3764-
RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG);
3764+
RREG32(mmHW_STATE);
37653765

37663766
if (hdev->asic_prop.fw_security_disabled) {
37673767
/* Set the access through PCI bars (Linux driver only) as
@@ -3847,7 +3847,7 @@ static int gaudi_hw_init(struct hl_device *hdev)
38473847
}
38483848

38493849
/* Perform read from the device to flush all configuration */
3850-
RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG);
3850+
RREG32(mmHW_STATE);
38513851

38523852
return 0;
38533853

drivers/misc/habanalabs/gaudi/gaudi_coresight.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../include/gaudi/gaudi_coresight.h"
1010
#include "../include/gaudi/asic_reg/gaudi_regs.h"
1111
#include "../include/gaudi/gaudi_masks.h"
12+
#include "../include/gaudi/gaudi_reg_map.h"
1213

1314
#include <uapi/misc/habanalabs.h>
1415
#define SPMU_SECTION_SIZE MME0_ACC_SPMU_MAX_OFFSET
@@ -874,7 +875,7 @@ int gaudi_debug_coresight(struct hl_device *hdev, void *data)
874875
}
875876

876877
/* Perform read from the device to flush all configuration */
877-
RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG);
878+
RREG32(mmHW_STATE);
878879

879880
return rc;
880881
}

0 commit comments

Comments
 (0)