]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu: simplify xgmi peer info calls
authorJonathan Kim <jonathan.kim@amd.com>
Mon, 10 Feb 2025 18:15:48 +0000 (13:15 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 25 Feb 2025 16:45:12 +0000 (11:45 -0500)
Deprecate KFD XGMI peer info calls in favour of calling directly from
simplified XGMI peer info functions.

Signed-off-by: Jonathan Kim <jonathan.kim@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_amdkfd.c
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h
drivers/gpu/drm/amd/amdkfd/kfd_crat.c

index 0312231b703e10f1426d84cb4272fce6c7f4370b..4cec3a873995c869dbaba95fd7364d92bf3b9b14 100644 (file)
@@ -555,48 +555,6 @@ out_put:
        return r;
 }
 
-uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct amdgpu_device *dst,
-                                         struct amdgpu_device *src)
-{
-       struct amdgpu_device *peer_adev = src;
-       struct amdgpu_device *adev = dst;
-       int ret = amdgpu_xgmi_get_hops_count(adev, peer_adev);
-
-       if (ret < 0) {
-               DRM_ERROR("amdgpu: failed to get  xgmi hops count between node %d and %d. ret = %d\n",
-                       adev->gmc.xgmi.physical_node_id,
-                       peer_adev->gmc.xgmi.physical_node_id, ret);
-               ret = 0;
-       }
-       return  (uint8_t)ret;
-}
-
-int amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(struct amdgpu_device *dst,
-                                           struct amdgpu_device *src,
-                                           bool is_min)
-{
-       struct amdgpu_device *adev = dst, *peer_adev;
-       int num_links;
-
-       if (amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(9, 4, 2))
-               return 0;
-
-       if (src)
-               peer_adev = src;
-
-       /* num links returns 0 for indirect peers since indirect route is unknown. */
-       num_links = is_min ? 1 : amdgpu_xgmi_get_num_links(adev, peer_adev);
-       if (num_links < 0) {
-               DRM_ERROR("amdgpu: failed to get xgmi num links between node %d and %d. ret = %d\n",
-                       adev->gmc.xgmi.physical_node_id,
-                       peer_adev->gmc.xgmi.physical_node_id, num_links);
-               num_links = 0;
-       }
-
-       /* Aldebaran xGMI DPM is defeatured so assume x16 x 25Gbps for bandwidth. */
-       return (num_links * 16 * 25000)/BITS_PER_BYTE;
-}
-
 int amdgpu_amdkfd_get_pcie_bandwidth_mbytes(struct amdgpu_device *adev, bool is_min)
 {
        int num_lanes_shift = (is_min ? ffs(adev->pm.pcie_mlw_mask) :
index 55d5399676951e049b99d5592b4d41cd9c4b525f..b6ca41859b53676a37ca8aa07a61e4c8c9279eae 100644 (file)
@@ -254,11 +254,6 @@ int amdgpu_amdkfd_get_dmabuf_info(struct amdgpu_device *adev, int dma_buf_fd,
                                  uint64_t *bo_size, void *metadata_buffer,
                                  size_t buffer_size, uint32_t *metadata_size,
                                  uint32_t *flags, int8_t *xcp_id);
-uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct amdgpu_device *dst,
-                                         struct amdgpu_device *src);
-int amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(struct amdgpu_device *dst,
-                                           struct amdgpu_device *src,
-                                           bool is_min);
 int amdgpu_amdkfd_get_pcie_bandwidth_mbytes(struct amdgpu_device *adev, bool is_min);
 int amdgpu_amdkfd_send_close_event_drain_irq(struct amdgpu_device *adev,
                                        uint32_t *payload);
index c98b6b35cfdfdaae1b700da3933abea133a021ce..49da137d42c91488bd57bfa4fa2a1bc06e7fd802 100644 (file)
@@ -818,28 +818,69 @@ int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive, struct amdgpu_dev
  * num_hops[2:0] = number of hops
  */
 int amdgpu_xgmi_get_hops_count(struct amdgpu_device *adev,
-               struct amdgpu_device *peer_adev)
+                              struct amdgpu_device *peer_adev)
 {
        struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info;
        uint8_t num_hops_mask = 0x7;
        int i;
 
+       if (!adev->gmc.xgmi.supported)
+               return 0;
+
        for (i = 0 ; i < top->num_nodes; ++i)
                if (top->nodes[i].node_id == peer_adev->gmc.xgmi.node_id)
                        return top->nodes[i].num_hops & num_hops_mask;
-       return  -EINVAL;
+
+       dev_err(adev->dev, "Failed to get xgmi hops count for peer %d.\n",
+               peer_adev->gmc.xgmi.physical_node_id);
+
+       return 0;
 }
 
