]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu: Refactor sriov xgmi topology filling to common code
authorWill Aitken <wiaitken@amd.com>
Tue, 30 Sep 2025 16:24:07 +0000 (16:24 +0000)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 14 Nov 2025 16:27:29 +0000 (11:27 -0500)
amdgpu_xgmi_fill_topology_info and psp_xgmi_reflect_topology_info
perform the same logic of copying topology info of one node to every
other node in the hive. Instead of having two functions that purport to
do the same thing, this refactoring moves the logic of the fill function
to the reflect function and adds reflecting port number info as well for
complete functionality.

Signed-off-by: Will Aitken <wiaitken@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c

index aa7987d0806c6c94f7d355acdec64e3f0bb0676f..76ab8462d9ed2a80161516678cb3a3e03e8343df 100644 (file)
@@ -1539,6 +1539,7 @@ static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
        uint64_t src_node_id = psp->adev->gmc.xgmi.node_id;
        uint64_t dst_node_id = node_info.node_id;
        uint8_t dst_num_hops = node_info.num_hops;
+       uint8_t dst_is_sharing_enabled = node_info.is_sharing_enabled;
        uint8_t dst_num_links = node_info.num_links;
 
        hive = amdgpu_get_xgmi_hive(psp->adev);
@@ -1558,13 +1559,20 @@ static void psp_xgmi_reflect_topology_info(struct psp_context *psp,
                                continue;
 
                        mirror_top_info->nodes[j].num_hops = dst_num_hops;
-                       /*
-                        * prevent 0 num_links value re-reflection since reflection
+                       mirror_top_info->nodes[j].is_sharing_enabled = dst_is_sharing_enabled;
+                       /* prevent 0 num_links value re-reflection since reflection
                         * criteria is based on num_hops (direct or indirect).
-                        *
                         */
-                       if (dst_num_links)
+                       if (dst_num_links) {
                                mirror_top_info->nodes[j].num_links = dst_num_links;
+                               /* swap src and dst due to frame of reference */
+                               for (int k = 0; k < dst_num_links; k++) {
+                                       mirror_top_info->nodes[j].port_num[k].src_xgmi_port_num =
+                                               node_info.port_num[k].dst_xgmi_port_num;
+                                       mirror_top_info->nodes[j].port_num[k].dst_xgmi_port_num =
+                                               node_info.port_num[k].src_xgmi_port_num;
+                               }
+                       }
 
                        break;
                }
@@ -1639,7 +1647,8 @@ int psp_xgmi_get_topology_info(struct psp_context *psp,
                        amdgpu_ip_version(psp->adev, MP0_HWIP, 0) ==
                                IP_VERSION(13, 0, 6) ||
                        amdgpu_ip_version(psp->adev, MP0_HWIP, 0) ==
-                               IP_VERSION(13, 0, 14);
+                               IP_VERSION(13, 0, 14) ||
+                       amdgpu_sriov_vf(psp->adev);
                bool ta_port_num_support = amdgpu_sriov_vf(psp->adev) ? 0 :
                                psp->xgmi_context.xgmi_ta_caps & EXTEND_PEER_LINK_INFO_CMD_FLAG;
 
index 10e42b0ff7a27fe525602bea3a736b7a9e3b5dfc..aad530c46a9f4f71a12f947ed64090d764637795 100644 (file)
@@ -968,28 +968,6 @@ static int amdgpu_xgmi_initialize_hive_get_data_partition(struct amdgpu_hive_inf
        return 0;
 }
 
-static void amdgpu_xgmi_fill_topology_info(struct amdgpu_device *adev,
-       struct amdgpu_device *peer_adev)
-{
-       struct psp_xgmi_topology_info *top_info = &adev->psp.xgmi_context.top_info;
-       struct psp_xgmi_topology_info *peer_info = &peer_adev->psp.xgmi_context.top_info;
-
-       for (int i = 0; i < peer_info->num_nodes; i++) {
-               if (peer_info->nodes[i].node_id == adev->gmc.xgmi.node_id) {
-                       for (int j = 0; j < top_info->num_nodes; j++) {
-                               if (top_info->nodes[j].node_id == peer_adev->gmc.xgmi.node_id) {
-                                       peer_info->nodes[i].num_hops = top_info->nodes[j].num_hops;
-                                       peer_info->nodes[i].is_sharing_enabled =
-                                                       top_info->nodes[j].is_sharing_enabled;
-                                       peer_info->nodes[i].num_links =
-                                                       top_info->nodes[j].num_links;
-                                       return;
-                               }
-                       }
-               }
-       }
-}
-
 int amdgpu_xgmi_add_device(struct amdgpu_device *adev)
 {
        struct psp_xgmi_topology_info *top_info;
@@ -1075,11 +1053,6 @@ int amdgpu_xgmi_add_device(struct amdgpu_device *adev)
                                /* To do: continue with some node failed or disable the whole hive*/
                                goto exit_unlock;
                        }
-
-                       /* fill the topology info for peers instead of getting from PSP */
-                       list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {
-                               amdgpu_xgmi_fill_topology_info(adev, tmp_adev);
-                       }
                } else {
                        /* get latest topology info for each device from psp */
                        list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head) {