11// SPDX-License-Identifier: GPL-2.0-only
2+ #include <linux/iommu.h>
23#include <linux/platform_device.h>
34#include <linux/of.h>
45#include <linux/module.h>
@@ -19,6 +20,8 @@ struct tegra_mgbe {
1920 struct reset_control * rst_mac ;
2021 struct reset_control * rst_pcs ;
2122
23+ u32 iommu_sid ;
24+
2225 void __iomem * hv ;
2326 void __iomem * regs ;
2427 void __iomem * xpcs ;
@@ -50,7 +53,6 @@ struct tegra_mgbe {
5053#define MGBE_WRAP_COMMON_INTR_ENABLE 0x8704
5154#define MAC_SBD_INTR BIT(2)
5255#define MGBE_WRAP_AXI_ASID0_CTRL 0x8400
53- #define MGBE_SID 0x6
5456
5557static int __maybe_unused tegra_mgbe_suspend (struct device * dev )
5658{
@@ -84,7 +86,7 @@ static int __maybe_unused tegra_mgbe_resume(struct device *dev)
8486 writel (MAC_SBD_INTR , mgbe -> regs + MGBE_WRAP_COMMON_INTR_ENABLE );
8587
8688 /* Program SID */
87- writel (MGBE_SID , mgbe -> hv + MGBE_WRAP_AXI_ASID0_CTRL );
89+ writel (mgbe -> iommu_sid , mgbe -> hv + MGBE_WRAP_AXI_ASID0_CTRL );
8890
8991 value = readl (mgbe -> xpcs + XPCS_WRAP_UPHY_STATUS );
9092 if ((value & XPCS_WRAP_UPHY_STATUS_TX_P_UP ) == 0 ) {
@@ -241,6 +243,12 @@ static int tegra_mgbe_probe(struct platform_device *pdev)
241243 if (IS_ERR (mgbe -> xpcs ))
242244 return PTR_ERR (mgbe -> xpcs );
243245
246+ /* get controller's stream id from iommu property in device tree */
247+ if (!tegra_dev_iommu_get_stream_id (mgbe -> dev , & mgbe -> iommu_sid )) {
248+ dev_err (mgbe -> dev , "failed to get iommu stream id\n" );
249+ return - EINVAL ;
250+ }
251+
244252 res .addr = mgbe -> regs ;
245253 res .irq = irq ;
246254
@@ -346,7 +354,7 @@ static int tegra_mgbe_probe(struct platform_device *pdev)
346354 writel (MAC_SBD_INTR , mgbe -> regs + MGBE_WRAP_COMMON_INTR_ENABLE );
347355
348356 /* Program SID */
349- writel (MGBE_SID , mgbe -> hv + MGBE_WRAP_AXI_ASID0_CTRL );
357+ writel (mgbe -> iommu_sid , mgbe -> hv + MGBE_WRAP_AXI_ASID0_CTRL );
350358
351359 plat -> flags |= STMMAC_FLAG_SERDES_UP_AFTER_PHY_LINKUP ;
352360
0 commit comments