-int amdgpu_xgmi_get_num_links(struct amdgpu_device *adev,
-               struct amdgpu_device *peer_adev)
+int amdgpu_xgmi_get_bandwidth(struct amdgpu_device *adev, struct amdgpu_device *peer_adev,
+                             enum amdgpu_xgmi_bw_mode bw_mode, enum amdgpu_xgmi_bw_unit bw_unit,
+                             uint32_t *min_bw, uint32_t *max_bw)
 {
-       struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info;
-       int i;
+       bool peer_mode = bw_mode == AMDGPU_XGMI_BW_MODE_PER_PEER;
+       int unit_scale = bw_unit == AMDGPU_XGMI_BW_UNIT_MBYTES ? 1000 : 1;
+       int speed = 25, num_lanes = 16, num_links = !peer_mode ? 1 : -1;
 
-       for (i = 0 ; i < top->num_nodes; ++i)
-               if (top->nodes[i].node_id == peer_adev->gmc.xgmi.node_id)
-                       return top->nodes[i].num_links;
-       return  -EINVAL;
+       if (!(min_bw && max_bw))
+               return -EINVAL;
+
+       *min_bw = 0;
+       *max_bw = 0;
+
+       if (!adev->gmc.xgmi.supported)
+               return -ENODATA;
+
+       if (peer_mode && !peer_adev)
+               return -EINVAL;
+
+       if (peer_mode) {
+               struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info;
+               int i;
+
+               for (i = 0 ; i < top->num_nodes; ++i) {
+                       if (top->nodes[i].node_id != peer_adev->gmc.xgmi.node_id)
+                               continue;
+
+                       num_links =  top->nodes[i].num_links;
+                       break;
+               }
+       }
+
+       if (num_links == -1) {
+               dev_err(adev->dev, "Failed to get number of xgmi links for peer %d.\n",
+                       peer_adev->gmc.xgmi.physical_node_id);
+       } else if (num_links) {
+               int per_link_bw = (speed * num_lanes * unit_scale)/BITS_PER_BYTE;
+
+               *min_bw = per_link_bw;
+               *max_bw = num_links * per_link_bw;
+       }
+
+       return 0;
 }
 
 bool amdgpu_xgmi_get_is_sharing_enabled(struct amdgpu_device *adev,
index d1282b4c63488bead5bb7b50ec0e012de09acd0b..924da0bec50967b43b0bfd87dbd96a5dc71eae93 100644 (file)
@@ -55,6 +55,22 @@ struct amdgpu_pcs_ras_field {
        uint32_t pcs_err_shift;
 };
 
+/**
+ * Bandwidth range reporting comes in two modes.
+ *
+ * PER_LINK - range for any xgmi link
+ * PER_PEER - range of max of single xgmi link to max of multiple links based on source peer
+ */
+enum amdgpu_xgmi_bw_mode {
+       AMDGPU_XGMI_BW_MODE_PER_LINK = 0,
+       AMDGPU_XGMI_BW_MODE_PER_PEER
+};
+
+enum amdgpu_xgmi_bw_unit {
+       AMDGPU_XGMI_BW_UNIT_GBYTES = 0,
+       AMDGPU_XGMI_BW_UNIT_MBYTES
+};
+
 extern struct amdgpu_xgmi_ras  xgmi_ras;
 struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev);
 void amdgpu_put_xgmi_hive(struct amdgpu_hive_info *hive);
