Lines Matching +full:lane +full:- +full:count
1 // SPDX-License-Identifier: GPL-2.0
87 return single_open(file, __space ## _show, inode->i_private); \
108 size_t *count) in validate_and_copy_from_user() argument
113 if (!*count) in validate_and_copy_from_user()
114 return ERR_PTR(-EINVAL); in validate_and_copy_from_user()
116 if (!access_ok(user_buf, *count)) in validate_and_copy_from_user()
117 return ERR_PTR(-EFAULT); in validate_and_copy_from_user()
121 return ERR_PTR(-ENOMEM); in validate_and_copy_from_user()
123 nbytes = min_t(size_t, *count, PAGE_SIZE); in validate_and_copy_from_user()
126 return ERR_PTR(-EFAULT); in validate_and_copy_from_user()
129 *count = nbytes; in validate_and_copy_from_user()
163 *val = v[short_fmt_len - 1]; in parse_line()
167 *val = v[long_fmt_len - 1]; in parse_line()
176 const char __user *user_buf, size_t count, in regs_write() argument
179 struct tb *tb = sw->tb; in regs_write()
184 buf = validate_and_copy_from_user(user_buf, &count); in regs_write()
188 pm_runtime_get_sync(&sw->dev); in regs_write()
190 if (mutex_lock_interruptible(&tb->lock)) { in regs_write()
191 ret = -ERESTARTSYS; in regs_write()
208 mutex_unlock(&tb->lock); in regs_write()
211 pm_runtime_mark_last_busy(&sw->dev); in regs_write()
212 pm_runtime_put_autosuspend(&sw->dev); in regs_write()
215 return ret < 0 ? ret : count; in regs_write()
219 size_t count, loff_t *ppos) in port_regs_write() argument
221 struct seq_file *s = file->private_data; in port_regs_write()
222 struct tb_port *port = s->private; in port_regs_write()
224 return regs_write(port->sw, port, user_buf, count, ppos); in port_regs_write()
228 size_t count, loff_t *ppos) in switch_regs_write() argument
230 struct seq_file *s = file->private_data; in switch_regs_write()
231 struct tb_switch *sw = s->private; in switch_regs_write()
233 return regs_write(sw, NULL, user_buf, count, ppos); in switch_regs_write()
268 char *buf, size_t count, loff_t *ppos) in sb_regs_write() argument
291 return -EINVAL; in sb_regs_write()
303 return -EINVAL; in sb_regs_write()
305 if (bytes_read > sb_regs->size) in sb_regs_write()
306 return -E2BIG; in sb_regs_write()
308 ret = usb4_port_sb_write(port, target, index, sb_reg->reg, data, in sb_regs_write()
318 size_t count, loff_t *ppos) in port_sb_regs_write() argument
320 struct seq_file *s = file->private_data; in port_sb_regs_write()
321 struct tb_port *port = s->private; in port_sb_regs_write()
322 struct tb_switch *sw = port->sw; in port_sb_regs_write()
323 struct tb *tb = sw->tb; in port_sb_regs_write()
327 buf = validate_and_copy_from_user(user_buf, &count); in port_sb_regs_write()
331 pm_runtime_get_sync(&sw->dev); in port_sb_regs_write()
333 if (mutex_lock_interruptible(&tb->lock)) { in port_sb_regs_write()
334 ret = -ERESTARTSYS; in port_sb_regs_write()
339 USB4_SB_TARGET_ROUTER, 0, buf, count, ppos); in port_sb_regs_write()
341 mutex_unlock(&tb->lock); in port_sb_regs_write()
343 pm_runtime_mark_last_busy(&sw->dev); in port_sb_regs_write()
344 pm_runtime_put_autosuspend(&sw->dev); in port_sb_regs_write()
347 return ret < 0 ? ret : count; in port_sb_regs_write()
352 size_t count, loff_t *ppos) in retimer_sb_regs_write() argument
354 struct seq_file *s = file->private_data; in retimer_sb_regs_write()
355 struct tb_retimer *rt = s->private; in retimer_sb_regs_write()
356 struct tb *tb = rt->tb; in retimer_sb_regs_write()
360 buf = validate_and_copy_from_user(user_buf, &count); in retimer_sb_regs_write()
364 pm_runtime_get_sync(&rt->dev); in retimer_sb_regs_write()
366 if (mutex_lock_interruptible(&tb->lock)) { in retimer_sb_regs_write()
367 ret = -ERESTARTSYS; in retimer_sb_regs_write()
371 ret = sb_regs_write(rt->port, retimer_sb_regs, ARRAY_SIZE(retimer_sb_regs), in retimer_sb_regs_write()
372 USB4_SB_TARGET_RETIMER, rt->index, buf, count, ppos); in retimer_sb_regs_write()
374 mutex_unlock(&tb->lock); in retimer_sb_regs_write()
376 pm_runtime_mark_last_busy(&rt->dev); in retimer_sb_regs_write()
377 pm_runtime_put_autosuspend(&rt->dev); in retimer_sb_regs_write()
380 return ret < 0 ? ret : count; in retimer_sb_regs_write()
393 * struct tb_margining - Lane margining support
398 * @caps: Port lane margining capabilities
399 * @results: Last lane margining results
450 struct tb_port *port = margining->port; in margining_modify_error_counter()
455 return -EOPNOTSUPP; in margining_modify_error_counter()
460 return usb4_port_sw_margin(port, margining->target, margining->index, in margining_modify_error_counter()
466 return margining->caps[0] & USB4_MARGIN_CAP_0_MODES_SW; in supports_software()
471 return margining->caps[0] & USB4_MARGIN_CAP_0_MODES_HW; in supports_hardware()
476 return margining->caps[0] & USB4_MARGIN_CAP_0_2_LANES; in both_lanes()
482 return FIELD_GET(USB4_MARGIN_CAP_0_VOLTAGE_INDP_MASK, margining->caps[0]); in independent_voltage_margins()
487 return margining->caps[0] & USB4_MARGIN_CAP_0_TIME; in supports_time()
494 return FIELD_GET(USB4_MARGIN_CAP_1_TIME_INDP_MASK, margining->caps[1]); in independent_time_margins()
500 return margining->caps[0] & USB4_MARGIN_CAP_0_OPT_VOLTAGE_SUPPORT; in supports_optional_voltage_offset_range()
505 size_t count, loff_t *ppos) in margining_ber_level_write() argument
507 struct seq_file *s = file->private_data; in margining_ber_level_write()
508 struct tb_margining *margining = s->private; in margining_ber_level_write()
509 struct tb *tb = margining->port->sw->tb; in margining_ber_level_write()
514 if (mutex_lock_interruptible(&tb->lock)) in margining_ber_level_write()
515 return -ERESTARTSYS; in margining_ber_level_write()
517 if (margining->software) { in margining_ber_level_write()
518 ret = -EINVAL; in margining_ber_level_write()
522 buf = validate_and_copy_from_user(user_buf, &count); in margining_ber_level_write()
528 buf[count - 1] = '\0'; in margining_ber_level_write()
534 if (val < margining->min_ber_level || in margining_ber_level_write()
535 val > margining->max_ber_level) { in margining_ber_level_write()
536 ret = -EINVAL; in margining_ber_level_write()
540 margining->ber_level = val; in margining_ber_level_write()
545 mutex_unlock(&tb->lock); in margining_ber_level_write()
547 return ret < 0 ? ret : count; in margining_ber_level_write()
553 seq_printf(s, "3 * 1e%d (%u)\n", -12 + (val + 1) / 2, val); in ber_level_show()
555 seq_printf(s, "1e%d (%u)\n", -12 + val / 2, val); in ber_level_show()
560 const struct tb_margining *margining = s->private; in margining_ber_level_show()
562 if (margining->software) in margining_ber_level_show()
563 return -EINVAL; in margining_ber_level_show()
564 ber_level_show(s, margining->ber_level); in margining_ber_level_show()
571 struct tb_margining *margining = s->private; in margining_caps_show()
572 struct tb *tb = margining->port->sw->tb; in margining_caps_show()
575 if (mutex_lock_interruptible(&tb->lock)) in margining_caps_show()
576 return -ERESTARTSYS; in margining_caps_show()
579 cap0 = margining->caps[0]; in margining_caps_show()
581 cap1 = margining->caps[1]; in margining_caps_show()
589 ber_level_show(s, margining->min_ber_level); in margining_caps_show()
591 ber_level_show(s, margining->max_ber_level); in margining_caps_show()
599 margining->voltage_steps); in margining_caps_show()
601 margining->max_voltage_offset); in margining_caps_show()
606 margining->voltage_steps_optional_range); in margining_caps_show()
608 margining->max_voltage_offset_optional_range); in margining_caps_show()
641 margining->time_steps); in margining_caps_show()
643 margining->max_time_offset); in margining_caps_show()
648 mutex_unlock(&tb->lock); in margining_caps_show()
655 size_t count, loff_t *ppos) in margining_lanes_write() argument
657 struct seq_file *s = file->private_data; in margining_lanes_write()
658 struct tb_margining *margining = s->private; in margining_lanes_write()
659 struct tb *tb = margining->port->sw->tb; in margining_lanes_write()
663 buf = validate_and_copy_from_user(user_buf, &count); in margining_lanes_write()
667 buf[count - 1] = '\0'; in margining_lanes_write()
669 if (mutex_lock_interruptible(&tb->lock)) { in margining_lanes_write()
670 ret = -ERESTARTSYS; in margining_lanes_write()
675 margining->lanes = 0; in margining_lanes_write()
677 margining->lanes = 1; in margining_lanes_write()
681 margining->lanes = 7; in margining_lanes_write()
683 ret = -EINVAL; in margining_lanes_write()
685 ret = -EINVAL; in margining_lanes_write()
688 mutex_unlock(&tb->lock); in margining_lanes_write()
692 return ret < 0 ? ret : count; in margining_lanes_write()
697 struct tb_margining *margining = s->private; in margining_lanes_show()
698 struct tb *tb = margining->port->sw->tb; in margining_lanes_show()
701 if (mutex_lock_interruptible(&tb->lock)) in margining_lanes_show()
702 return -ERESTARTSYS; in margining_lanes_show()
704 lanes = margining->lanes; in margining_lanes_show()
719 mutex_unlock(&tb->lock); in margining_lanes_show()
727 size_t count, loff_t *ppos) in margining_voltage_time_offset_write() argument
729 struct seq_file *s = file->private_data; in margining_voltage_time_offset_write()
730 struct tb_margining *margining = s->private; in margining_voltage_time_offset_write()
731 struct tb *tb = margining->port->sw->tb; in margining_voltage_time_offset_write()
736 ret = kstrtouint_from_user(user_buf, count, 10, &val); in margining_voltage_time_offset_write()
740 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { in margining_voltage_time_offset_write()
741 if (!margining->software) in margining_voltage_time_offset_write()
742 return -EOPNOTSUPP; in margining_voltage_time_offset_write()
744 if (margining->time) in margining_voltage_time_offset_write()
745 max_margin = margining->time_steps; in margining_voltage_time_offset_write()
747 if (margining->optional_voltage_offset_range) in margining_voltage_time_offset_write()
748 max_margin = margining->voltage_steps_optional_range; in margining_voltage_time_offset_write()
750 max_margin = margining->voltage_steps; in margining_voltage_time_offset_write()
752 margining->voltage_time_offset = clamp(val, 0, max_margin); in margining_voltage_time_offset_write()
755 return count; in margining_voltage_time_offset_write()
761 const struct tb_margining *margining = s->private; in margining_voltage_time_offset_show()
762 struct tb *tb = margining->port->sw->tb; in margining_voltage_time_offset_show()
764 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { in margining_voltage_time_offset_show()
765 if (!margining->software) in margining_voltage_time_offset_show()
766 return -EOPNOTSUPP; in margining_voltage_time_offset_show()
768 seq_printf(s, "%d\n", margining->voltage_time_offset); in margining_voltage_time_offset_show()
777 size_t count, loff_t *ppos) in margining_error_counter_write() argument
780 struct seq_file *s = file->private_data; in margining_error_counter_write()
781 struct tb_margining *margining = s->private; in margining_error_counter_write()
782 struct tb *tb = margining->port->sw->tb; in margining_error_counter_write()
785 buf = validate_and_copy_from_user(user_buf, &count); in margining_error_counter_write()
789 buf[count - 1] = '\0'; in margining_error_counter_write()
800 return -EINVAL; in margining_error_counter_write()
802 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { in margining_error_counter_write()
803 if (!margining->software) in margining_error_counter_write()
804 return -EOPNOTSUPP; in margining_error_counter_write()
806 margining->error_counter = error_counter; in margining_error_counter_write()
809 return count; in margining_error_counter_write()
814 const struct tb_margining *margining = s->private; in margining_error_counter_show()
815 struct tb *tb = margining->port->sw->tb; in margining_error_counter_show()
817 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { in margining_error_counter_show()
818 if (!margining->software) in margining_error_counter_show()
819 return -EOPNOTSUPP; in margining_error_counter_show()
821 switch (margining->error_counter) { in margining_error_counter_show()
843 size_t count, loff_t *ppos) in margining_dwell_time_write() argument
845 struct seq_file *s = file->private_data; in margining_dwell_time_write()
846 struct tb_margining *margining = s->private; in margining_dwell_time_write()
847 struct tb *tb = margining->port->sw->tb; in margining_dwell_time_write()
851 ret = kstrtouint_from_user(user_buf, count, 10, &val); in margining_dwell_time_write()
855 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { in margining_dwell_time_write()
856 if (!margining->software) in margining_dwell_time_write()
857 return -EOPNOTSUPP; in margining_dwell_time_write()
859 margining->dwell_time = clamp(val, MIN_DWELL_TIME, MAX_DWELL_TIME); in margining_dwell_time_write()
862 return count; in margining_dwell_time_write()
867 struct tb_margining *margining = s->private; in margining_dwell_time_show()
868 struct tb *tb = margining->port->sw->tb; in margining_dwell_time_show()
870 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { in margining_dwell_time_show()
871 if (!margining->software) in margining_dwell_time_show()
872 return -EOPNOTSUPP; in margining_dwell_time_show()
874 seq_printf(s, "%d\n", margining->dwell_time); in margining_dwell_time_show()
883 size_t count, loff_t *ppos) in margining_optional_voltage_offset_write() argument
885 struct seq_file *s = file->private_data; in margining_optional_voltage_offset_write()
886 struct tb_margining *margining = s->private; in margining_optional_voltage_offset_write()
887 struct tb *tb = margining->port->sw->tb; in margining_optional_voltage_offset_write()
891 ret = kstrtobool_from_user(user_buf, count, &val); in margining_optional_voltage_offset_write()
895 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { in margining_optional_voltage_offset_write()
896 margining->optional_voltage_offset_range = val; in margining_optional_voltage_offset_write()
899 return count; in margining_optional_voltage_offset_write()
905 struct tb_margining *margining = s->private; in margining_optional_voltage_offset_show()
906 struct tb *tb = margining->port->sw->tb; in margining_optional_voltage_offset_show()
908 scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &tb->lock) { in margining_optional_voltage_offset_show()
909 seq_printf(s, "%u\n", margining->optional_voltage_offset_range); in margining_optional_voltage_offset_show()
918 size_t count, loff_t *ppos) in margining_mode_write() argument
920 struct seq_file *s = file->private_data; in margining_mode_write()
921 struct tb_margining *margining = s->private; in margining_mode_write()
922 struct tb *tb = margining->port->sw->tb; in margining_mode_write()
926 buf = validate_and_copy_from_user(user_buf, &count); in margining_mode_write()
930 buf[count - 1] = '\0'; in margining_mode_write()
932 if (mutex_lock_interruptible(&tb->lock)) { in margining_mode_write()
933 ret = -ERESTARTSYS; in margining_mode_write()
939 margining->software = true; in margining_mode_write()
941 ret = -EINVAL; in margining_mode_write()
944 margining->software = false; in margining_mode_write()
946 ret = -EINVAL; in margining_mode_write()
948 ret = -EINVAL; in margining_mode_write()
951 mutex_unlock(&tb->lock); in margining_mode_write()
955 return ret ? ret : count; in margining_mode_write()
960 struct tb_margining *margining = s->private; in margining_mode_show()
961 struct tb *tb = margining->port->sw->tb; in margining_mode_show()
964 if (mutex_lock_interruptible(&tb->lock)) in margining_mode_show()
965 return -ERESTARTSYS; in margining_mode_show()
968 if (margining->software) in margining_mode_show()
975 if (margining->software) in margining_mode_show()
981 mutex_unlock(&tb->lock); in margining_mode_show()
991 u32 nsamples = margining->dwell_time / DWELL_SAMPLE_INTERVAL; in margining_run_sw()
994 ret = usb4_port_sw_margin(margining->port, margining->target, margining->index, in margining_run_sw()
995 params, margining->results); in margining_run_sw()
1002 ret = usb4_port_sw_margin_errors(margining->port, margining->target, in margining_run_sw()
1003 margining->index, &margining->results[1]); in margining_run_sw()
1007 if (margining->lanes == USB4_MARGIN_SW_LANE_0) in margining_run_sw()
1009 margining->results[1]); in margining_run_sw()
1010 else if (margining->lanes == USB4_MARGIN_SW_LANE_1) in margining_run_sw()
1012 margining->results[1]); in margining_run_sw()
1013 else if (margining->lanes == USB4_MARGIN_SW_ALL_LANES) in margining_run_sw()
1014 errors = margining->results[1]; in margining_run_sw()
1028 margining_modify_error_counter(margining, margining->lanes, in margining_run_sw()
1036 struct tb_port *port = margining->port; in margining_run_write()
1037 struct device *dev = margining->dev; in margining_run_write()
1038 struct tb_switch *sw = port->sw; in margining_run_write()
1040 struct tb *tb = sw->tb; in margining_run_write()
1044 return -EINVAL; in margining_run_write()
1048 if (mutex_lock_interruptible(&tb->lock)) { in margining_run_write()
1049 ret = -ERESTARTSYS; in margining_run_write()
1055 else if (port->remote) in margining_run_write()
1056 down_sw = port->remote->sw; in margining_run_write()
1062 * CL states may interfere with lane margining so in margining_run_write()
1074 memset(margining->results, 0, sizeof(margining->results)); in margining_run_write()
1076 if (margining->software) { in margining_run_write()
1079 .lanes = margining->lanes, in margining_run_write()
1080 .time = margining->time, in margining_run_write()
1081 .voltage_time_offset = margining->voltage_time_offset, in margining_run_write()
1082 .right_high = margining->right_high, in margining_run_write()
1083 .optional_voltage_offset_range = margining->optional_voltage_offset_range, in margining_run_write()
1087 "running software %s lane margining for %s lanes %u\n", in margining_run_write()
1088 margining->time ? "time" : "voltage", dev_name(dev), in margining_run_write()
1089 margining->lanes); in margining_run_write()
1094 .ber_level = margining->ber_level, in margining_run_write()
1095 .lanes = margining->lanes, in margining_run_write()
1096 .time = margining->time, in margining_run_write()
1097 .right_high = margining->right_high, in margining_run_write()
1098 .optional_voltage_offset_range = margining->optional_voltage_offset_range, in margining_run_write()
1102 "running hardware %s lane margining for %s lanes %u\n", in margining_run_write()
1103 margining->time ? "time" : "voltage", dev_name(dev), in margining_run_write()
1104 margining->lanes); in margining_run_write()
1106 ret = usb4_port_hw_margin(port, margining->target, margining->index, ¶ms, in margining_run_write()
1107 margining->results); in margining_run_write()
1113 mutex_unlock(&tb->lock); in margining_run_write()
1125 size_t count, loff_t *ppos) in margining_results_write() argument
1127 struct seq_file *s = file->private_data; in margining_results_write()
1128 struct tb_margining *margining = s->private; in margining_results_write()
1129 struct tb *tb = margining->port->sw->tb; in margining_results_write()
1131 if (mutex_lock_interruptible(&tb->lock)) in margining_results_write()
1132 return -ERESTARTSYS; in margining_results_write()
1135 margining->results[0] = 0; in margining_results_write()
1136 margining->results[1] = 0; in margining_results_write()
1138 if (margining->software) { in margining_results_write()
1145 mutex_unlock(&tb->lock); in margining_results_write()
1146 return count; in margining_results_write()
1155 voltage = tmp * margining->max_voltage_offset / margining->voltage_steps; in voltage_margin_show()
1160 if (margining->optional_voltage_offset_range) in voltage_margin_show()
1170 interval = tmp * margining->max_time_offset / margining->time_steps; in time_margin_show()
1179 struct tb_margining *margining = s->private; in margining_results_show()
1180 struct tb *tb = margining->port->sw->tb; in margining_results_show()
1182 if (mutex_lock_interruptible(&tb->lock)) in margining_results_show()
1183 return -ERESTARTSYS; in margining_results_show()
1186 seq_printf(s, "0x%08x\n", margining->results[0]); in margining_results_show()
1188 if (!margining->software) { in margining_results_show()
1191 seq_printf(s, "0x%08x\n", margining->results[1]); in margining_results_show()
1193 if (margining->time) { in margining_results_show()
1194 if (!margining->lanes || margining->lanes == 7) { in margining_results_show()
1195 val = margining->results[1]; in margining_results_show()
1196 seq_puts(s, "# lane 0 right time margin: "); in margining_results_show()
1198 val = margining->results[1] >> in margining_results_show()
1200 seq_puts(s, "# lane 0 left time margin: "); in margining_results_show()
1203 if (margining->lanes == 1 || margining->lanes == 7) { in margining_results_show()
1204 val = margining->results[1] >> in margining_results_show()
1206 seq_puts(s, "# lane 1 right time margin: "); in margining_results_show()
1208 val = margining->results[1] >> in margining_results_show()
1210 seq_puts(s, "# lane 1 left time margin: "); in margining_results_show()
1214 if (!margining->lanes || margining->lanes == 7) { in margining_results_show()
1215 val = margining->results[1]; in margining_results_show()
1216 seq_puts(s, "# lane 0 high voltage margin: "); in margining_results_show()
1218 val = margining->results[1] >> in margining_results_show()
1220 seq_puts(s, "# lane 0 low voltage margin: "); in margining_results_show()
1223 if (margining->lanes == 1 || margining->lanes == 7) { in margining_results_show()
1224 val = margining->results[1] >> in margining_results_show()
1226 seq_puts(s, "# lane 1 high voltage margin: "); in margining_results_show()
1228 val = margining->results[1] >> in margining_results_show()
1230 seq_puts(s, "# lane 1 low voltage margin: "); in margining_results_show()
1237 seq_printf(s, "0x%08x\n", margining->results[1]); in margining_results_show()
1238 result = FIELD_GET(USB4_MARGIN_SW_LANES_MASK, margining->results[0]); in margining_results_show()
1243 margining->results[1]); in margining_results_show()
1244 seq_printf(s, "# lane 0 errors: %u\n", lane_errors); in margining_results_show()
1249 margining->results[1]); in margining_results_show()
1250 seq_printf(s, "# lane 1 errors: %u\n", lane_errors); in margining_results_show()
1254 mutex_unlock(&tb->lock); in margining_results_show()
1261 size_t count, loff_t *ppos) in margining_test_write() argument
1263 struct seq_file *s = file->private_data; in margining_test_write()
1264 struct tb_margining *margining = s->private; in margining_test_write()
1265 struct tb *tb = margining->port->sw->tb; in margining_test_write()
1269 buf = validate_and_copy_from_user(user_buf, &count); in margining_test_write()
1273 buf[count - 1] = '\0'; in margining_test_write()
1275 if (mutex_lock_interruptible(&tb->lock)) { in margining_test_write()
1276 ret = -ERESTARTSYS; in margining_test_write()
1281 margining->time = true; in margining_test_write()
1283 margining->time = false; in margining_test_write()
1285 ret = -EINVAL; in margining_test_write()
1287 mutex_unlock(&tb->lock); in margining_test_write()
1291 return ret ? ret : count; in margining_test_write()
1296 struct tb_margining *margining = s->private; in margining_test_show()
1297 struct tb *tb = margining->port->sw->tb; in margining_test_show()
1299 if (mutex_lock_interruptible(&tb->lock)) in margining_test_show()
1300 return -ERESTARTSYS; in margining_test_show()
1303 if (margining->time) in margining_test_show()
1311 mutex_unlock(&tb->lock); in margining_test_show()
1318 size_t count, loff_t *ppos) in margining_margin_write() argument
1320 struct seq_file *s = file->private_data; in margining_margin_write()
1321 struct tb_margining *margining = s->private; in margining_margin_write()
1322 struct tb *tb = margining->port->sw->tb; in margining_margin_write()
1326 buf = validate_and_copy_from_user(user_buf, &count); in margining_margin_write()
1330 buf[count - 1] = '\0'; in margining_margin_write()
1332 if (mutex_lock_interruptible(&tb->lock)) { in margining_margin_write()
1333 ret = -ERESTARTSYS; in margining_margin_write()
1337 if (margining->time) { in margining_margin_write()
1339 margining->right_high = false; in margining_margin_write()
1341 margining->right_high = true; in margining_margin_write()
1343 ret = -EINVAL; in margining_margin_write()
1346 margining->right_high = false; in margining_margin_write()
1348 margining->right_high = true; in margining_margin_write()
1350 ret = -EINVAL; in margining_margin_write()
1353 mutex_unlock(&tb->lock); in margining_margin_write()
1357 return ret ? ret : count; in margining_margin_write()
1362 struct tb_margining *margining = s->private; in margining_margin_show()
1363 struct tb *tb = margining->port->sw->tb; in margining_margin_show()
1365 if (mutex_lock_interruptible(&tb->lock)) in margining_margin_show()
1366 return -ERESTARTSYS; in margining_margin_show()
1368 if (margining->time) { in margining_margin_show()
1369 if (margining->right_high) in margining_margin_show()
1374 if (margining->right_high) in margining_margin_show()
1380 mutex_unlock(&tb->lock); in margining_margin_show()
1399 margining->port = port; in margining_alloc()
1400 margining->target = target; in margining_alloc()
1401 margining->index = index; in margining_alloc()
1402 margining->dev = dev; in margining_alloc()
1404 ret = usb4_port_margining_caps(port, target, index, margining->caps); in margining_alloc()
1412 margining->software = true; in margining_alloc()
1414 val = FIELD_GET(USB4_MARGIN_CAP_0_VOLTAGE_STEPS_MASK, margining->caps[0]); in margining_alloc()
1415 margining->voltage_steps = val; in margining_alloc()
1416 val = FIELD_GET(USB4_MARGIN_CAP_0_MAX_VOLTAGE_OFFSET_MASK, margining->caps[0]); in margining_alloc()
1417 margining->max_voltage_offset = 74 + val * 2; in margining_alloc()
1421 margining->caps[0]); in margining_alloc()
1422 margining->voltage_steps_optional_range = val; in margining_alloc()
1424 margining->caps[1]); in margining_alloc()
1425 margining->max_voltage_offset_optional_range = 74 + val * 2; in margining_alloc()
1429 val = FIELD_GET(USB4_MARGIN_CAP_1_TIME_STEPS_MASK, margining->caps[1]); in margining_alloc()
1430 margining->time_steps = val; in margining_alloc()
1431 val = FIELD_GET(USB4_MARGIN_CAP_1_TIME_OFFSET_MASK, margining->caps[1]); in margining_alloc()
1436 margining->max_time_offset = 200 + 10 * val; in margining_alloc()
1441 val = FIELD_GET(USB4_MARGIN_CAP_1_MIN_BER_MASK, margining->caps[1]); in margining_alloc()
1442 margining->min_ber_level = val; in margining_alloc()
1443 val = FIELD_GET(USB4_MARGIN_CAP_1_MAX_BER_MASK, margining->caps[1]); in margining_alloc()
1444 margining->max_ber_level = val; in margining_alloc()
1447 margining->ber_level = margining->min_ber_level; in margining_alloc()
1465 margining->error_counter = USB4_MARGIN_SW_ERROR_COUNTER_CLEAR; in margining_alloc()
1466 margining->dwell_time = MIN_DWELL_TIME; in margining_alloc()
1488 if (!port->usb4) in margining_port_init()
1491 snprintf(dir_name, sizeof(dir_name), "port%d", port->port); in margining_port_init()
1492 parent = debugfs_lookup(dir_name, port->sw->debugfs_dir); in margining_port_init()
1493 port->usb4->margining = margining_alloc(port, &port->usb4->dev, in margining_port_init()
1503 if (!port->usb4) in margining_port_remove()
1506 snprintf(dir_name, sizeof(dir_name), "port%d", port->port); in margining_port_remove()
1507 parent = debugfs_lookup(dir_name, port->sw->debugfs_dir); in margining_port_remove()
1511 kfree(port->usb4->margining); in margining_port_remove()
1512 port->usb4->margining = NULL; in margining_port_remove()
1555 downstream = tb_port_at(xd->route, parent_sw); in margining_xdomain_init()
1566 downstream = tb_port_at(xd->route, parent_sw); in margining_xdomain_remove()
1572 rt->margining = margining_alloc(rt->port, &rt->dev, in margining_retimer_init()
1573 USB4_SB_TARGET_RETIMER, rt->index, in margining_retimer_init()
1579 kfree(rt->margining); in margining_retimer_remove()
1580 rt->margining = NULL; in margining_retimer_remove()
1597 buf = kcalloc(COUNTER_SET_LEN * port->config.max_counters, sizeof(u32), in port_clear_all_counters()
1600 return -ENOMEM; in port_clear_all_counters()
1603 COUNTER_SET_LEN * port->config.max_counters); in port_clear_all_counters()
1610 size_t count, loff_t *ppos) in counters_write()
1612 struct seq_file *s = file->private_data; in counters_write()
1613 struct tb_port *port = s->private; in counters_write()
1614 struct tb_switch *sw = port->sw; in counters_write()
1615 struct tb *tb = port->sw->tb; in counters_write()
1619 buf = validate_and_copy_from_user(user_buf, &count); in counters_write()
1623 pm_runtime_get_sync(&sw->dev); in counters_write()
1625 if (mutex_lock_interruptible(&tb->lock)) { in counters_write()
1626 ret = -ERESTARTSYS; in counters_write()
1637 ret = -EINVAL; in counters_write()
1646 mutex_unlock(&tb->lock); in counters_write()
1649 pm_runtime_mark_last_busy(&sw->dev); in counters_write()
1650 pm_runtime_put_autosuspend(&sw->dev); in counters_write()
1653 return ret < 0 ? ret : count; in counters_write()
1705 length -= dwords; in cap_show()
1730 if (usb4_switch_version(port->sw) < 2) in port_cap_show()
1742 if (usb4_switch_version(port->sw) < 2) in port_cap_show()
1747 if (usb4_switch_version(port->sw) < 2) in port_cap_show()
1821 struct tb_port *port = s->private; in port_regs_show()
1822 struct tb_switch *sw = port->sw; in port_regs_show()
1823 struct tb *tb = sw->tb; in port_regs_show()
1826 pm_runtime_get_sync(&sw->dev); in port_regs_show()
1828 if (mutex_lock_interruptible(&tb->lock)) { in port_regs_show()
1829 ret = -ERESTARTSYS; in port_regs_show()
1842 mutex_unlock(&tb->lock); in port_regs_show()
1844 pm_runtime_mark_last_busy(&sw->dev); in port_regs_show()
1845 pm_runtime_put_autosuspend(&sw->dev); in port_regs_show()
1926 struct tb_switch *sw = s->private; in switch_regs_show()
1927 struct tb *tb = sw->tb; in switch_regs_show()
1930 pm_runtime_get_sync(&sw->dev); in switch_regs_show()
1932 if (mutex_lock_interruptible(&tb->lock)) { in switch_regs_show()
1933 ret = -ERESTARTSYS; in switch_regs_show()
1946 mutex_unlock(&tb->lock); in switch_regs_show()
1948 pm_runtime_mark_last_busy(&sw->dev); in switch_regs_show()
1949 pm_runtime_put_autosuspend(&sw->dev); in switch_regs_show()
1977 struct tb_port *port = s->private; in path_show()
1978 struct tb_switch *sw = port->sw; in path_show()
1979 struct tb *tb = sw->tb; in path_show()
1982 pm_runtime_get_sync(&sw->dev); in path_show()
1984 if (mutex_lock_interruptible(&tb->lock)) { in path_show()
1985 ret = -ERESTARTSYS; in path_show()
1991 /* NHI and lane adapters have entry for path 0 */ in path_show()
2000 for (i = start; i <= port->config.max_in_hop_id; i++) { in path_show()
2007 mutex_unlock(&tb->lock); in path_show()
2009 pm_runtime_mark_last_busy(&sw->dev); in path_show()
2010 pm_runtime_put_autosuspend(&sw->dev); in path_show()
2040 struct tb_port *port = s->private; in counters_show()
2041 struct tb_switch *sw = port->sw; in counters_show()
2042 struct tb *tb = sw->tb; in counters_show()
2045 pm_runtime_get_sync(&sw->dev); in counters_show()
2047 if (mutex_lock_interruptible(&tb->lock)) { in counters_show()
2048 ret = -ERESTARTSYS; in counters_show()
2054 for (i = 0; i < port->config.max_counters; i++) { in counters_show()
2060 mutex_unlock(&tb->lock); in counters_show()
2063 pm_runtime_mark_last_busy(&sw->dev); in counters_show()
2064 pm_runtime_put_autosuspend(&sw->dev); in counters_show()
2084 ret = usb4_port_sb_read(port, target, index, regs->reg, data, in sb_regs_show()
2085 regs->size); in sb_regs_show()
2089 seq_printf(s, "0x%02x", regs->reg); in sb_regs_show()
2090 for (j = 0; j < regs->size; j++) in sb_regs_show()
2100 struct tb_port *port = s->private; in port_sb_regs_show()
2101 struct tb_switch *sw = port->sw; in port_sb_regs_show()
2102 struct tb *tb = sw->tb; in port_sb_regs_show()
2105 pm_runtime_get_sync(&sw->dev); in port_sb_regs_show()
2107 if (mutex_lock_interruptible(&tb->lock)) { in port_sb_regs_show()
2108 ret = -ERESTARTSYS; in port_sb_regs_show()
2115 mutex_unlock(&tb->lock); in port_sb_regs_show()
2117 pm_runtime_mark_last_busy(&sw->dev); in port_sb_regs_show()
2118 pm_runtime_put_autosuspend(&sw->dev); in port_sb_regs_show()
2125 * tb_switch_debugfs_init() - Add debugfs entries for router
2135 debugfs_dir = debugfs_create_dir(dev_name(&sw->dev), tb_debugfs_root); in tb_switch_debugfs_init()
2136 sw->debugfs_dir = debugfs_dir; in tb_switch_debugfs_init()
2144 if (port->disabled) in tb_switch_debugfs_init()
2146 if (port->config.type == TB_TYPE_INACTIVE) in tb_switch_debugfs_init()
2149 snprintf(dir_name, sizeof(dir_name), "port%d", port->port); in tb_switch_debugfs_init()
2150 debugfs_dir = debugfs_create_dir(dir_name, sw->debugfs_dir); in tb_switch_debugfs_init()
2155 if (port->config.counters_support) in tb_switch_debugfs_init()
2158 if (port->usb4) in tb_switch_debugfs_init()
2167 * tb_switch_debugfs_remove() - Remove all router debugfs entries
2175 debugfs_remove_recursive(sw->debugfs_dir); in tb_switch_debugfs_remove()
2189 * tb_service_debugfs_init() - Add debugfs directory for service
2196 svc->debugfs_dir = debugfs_create_dir(dev_name(&svc->dev), in tb_service_debugfs_init()
2201 * tb_service_debugfs_remove() - Remove service debugfs directory
2208 debugfs_remove_recursive(svc->debugfs_dir); in tb_service_debugfs_remove()
2209 svc->debugfs_dir = NULL; in tb_service_debugfs_remove()
2214 struct tb_retimer *rt = s->private; in retimer_sb_regs_show()
2215 struct tb *tb = rt->tb; in retimer_sb_regs_show()
2218 pm_runtime_get_sync(&rt->dev); in retimer_sb_regs_show()
2220 if (mutex_lock_interruptible(&tb->lock)) { in retimer_sb_regs_show()
2221 ret = -ERESTARTSYS; in retimer_sb_regs_show()
2225 ret = sb_regs_show(rt->port, retimer_sb_regs, ARRAY_SIZE(retimer_sb_regs), in retimer_sb_regs_show()
2226 USB4_SB_TARGET_RETIMER, rt->index, s); in retimer_sb_regs_show()
2228 mutex_unlock(&tb->lock); in retimer_sb_regs_show()
2230 pm_runtime_mark_last_busy(&rt->dev); in retimer_sb_regs_show()
2231 pm_runtime_put_autosuspend(&rt->dev); in retimer_sb_regs_show()
2238 * tb_retimer_debugfs_init() - Add debugfs directory for retimer
2247 debugfs_dir = debugfs_create_dir(dev_name(&rt->dev), tb_debugfs_root); in tb_retimer_debugfs_init()
2254 * tb_retimer_debugfs_remove() - Remove retimer debugfs directory
2261 debugfs_lookup_and_remove(dev_name(&rt->dev), tb_debugfs_root); in tb_retimer_debugfs_remove()