Lines Matching +full:rc +full:- +full:map +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2016-2019 HabanaLabs, Ltd.
21 * hl_pci_bars_map() - Map PCI BARs.
23 * @name: Array of BAR names.
24 * @is_wc: Array with flag per BAR whether a write-combined mapping is needed.
26 * Request PCI regions and map them to kernel virtual addresses.
28 * Return: 0 on success, non-zero for failure.
30 int hl_pci_bars_map(struct hl_device *hdev, const char * const name[3], in hl_pci_bars_map()
33 struct pci_dev *pdev = hdev->pdev; in hl_pci_bars_map()
34 int rc, i, bar; in hl_pci_bars_map() local
36 rc = pci_request_regions(pdev, HL_NAME); in hl_pci_bars_map()
37 if (rc) { in hl_pci_bars_map()
38 dev_err(hdev->dev, "Cannot obtain PCI resources\n"); in hl_pci_bars_map()
39 return rc; in hl_pci_bars_map()
43 bar = i * 2; /* 64-bit BARs */ in hl_pci_bars_map()
44 hdev->pcie_bar[bar] = is_wc[i] ? in hl_pci_bars_map()
47 if (!hdev->pcie_bar[bar]) { in hl_pci_bars_map()
48 dev_err(hdev->dev, "pci_ioremap%s_bar failed for %s\n", in hl_pci_bars_map()
49 is_wc[i] ? "_wc" : "", name[i]); in hl_pci_bars_map()
50 rc = -ENODEV; in hl_pci_bars_map()
58 for (i = 2 ; i >= 0 ; i--) { in hl_pci_bars_map()
59 bar = i * 2; /* 64-bit BARs */ in hl_pci_bars_map()
60 if (hdev->pcie_bar[bar]) in hl_pci_bars_map()
61 iounmap(hdev->pcie_bar[bar]); in hl_pci_bars_map()
66 return rc; in hl_pci_bars_map()
70 * hl_pci_bars_unmap() - Unmap PCI BARS.
77 struct pci_dev *pdev = hdev->pdev; in hl_pci_bars_unmap()
80 for (i = 2 ; i >= 0 ; i--) { in hl_pci_bars_unmap()
81 bar = i * 2; /* 64-bit BARs */ in hl_pci_bars_unmap()
82 iounmap(hdev->pcie_bar[bar]); in hl_pci_bars_unmap()
89 * hl_pci_elbi_write() - Write through the ELBI interface.
98 struct pci_dev *pdev = hdev->pdev; in hl_pci_elbi_write()
103 if (hdev->pldm) in hl_pci_elbi_write()
134 dev_err(hdev->dev, "Error writing to ELBI\n"); in hl_pci_elbi_write()
135 return -EIO; in hl_pci_elbi_write()
139 dev_err(hdev->dev, "ELBI write didn't finish in time\n"); in hl_pci_elbi_write()
140 return -EIO; in hl_pci_elbi_write()
143 dev_err(hdev->dev, "ELBI write has undefined bits in status\n"); in hl_pci_elbi_write()
144 return -EIO; in hl_pci_elbi_write()
148 * hl_pci_iatu_write() - iatu write routine.
157 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_pci_iatu_write()
159 int rc; in hl_pci_iatu_write() local
163 rc = hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0x00300000); in hl_pci_iatu_write()
164 rc |= hl_pci_elbi_write(hdev, prop->pcie_dbi_base_address + dbi_offset, in hl_pci_iatu_write()
167 if (rc) in hl_pci_iatu_write()
168 return -EIO; in hl_pci_iatu_write()
174 * hl_pci_reset_link_through_bridge() - Reset PCI link.
179 struct pci_dev *pdev = hdev->pdev; in hl_pci_reset_link_through_bridge()
183 parent_port = pdev->bus->self; in hl_pci_reset_link_through_bridge()
195 * hl_pci_set_inbound_region() - Configure inbound region
207 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_pci_set_inbound_region()
210 int rc = 0; in hl_pci_set_inbound_region() local
215 if (pci_region->mode == PCI_ADDRESS_MATCH_MODE) { in hl_pci_set_inbound_region()
216 bar_phys_base = hdev->pcie_bar_phys[pci_region->bar]; in hl_pci_set_inbound_region()
217 region_base = bar_phys_base + pci_region->offset_in_bar; in hl_pci_set_inbound_region()
218 region_end_address = region_base + pci_region->size - 1; in hl_pci_set_inbound_region()
220 rc |= hl_pci_iatu_write(hdev, offset + 0x8, in hl_pci_set_inbound_region()
222 rc |= hl_pci_iatu_write(hdev, offset + 0xC, in hl_pci_set_inbound_region()
224 rc |= hl_pci_iatu_write(hdev, offset + 0x10, in hl_pci_set_inbound_region()
229 rc |= hl_pci_iatu_write(hdev, offset + 0x14, in hl_pci_set_inbound_region()
230 lower_32_bits(pci_region->addr)); in hl_pci_set_inbound_region()
231 rc |= hl_pci_iatu_write(hdev, offset + 0x18, in hl_pci_set_inbound_region()
232 upper_32_bits(pci_region->addr)); in hl_pci_set_inbound_region()
233 rc |= hl_pci_iatu_write(hdev, offset + 0x0, 0); in hl_pci_set_inbound_region()
238 pci_region->mode); in hl_pci_set_inbound_region()
241 if (pci_region->mode == PCI_BAR_MATCH_MODE) in hl_pci_set_inbound_region()
243 pci_region->bar); in hl_pci_set_inbound_region()
245 rc |= hl_pci_iatu_write(hdev, offset + 0x4, ctrl_reg_val); in hl_pci_set_inbound_region()
248 rc |= hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0); in hl_pci_set_inbound_region()
249 rc |= hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr + 4, 0); in hl_pci_set_inbound_region()
251 if (rc) in hl_pci_set_inbound_region()
252 dev_err(hdev->dev, "failed to map bar %u to 0x%08llx\n", in hl_pci_set_inbound_region()
253 pci_region->bar, pci_region->addr); in hl_pci_set_inbound_region()
255 return rc; in hl_pci_set_inbound_region()
259 * hl_pci_set_outbound_region() - Configure outbound region 0
270 struct asic_fixed_properties *prop = &hdev->asic_prop; in hl_pci_set_outbound_region()
272 int rc = 0; in hl_pci_set_outbound_region() local
276 pci_region->addr + pci_region->size - 1; in hl_pci_set_outbound_region()
277 rc |= hl_pci_iatu_write(hdev, 0x008, in hl_pci_set_outbound_region()
278 lower_32_bits(pci_region->addr)); in hl_pci_set_outbound_region()
279 rc |= hl_pci_iatu_write(hdev, 0x00C, in hl_pci_set_outbound_region()
280 upper_32_bits(pci_region->addr)); in hl_pci_set_outbound_region()
281 rc |= hl_pci_iatu_write(hdev, 0x010, in hl_pci_set_outbound_region()
283 rc |= hl_pci_iatu_write(hdev, 0x014, 0); in hl_pci_set_outbound_region()
285 if ((hdev->power9_64bit_dma_enable) && (hdev->dma_mask == 64)) in hl_pci_set_outbound_region()
286 rc |= hl_pci_iatu_write(hdev, 0x018, 0x08000000); in hl_pci_set_outbound_region()
288 rc |= hl_pci_iatu_write(hdev, 0x018, 0); in hl_pci_set_outbound_region()
290 rc |= hl_pci_iatu_write(hdev, 0x020, in hl_pci_set_outbound_region()
293 rc |= hl_pci_iatu_write(hdev, 0x000, 0x00002000); in hl_pci_set_outbound_region()
295 rc |= hl_pci_iatu_write(hdev, 0x004, 0x80000000); in hl_pci_set_outbound_region()
298 rc |= hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr, 0); in hl_pci_set_outbound_region()
299 rc |= hl_pci_elbi_write(hdev, prop->pcie_aux_dbi_reg_addr + 4, 0); in hl_pci_set_outbound_region()
301 return rc; in hl_pci_set_outbound_region()
305 * hl_pci_set_dma_mask() - Set DMA masks for the device.
309 * value. If it doesn't succeed, it tries to set it to a fall-back value
311 * Return: 0 on success, non-zero for failure.
315 struct pci_dev *pdev = hdev->pdev; in hl_pci_set_dma_mask()
316 int rc; in hl_pci_set_dma_mask() local
319 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(hdev->dma_mask)); in hl_pci_set_dma_mask()
320 if (rc) { in hl_pci_set_dma_mask()
321 dev_err(hdev->dev, in hl_pci_set_dma_mask()
323 hdev->dma_mask, rc); in hl_pci_set_dma_mask()
324 return rc; in hl_pci_set_dma_mask()
327 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(hdev->dma_mask)); in hl_pci_set_dma_mask()
328 if (rc) { in hl_pci_set_dma_mask()
329 dev_err(hdev->dev, in hl_pci_set_dma_mask()
331 hdev->dma_mask, rc); in hl_pci_set_dma_mask()
332 return rc; in hl_pci_set_dma_mask()
339 * hl_pci_init() - PCI initialization code.
346 * Set DMA masks, initialize the PCI controller and map the PCI BARs.
348 * Return: 0 on success, non-zero for failure.
353 struct pci_dev *pdev = hdev->pdev; in hl_pci_init()
354 int rc; in hl_pci_init() local
356 if (hdev->reset_pcilink) in hl_pci_init()
359 rc = pci_enable_device_mem(pdev); in hl_pci_init()
360 if (rc) { in hl_pci_init()
361 dev_err(hdev->dev, "can't enable PCI device\n"); in hl_pci_init()
362 return rc; in hl_pci_init()
367 rc = hdev->asic_funcs->pci_bars_map(hdev); in hl_pci_init()
368 if (rc) { in hl_pci_init()
369 dev_err(hdev->dev, "Failed to initialize PCI BARs\n"); in hl_pci_init()
373 rc = hdev->asic_funcs->init_iatu(hdev); in hl_pci_init()
374 if (rc) { in hl_pci_init()
375 dev_err(hdev->dev, "Failed to initialize iATU\n"); in hl_pci_init()
379 rc = hl_pci_set_dma_mask(hdev); in hl_pci_init()
380 if (rc) in hl_pci_init()
384 * version to determine whether we run with a security-enabled firmware in hl_pci_init()
387 rc = hl_fw_read_preboot_ver(hdev, cpu_boot_status_reg, boot_err0_reg, in hl_pci_init()
389 if (rc) in hl_pci_init()
400 return rc; in hl_pci_init()
404 * hl_fw_fini() - PCI finalization code.
413 pci_clear_master(hdev->pdev); in hl_pci_fini()
414 pci_disable_device(hdev->pdev); in hl_pci_fini()