@@ -62,10 +78,10 @@ int amdgpu_xgmi_update_topology(struct amdgpu_hive_info *hive, struct amdgpu_dev
 int amdgpu_xgmi_add_device(struct amdgpu_device *adev);
 int amdgpu_xgmi_remove_device(struct amdgpu_device *adev);
 int amdgpu_xgmi_set_pstate(struct amdgpu_device *adev, int pstate);
-int amdgpu_xgmi_get_hops_count(struct amdgpu_device *adev,
-               struct amdgpu_device *peer_adev);
-int amdgpu_xgmi_get_num_links(struct amdgpu_device *adev,
-               struct amdgpu_device *peer_adev);
+int amdgpu_xgmi_get_hops_count(struct amdgpu_device *adev, struct amdgpu_device *peer_adev);
+int amdgpu_xgmi_get_bandwidth(struct amdgpu_device *adev, struct amdgpu_device *peer_adev,
+                             enum amdgpu_xgmi_bw_mode bw_mode, enum amdgpu_xgmi_bw_unit bw_unit,
+                             uint32_t *min_bw, uint32_t *max_bw);
 bool amdgpu_xgmi_get_is_sharing_enabled(struct amdgpu_device *adev,
                                        struct amdgpu_device *peer_adev);
 uint64_t amdgpu_xgmi_get_relative_phy_addr(struct amdgpu_device *adev,
index 70b3ae0b74febac359878578c10a9a44b8a03d6b..4a7180b46b7195a0848ba5b00b4bb54b17a2ca6e 100644 (file)
@@ -2133,9 +2133,6 @@ static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,
                bool ext_cpu = KFD_GC_VERSION(kdev) != IP_VERSION(9, 4, 3);
                int mem_bw = 819200, weight = ext_cpu ? KFD_CRAT_XGMI_WEIGHT :
                                                        KFD_CRAT_INTRA_SOCKET_WEIGHT;
-               uint32_t bandwidth = ext_cpu ? amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(
-                                                       kdev->adev, NULL, true) : mem_bw;
-
                /*
                 * with host gpu xgmi link, host can access gpu memory whether
                 * or not pcie bar type is large, so always create bidirectional
@@ -2144,8 +2141,16 @@ static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,
                sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
                sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
                sub_type_hdr->weight_xgmi = weight;
-               sub_type_hdr->minimum_bandwidth_mbs = bandwidth;
-               sub_type_hdr->maximum_bandwidth_mbs = bandwidth;
+               if (ext_cpu) {
+                       amdgpu_xgmi_get_bandwidth(kdev->adev, NULL,
+                                                 AMDGPU_XGMI_BW_MODE_PER_LINK,
+                                                 AMDGPU_XGMI_BW_UNIT_MBYTES,
+                                                 &sub_type_hdr->minimum_bandwidth_mbs,
+                                                 &sub_type_hdr->maximum_bandwidth_mbs);
+               } else {
+                       sub_type_hdr->minimum_bandwidth_mbs = mem_bw;
+                       sub_type_hdr->maximum_bandwidth_mbs = mem_bw;
+               }
        } else {
                sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_PCIEXPRESS;
                sub_type_hdr->minimum_bandwidth_mbs =
@@ -2198,12 +2203,12 @@ static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
 
        if (use_ta_info) {
                sub_type_hdr->weight_xgmi = KFD_CRAT_XGMI_WEIGHT *
-                       amdgpu_amdkfd_get_xgmi_hops_count(kdev->adev, peer_kdev->adev);
-               sub_type_hdr->maximum_bandwidth_mbs =
-                       amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(kdev->adev,
-                                                       peer_kdev->adev, false);
-               sub_type_hdr->minimum_bandwidth_mbs = sub_type_hdr->maximum_bandwidth_mbs ?
-                       amdgpu_amdkfd_get_xgmi_bandwidth_mbytes(kdev->adev, NULL, true) : 0;
+                       amdgpu_xgmi_get_hops_count(kdev->adev, peer_kdev->adev);
+               amdgpu_xgmi_get_bandwidth(kdev->adev, peer_kdev->adev,
+                                         AMDGPU_XGMI_BW_MODE_PER_PEER,
+                                         AMDGPU_XGMI_BW_UNIT_MBYTES,
+                                         &sub_type_hdr->minimum_bandwidth_mbs,
+                                         &sub_type_hdr->maximum_bandwidth_mbs);
        } else {
                bool is_single_hop = kdev->kfd == peer_kdev->kfd;
                int weight = is_single_hop ? KFD_CRAT_INTRA_SOCKET_WEIGHT :