@@ -162,78 +162,6 @@ static void retrieve_usb4_dp_bw_allocation_info(struct dc_link *link)
162162 link -> dpia_bw_alloc_config .nrd_max_lane_count );
163163}
164164
165- static uint8_t get_lowest_dpia_index (struct dc_link * link )
166- {
167- const struct dc * dc_struct = link -> dc ;
168- uint8_t idx = 0xFF ;
169- int i ;
170-
171- for (i = 0 ; i < MAX_LINKS ; ++ i ) {
172-
173- if (!dc_struct -> links [i ] ||
174- dc_struct -> links [i ]-> ep_type != DISPLAY_ENDPOINT_USB4_DPIA )
175- continue ;
176-
177- if (idx > dc_struct -> links [i ]-> link_index ) {
178- idx = dc_struct -> links [i ]-> link_index ;
179- break ;
180- }
181- }
182-
183- return idx ;
184- }
185-
186- /*
187- * Get the maximum dp tunnel banwidth of host router
188- *
189- * @dc: pointer to the dc struct instance
190- * @hr_index: host router index
191- *
192- * return: host router maximum dp tunnel bandwidth
193- */
194- static int get_host_router_total_dp_tunnel_bw (const struct dc * dc , uint8_t hr_index )
195- {
196- uint8_t lowest_dpia_index = get_lowest_dpia_index (dc -> links [0 ]);
197- uint8_t hr_index_temp = 0 ;
198- struct dc_link * link_dpia_primary , * link_dpia_secondary ;
199- int total_bw = 0 ;
200-
201- for (uint8_t i = 0 ; i < MAX_LINKS - 1 ; ++ i ) {
202-
203- if (!dc -> links [i ] || dc -> links [i ]-> ep_type != DISPLAY_ENDPOINT_USB4_DPIA )
204- continue ;
205-
206- hr_index_temp = (dc -> links [i ]-> link_index - lowest_dpia_index ) / 2 ;
207-
208- if (hr_index_temp == hr_index ) {
209- link_dpia_primary = dc -> links [i ];
210- link_dpia_secondary = dc -> links [i + 1 ];
211-
212- /**
213- * If BW allocation enabled on both DPIAs, then
214- * HR BW = Estimated(dpia_primary) + Allocated(dpia_secondary)
215- * otherwise HR BW = Estimated(bw alloc enabled dpia)
216- */
217- if ((link_dpia_primary -> hpd_status &&
218- link_dpia_primary -> dpia_bw_alloc_config .bw_alloc_enabled ) &&
219- (link_dpia_secondary -> hpd_status &&
220- link_dpia_secondary -> dpia_bw_alloc_config .bw_alloc_enabled )) {
221- total_bw += link_dpia_primary -> dpia_bw_alloc_config .estimated_bw +
222- link_dpia_secondary -> dpia_bw_alloc_config .allocated_bw ;
223- } else if (link_dpia_primary -> hpd_status &&
224- link_dpia_primary -> dpia_bw_alloc_config .bw_alloc_enabled ) {
225- total_bw = link_dpia_primary -> dpia_bw_alloc_config .estimated_bw ;
226- } else if (link_dpia_secondary -> hpd_status &&
227- link_dpia_secondary -> dpia_bw_alloc_config .bw_alloc_enabled ) {
228- total_bw += link_dpia_secondary -> dpia_bw_alloc_config .estimated_bw ;
229- }
230- break ;
231- }
232- }
233-
234- return total_bw ;
235- }
236-
237165/*
238166 * Cleanup function for when the dpia is unplugged to reset struct
239167 * and perform any required clean up
@@ -398,54 +326,9 @@ void link_dp_dpia_allocate_usb4_bandwidth_for_stream(struct dc_link *link, int r
398326 DC_LOG_DEBUG ("%s: BW Allocation mode not available" , __func__ );
399327}
400328
401- bool dpia_validate_usb4_bw (struct dc_link * * link , int * bw_needed_per_dpia , const unsigned int num_dpias )
402- {
403- bool ret = true;
404- int bw_needed_per_hr [MAX_HOST_ROUTERS_NUM ] = { 0 };
405- int host_router_total_dp_bw = 0 ;
406- uint8_t lowest_dpia_index , i , hr_index ;
407-
408- if (!num_dpias || num_dpias > MAX_DPIA_NUM )
409- return ret ;
410-
411- lowest_dpia_index = get_lowest_dpia_index (link [0 ]);
412-
413- /* get total Host Router BW with granularity for the given modes */
414- for (i = 0 ; i < num_dpias ; ++ i ) {
415- int granularity_Gbps = 0 ;
416- int bw_granularity = 0 ;
417-
418- if (!link [i ]-> dpia_bw_alloc_config .bw_alloc_enabled )
419- continue ;
420-
421- if (link [i ]-> link_index < lowest_dpia_index )
422- continue ;
423-
424- granularity_Gbps = (Kbps_TO_Gbps / link [i ]-> dpia_bw_alloc_config .bw_granularity );
425- bw_granularity = (bw_needed_per_dpia [i ] / granularity_Gbps ) * granularity_Gbps +
426- ((bw_needed_per_dpia [i ] % granularity_Gbps ) ? granularity_Gbps : 0 );
427-
428- hr_index = (link [i ]-> link_index - lowest_dpia_index ) / 2 ;
429- bw_needed_per_hr [hr_index ] += bw_granularity ;
430- }
431-
432- /* validate against each Host Router max BW */
433- for (hr_index = 0 ; hr_index < MAX_HOST_ROUTERS_NUM ; ++ hr_index ) {
434- if (bw_needed_per_hr [hr_index ]) {
435- host_router_total_dp_bw = get_host_router_total_dp_tunnel_bw (link [0 ]-> dc , hr_index );
436- if (bw_needed_per_hr [hr_index ] > host_router_total_dp_bw ) {
437- ret = false;
438- break ;
439- }
440- }
441- }
442-
443- return ret ;
444- }
445-
446- uint32_t link_dpia_get_dp_mst_overhead (const struct dc_link * link )
329+ uint32_t link_dpia_get_dp_overhead (const struct dc_link * link )
447330{
448- uint32_t link_mst_overhead = 0 ;
331+ uint32_t link_dp_overhead = 0 ;
449332
450333 if ((link -> type == dc_connection_mst_branch ) &&
451334 !link -> dpcd_caps .channel_coding_cap .bits .DP_128b_132b_SUPPORTED ) {
@@ -458,12 +341,12 @@ uint32_t link_dpia_get_dp_mst_overhead(const struct dc_link *link)
458341 uint32_t link_bw_in_kbps = (uint32_t )link_cap -> link_rate *
459342 (uint32_t )link_cap -> lane_count *
460343 LINK_RATE_REF_FREQ_IN_KHZ * 8 ;
461- link_mst_overhead = (link_bw_in_kbps / MST_TIME_SLOT_COUNT )
344+ link_dp_overhead = (link_bw_in_kbps / MST_TIME_SLOT_COUNT )
462345 + ((link_bw_in_kbps % MST_TIME_SLOT_COUNT ) ? 1 : 0 );
463346 }
464347 }
465348
466- return link_mst_overhead ;
349+ return link_dp_overhead ;
467350}
468351
469352/*
@@ -484,11 +367,13 @@ bool link_dpia_validate_dp_tunnel_bandwidth(const struct dc_validation_dpia_set
484367 struct usb4_router_validation_set router_sets [MAX_HOST_ROUTERS_NUM ] = { 0 };
485368 uint8_t i ;
486369 bool is_success = true;
487- uint8_t rounter_count = 0 ;
370+ uint8_t router_count = 0 ;
488371
489372 if ((dpia_link_sets == NULL ) || (count == 0 ))
490373 return is_success ;
491374
375+ // Iterate through each DP tunneling link (DPIA).
376+ // Aggregate its bandwidth requirements onto the respective USB4 router.
492377 for (i = 0 ; i < count ; i ++ ) {
493378 link = dpia_link_sets [i ].link ;
494379 link_required_bw = dpia_link_sets [i ].required_bw ;
@@ -498,17 +383,18 @@ bool link_dpia_validate_dp_tunnel_bandwidth(const struct dc_validation_dpia_set
498383 break ;
499384
500385 if (link -> type == dc_connection_mst_branch )
501- link_required_bw += link_dpia_get_dp_mst_overhead (link );
386+ link_required_bw += link_dpia_get_dp_overhead (link );
502387
503388 granularity_Gbps = (Kbps_TO_Gbps / dp_tunnel_settings -> bw_granularity );
504389 link_bw_granularity = (link_required_bw / granularity_Gbps ) * granularity_Gbps +
505390 ((link_required_bw % granularity_Gbps ) ? granularity_Gbps : 0 );
506391
392+ // Find or add the USB4 router associated with the current DPIA link
507393 for (uint8_t j = 0 ; j < MAX_HOST_ROUTERS_NUM ; j ++ ) {
508394 if (router_sets [j ].is_valid == false) {
509395 router_sets [j ].is_valid = true;
510396 router_sets [j ].cm_id = dp_tunnel_settings -> cm_id ;
511- rounter_count ++ ;
397+ router_count ++ ;
512398 }
513399
514400 if (router_sets [j ].cm_id == dp_tunnel_settings -> cm_id ) {
@@ -531,12 +417,14 @@ bool link_dpia_validate_dp_tunnel_bandwidth(const struct dc_validation_dpia_set
531417 }
532418 }
533419
534- for (i = 0 ; i < rounter_count ; i ++ ) {
420+ // Validate bandwidth for each unique router found.
421+ for (i = 0 ; i < router_count ; i ++ ) {
535422 uint32_t total_bw = 0 ;
536423
537424 if (router_sets [i ].is_valid == false)
538425 break ;
539426
427+ // Determine the total available bandwidth for the current router based on aggregated data
540428 if ((router_sets [i ].dpia_count == 1 ) || (router_sets [i ].allocated_bw == 0 ))
541429 total_bw = router_sets [i ].estimated_bw ;
542430 else
0 commit comments