@@ -380,6 +380,9 @@ static ssize_t retimer_sb_regs_write(struct file *file,
380
380
/**
381
381
* struct tb_margining - Lane margining support
382
382
* @port: USB4 port through which the margining operations are run
383
+ * @target: Sideband target
384
+ * @index: Retimer index if taget is %USB4_SB_TARGET_RETIMER
385
+ * @dev: Pointer to the device that is the target (USB4 port or retimer)
383
386
* @caps: Port lane margining capabilities
384
387
* @results: Last lane margining results
385
388
* @lanes: %0, %1 or %7 (all)
@@ -397,6 +400,9 @@ static ssize_t retimer_sb_regs_write(struct file *file,
397
400
*/
398
401
struct tb_margining {
399
402
struct tb_port * port ;
403
+ enum usb4_sb_target target ;
404
+ u8 index ;
405
+ struct device * dev ;
400
406
u32 caps [2 ];
401
407
u32 results [2 ];
402
408
unsigned int lanes ;
@@ -736,6 +742,7 @@ static int margining_run_write(void *data, u64 val)
736
742
{
737
743
struct tb_margining * margining = data ;
738
744
struct tb_port * port = margining -> port ;
745
+ struct device * dev = margining -> dev ;
739
746
struct tb_switch * sw = port -> sw ;
740
747
struct tb_switch * down_sw ;
741
748
struct tb * tb = sw -> tb ;
@@ -744,7 +751,7 @@ static int margining_run_write(void *data, u64 val)
744
751
if (val != 1 )
745
752
return - EINVAL ;
746
753
747
- pm_runtime_get_sync (& sw -> dev );
754
+ pm_runtime_get_sync (dev );
748
755
749
756
if (mutex_lock_interruptible (& tb -> lock )) {
750
757
ret = - ERESTARTSYS ;
@@ -772,24 +779,29 @@ static int margining_run_write(void *data, u64 val)
772
779
}
773
780
774
781
if (margining -> software ) {
775
- tb_port_dbg (port , "running software %s lane margining for lanes %u\n" ,
776
- margining -> time ? "time" : "voltage" , margining -> lanes );
777
- ret = usb4_port_sw_margin (port , USB4_SB_TARGET_ROUTER , 0 ,
782
+ tb_port_dbg (port ,
783
+ "running software %s lane margining for %s lanes %u\n" ,
784
+ margining -> time ? "time" : "voltage" , dev_name (dev ),
785
+ margining -> lanes );
786
+ ret = usb4_port_sw_margin (port , margining -> target , margining -> index ,
778
787
margining -> lanes , margining -> time ,
779
788
margining -> right_high ,
780
789
USB4_MARGIN_SW_COUNTER_CLEAR );
781
790
if (ret )
782
791
goto out_clx ;
783
792
784
- ret = usb4_port_sw_margin_errors (port , USB4_SB_TARGET_ROUTER , 0 ,
793
+ ret = usb4_port_sw_margin_errors (port , margining -> target ,
794
+ margining -> index ,
785
795
& margining -> results [0 ]);
786
796
} else {
787
- tb_port_dbg (port , "running hardware %s lane margining for lanes %u\n" ,
788
- margining -> time ? "time" : "voltage" , margining -> lanes );
797
+ tb_port_dbg (port ,
798
+ "running hardware %s lane margining for %s lanes %u\n" ,
799
+ margining -> time ? "time" : "voltage" , dev_name (dev ),
800
+ margining -> lanes );
789
801
/* Clear the results */
790
802
margining -> results [0 ] = 0 ;
791
803
margining -> results [1 ] = 0 ;
792
- ret = usb4_port_hw_margin (port , USB4_SB_TARGET_ROUTER , 0 ,
804
+ ret = usb4_port_hw_margin (port , margining -> target , margining -> index ,
793
805
margining -> lanes , margining -> ber_level ,
794
806
margining -> time , margining -> right_high ,
795
807
margining -> results );
@@ -801,8 +813,8 @@ static int margining_run_write(void *data, u64 val)
801
813
out_unlock :
802
814
mutex_unlock (& tb -> lock );
803
815
out_rpm_put :
804
- pm_runtime_mark_last_busy (& sw -> dev );
805
- pm_runtime_put_autosuspend (& sw -> dev );
816
+ pm_runtime_mark_last_busy (dev );
817
+ pm_runtime_put_autosuspend (dev );
806
818
807
819
return ret ;
808
820
}
@@ -1044,33 +1056,29 @@ static int margining_margin_show(struct seq_file *s, void *not_used)
1044
1056
}
1045
1057
DEBUGFS_ATTR_RW (margining_margin );
1046
1058
1047
- static void margining_port_init (struct tb_port * port )
1059
+ static struct tb_margining * margining_alloc (struct tb_port * port ,
1060
+ struct device * dev ,
1061
+ enum usb4_sb_target target ,
1062
+ u8 index , struct dentry * parent )
1048
1063
{
1049
1064
struct tb_margining * margining ;
1050
- struct dentry * dir , * parent ;
1051
- struct usb4_port * usb4 ;
1052
- char dir_name [10 ];
1065
+ struct dentry * dir ;
1053
1066
unsigned int val ;
1054
1067
int ret ;
1055
1068
1056
- usb4 = port -> usb4 ;
1057
- if (!usb4 )
1058
- return ;
1059
-
1060
- snprintf (dir_name , sizeof (dir_name ), "port%d" , port -> port );
1061
- parent = debugfs_lookup (dir_name , port -> sw -> debugfs_dir );
1062
-
1063
1069
margining = kzalloc (sizeof (* margining ), GFP_KERNEL );
1064
1070
if (!margining )
1065
- return ;
1071
+ return NULL ;
1066
1072
1067
1073
margining -> port = port ;
1074
+ margining -> target = target ;
1075
+ margining -> index = index ;
1076
+ margining -> dev = dev ;
1068
1077
1069
- ret = usb4_port_margining_caps (port , USB4_SB_TARGET_ROUTER , 0 ,
1070
- margining -> caps );
1078
+ ret = usb4_port_margining_caps (port , target , index , margining -> caps );
1071
1079
if (ret ) {
1072
1080
kfree (margining );
1073
- return ;
1081
+ return NULL ;
1074
1082
}
1075
1083
1076
1084
/* Set the initial mode */
@@ -1124,8 +1132,22 @@ static void margining_port_init(struct tb_port *port)
1124
1132
independent_time_margins (margining ) == USB4_MARGIN_CAP_1_TIME_LR ))
1125
1133
debugfs_create_file ("margin" , 0600 , dir , margining ,
1126
1134
& margining_margin_fops );
1135
+ return margining ;
1136
+ }
1127
1137
1128
- usb4 -> margining = margining ;
1138
+ static void margining_port_init (struct tb_port * port )
1139
+ {
1140
+ struct dentry * parent ;
1141
+ char dir_name [10 ];
1142
+
1143
+ if (!port -> usb4 )
1144
+ return ;
1145
+
1146
+ snprintf (dir_name , sizeof (dir_name ), "port%d" , port -> port );
1147
+ parent = debugfs_lookup (dir_name , port -> sw -> debugfs_dir );
1148
+ port -> usb4 -> margining = margining_alloc (port , & port -> usb4 -> dev ,
1149
+ USB4_SB_TARGET_ROUTER , 0 ,
1150
+ parent );
1129
1151
}
1130
1152
1131
1153
static void margining_port_remove (struct tb_port * port )
@@ -1199,11 +1221,27 @@ static void margining_xdomain_remove(struct tb_xdomain *xd)
1199
1221
downstream = tb_port_at (xd -> route , parent_sw );
1200
1222
margining_port_remove (downstream );
1201
1223
}
1224
+
1225
+ static void margining_retimer_init (struct tb_retimer * rt , struct dentry * debugfs_dir )
1226
+ {
1227
+ rt -> margining = margining_alloc (rt -> port , & rt -> dev ,
1228
+ USB4_SB_TARGET_RETIMER , rt -> index ,
1229
+ debugfs_dir );
1230
+ }
1231
+
1232
+ static void margining_retimer_remove (struct tb_retimer * rt )
1233
+ {
1234
+ kfree (rt -> margining );
1235
+ rt -> margining = NULL ;
1236
+ }
1202
1237
#else
1203
1238
static inline void margining_switch_init (struct tb_switch * sw ) { }
1204
1239
static inline void margining_switch_remove (struct tb_switch * sw ) { }
1205
1240
static inline void margining_xdomain_init (struct tb_xdomain * xd ) { }
1206
1241
static inline void margining_xdomain_remove (struct tb_xdomain * xd ) { }
1242
+ static inline void margining_retimer_init (struct tb_retimer * rt ,
1243
+ struct dentry * debugfs_dir ) { }
1244
+ static inline void margining_retimer_remove (struct tb_retimer * rt ) { }
1207
1245
#endif
1208
1246
1209
1247
static int port_clear_all_counters (struct tb_port * port )
@@ -1864,6 +1902,7 @@ void tb_retimer_debugfs_init(struct tb_retimer *rt)
1864
1902
debugfs_dir = debugfs_create_dir (dev_name (& rt -> dev ), tb_debugfs_root );
1865
1903
debugfs_create_file ("sb_regs" , DEBUGFS_MODE , debugfs_dir , rt ,
1866
1904
& retimer_sb_regs_fops );
1905
+ margining_retimer_init (rt , debugfs_dir );
1867
1906
}
1868
1907
1869
1908
/**
@@ -1875,6 +1914,7 @@ void tb_retimer_debugfs_init(struct tb_retimer *rt)
1875
1914
void tb_retimer_debugfs_remove (struct tb_retimer * rt )
1876
1915
{
1877
1916
debugfs_lookup_and_remove (dev_name (& rt -> dev ), tb_debugfs_root );
1917
+ margining_retimer_remove (rt );
1878
1918
}
1879
1919
1880
1920
void tb_debugfs_init (void )
0 commit comments