Lines Matching +full:port +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0
64 ret = tb_sw_write(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1); in usb4_native_switch_op()
76 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_native_switch_op()
84 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_native_switch_op()
89 return -EOPNOTSUPP; in usb4_native_switch_op()
96 ret = tb_sw_read(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1); in usb4_native_switch_op()
114 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in __usb4_switch_op()
117 return -EINVAL; in __usb4_switch_op()
124 if (cm_ops->usb4_switch_op) { in __usb4_switch_op()
127 ret = cm_ops->usb4_switch_op(sw, opcode, metadata, status, in __usb4_switch_op()
130 if (ret != -EOPNOTSUPP) in __usb4_switch_op()
159 * usb4_switch_check_wakes() - Check for wakes and notify PM core about them
168 struct tb_port *port; in usb4_switch_check_wakes() local
173 if (tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1)) in usb4_switch_check_wakes()
187 tb_switch_for_each_port(sw, port) { in usb4_switch_check_wakes()
188 if (!port->cap_usb4) in usb4_switch_check_wakes()
191 if (tb_port_read(port, &val, TB_CFG_PORT, in usb4_switch_check_wakes()
192 port->cap_usb4 + PORT_CS_18, 1)) in usb4_switch_check_wakes()
195 tb_port_dbg(port, "USB4 wake: %s, connection wake: %s, disconnection wake: %s\n", in usb4_switch_check_wakes()
203 usb4 = port->usb4; in usb4_switch_check_wakes()
204 if (device_may_wakeup(&usb4->dev) && wakeup_usb4) in usb4_switch_check_wakes()
205 pm_wakeup_event(&usb4->dev, 0); in usb4_switch_check_wakes()
211 pm_wakeup_event(&sw->dev, 0); in usb4_switch_check_wakes()
214 static bool link_is_usb4(struct tb_port *port) in link_is_usb4() argument
218 if (!port->cap_usb4) in link_is_usb4()
221 if (tb_port_read(port, &val, TB_CFG_PORT, in link_is_usb4()
222 port->cap_usb4 + PORT_CS_18, 1)) in link_is_usb4()
229 * usb4_switch_setup() - Additional setup for USB4 device
253 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1); in usb4_switch_setup()
258 sw->link_usb4 = link_is_usb4(down); in usb4_switch_setup()
259 tb_sw_dbg(sw, "link: %s\n", sw->link_usb4 ? "USB4" : "TBT"); in usb4_switch_setup()
267 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_setup()
271 if (tb_acpi_may_tunnel_usb3() && sw->link_usb4 && in usb4_switch_setup()
296 return tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_setup()
300 * usb4_switch_configuration_valid() - Set tunneling configuration to be valid
318 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_configuration_valid()
324 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_configuration_valid()
333 * usb4_switch_read_uid() - Read UID from USB4 router
337 * Reads 64-bit UID from USB4 router config space.
362 return status ? -EIO : 0; in usb4_switch_drom_read_block()
366 * usb4_switch_drom_read() - Read arbitrary bytes from USB4 router DROM
373 * should always work but for hosts it may return %-EOPNOTSUPP in which
384 * usb4_switch_lane_bonding_possible() - Are conditions met for lane bonding
397 ret = tb_port_read(up, &val, TB_CFG_PORT, up->cap_usb4 + PORT_CS_18, 1); in usb4_switch_lane_bonding_possible()
405 * usb4_switch_set_wake() - Enabled/disable wake
414 struct tb_port *port; in usb4_switch_set_wake() local
422 * upstream USB4 port. in usb4_switch_set_wake()
424 tb_switch_for_each_port(sw, port) { in usb4_switch_set_wake()
425 if (!tb_port_is_null(port)) in usb4_switch_set_wake()
427 if (!route && tb_is_upstream_port(port)) in usb4_switch_set_wake()
429 if (!port->cap_usb4) in usb4_switch_set_wake()
432 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_switch_set_wake()
433 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
439 if (tb_is_upstream_port(port)) { in usb4_switch_set_wake()
443 usb4 = port->usb4; in usb4_switch_set_wake()
446 device_may_wakeup(&usb4->dev)) && !configured) in usb4_switch_set_wake()
449 device_may_wakeup(&usb4->dev)) && configured) in usb4_switch_set_wake()
455 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_switch_set_wake()
456 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
466 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_wake()
478 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_wake()
487 * usb4_switch_set_sleep() - Prepare the router to enter sleep
499 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_sleep()
505 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_sleep()
514 * usb4_switch_nvm_sector_size() - Return router NVM sector size
519 * %-EOPNOTSUPP.
533 return status == 0x2 ? -EOPNOTSUPP : -EIO; in usb4_switch_nvm_sector_size()
556 return status ? -EIO : 0; in usb4_switch_nvm_read_block()
560 * usb4_switch_nvm_read() - Read arbitrary bytes from router NVM
567 * %-EOPNOTSUPP.
577 * usb4_switch_nvm_set_offset() - Set NVM write offset
601 return status ? -EIO : 0; in usb4_switch_nvm_set_offset()
616 return status ? -EIO : 0; in usb4_switch_nvm_write_next_block()
620 * usb4_switch_nvm_write() - Write to the router NVM
627 * write is not supported returns %-EOPNOTSUPP.
643 * usb4_switch_nvm_authenticate() - Authenticate new NVM
665 case -EACCES: in usb4_switch_nvm_authenticate()
666 case -ENOTCONN: in usb4_switch_nvm_authenticate()
667 case -ETIMEDOUT: in usb4_switch_nvm_authenticate()
676 * usb4_switch_nvm_authenticate_status() - Read status of last NVM authenticate
689 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in usb4_switch_nvm_authenticate_status()
694 if (cm_ops->usb4_switch_nvm_authenticate_status) { in usb4_switch_nvm_authenticate_status()
695 ret = cm_ops->usb4_switch_nvm_authenticate_status(sw, status); in usb4_switch_nvm_authenticate_status()
696 if (ret != -EOPNOTSUPP) in usb4_switch_nvm_authenticate_status()
700 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_switch_nvm_authenticate_status()
708 return -EBUSY; in usb4_switch_nvm_authenticate_status()
710 return -EOPNOTSUPP; in usb4_switch_nvm_authenticate_status()
722 * usb4_switch_credits_init() - Read buffer allocation parameters
726 * allocation fields accordingly. Specifically @sw->credits_allocation
735 const struct tb_port *port; in usb4_switch_credits_init() local
746 return -EIO; in usb4_switch_credits_init()
750 return -EMSGSIZE; in usb4_switch_credits_init()
752 max_usb3 = -1; in usb4_switch_credits_init()
753 min_dp_aux = -1; in usb4_switch_credits_init()
754 min_dp_main = -1; in usb4_switch_credits_init()
755 max_pcie = -1; in usb4_switch_credits_init()
756 max_dma = -1; in usb4_switch_credits_init()
796 * issues, log a warning and fall back using the hard-coded in usb4_switch_credits_init()
807 tb_switch_for_each_port(sw, port) { in usb4_switch_credits_init()
808 if (tb_port_is_null(port)) in usb4_switch_credits_init()
818 tb_switch_for_each_port(sw, port) { in usb4_switch_credits_init()
819 if (tb_port_is_dpout(port) && min_dp_main < 0) { in usb4_switch_credits_init()
823 if ((tb_port_is_dpin(port) || tb_port_is_dpout(port)) && in usb4_switch_credits_init()
828 if ((tb_port_is_usb3_down(port) || tb_port_is_usb3_up(port)) && in usb4_switch_credits_init()
833 if ((tb_port_is_pcie_down(port) || tb_port_is_pcie_up(port)) && in usb4_switch_credits_init()
844 sw->credit_allocation = true; in usb4_switch_credits_init()
846 sw->max_usb3_credits = max_usb3; in usb4_switch_credits_init()
848 sw->min_dp_aux_credits = min_dp_aux; in usb4_switch_credits_init()
850 sw->min_dp_main_credits = min_dp_main; in usb4_switch_credits_init()
852 sw->max_pcie_credits = max_pcie; in usb4_switch_credits_init()
854 sw->max_dma_credits = max_dma; in usb4_switch_credits_init()
859 return -EINVAL; in usb4_switch_credits_init()
863 * usb4_switch_query_dp_resource() - Query availability of DP IN resource
873 u32 metadata = in->port; in usb4_switch_query_dp_resource()
883 if (ret == -EOPNOTSUPP) in usb4_switch_query_dp_resource()
892 * usb4_switch_alloc_dp_resource() - Allocate DP IN resource
898 * returns negative errno, in particular %-EBUSY if the resource is
903 u32 metadata = in->port; in usb4_switch_alloc_dp_resource()
909 if (ret == -EOPNOTSUPP) in usb4_switch_alloc_dp_resource()
914 return status ? -EBUSY : 0; in usb4_switch_alloc_dp_resource()
918 * usb4_switch_dealloc_dp_resource() - Releases allocated DP IN resource
926 u32 metadata = in->port; in usb4_switch_dealloc_dp_resource()
932 if (ret == -EOPNOTSUPP) in usb4_switch_dealloc_dp_resource()
937 return status ? -EIO : 0; in usb4_switch_dealloc_dp_resource()
940 static int usb4_port_idx(const struct tb_switch *sw, const struct tb_port *port) in usb4_port_idx() argument
945 /* Assume port is primary */ in usb4_port_idx()
951 if (!p->link_nr) { in usb4_port_idx()
952 if (p == port) in usb4_port_idx()
962 * usb4_switch_map_pcie_down() - Map USB4 port to a PCIe downstream adapter
964 * @port: USB4 port
972 const struct tb_port *port) in usb4_switch_map_pcie_down() argument
974 int usb4_idx = usb4_port_idx(sw, port); in usb4_switch_map_pcie_down()
978 /* Find PCIe down port matching usb4_port */ in usb4_switch_map_pcie_down()
993 * usb4_switch_map_usb3_down() - Map USB4 port to a USB3 downstream adapter
995 * @port: USB4 port
1003 const struct tb_port *port) in usb4_switch_map_usb3_down() argument
1005 int usb4_idx = usb4_port_idx(sw, port); in usb4_switch_map_usb3_down()
1009 /* Find USB3 down port matching usb4_port */ in usb4_switch_map_usb3_down()
1024 * usb4_switch_add_ports() - Add USB4 ports for this router
1034 struct tb_port *port; in usb4_switch_add_ports() local
1039 tb_switch_for_each_port(sw, port) { in usb4_switch_add_ports()
1042 if (!tb_port_is_null(port)) in usb4_switch_add_ports()
1044 if (!port->cap_usb4) in usb4_switch_add_ports()
1047 usb4 = usb4_port_device_add(port); in usb4_switch_add_ports()
1053 port->usb4 = usb4; in usb4_switch_add_ports()
1060 * usb4_switch_remove_ports() - Removes USB4 ports from this router
1067 struct tb_port *port; in usb4_switch_remove_ports() local
1069 tb_switch_for_each_port(sw, port) { in usb4_switch_remove_ports()
1070 if (port->usb4) { in usb4_switch_remove_ports()
1071 usb4_port_device_remove(port->usb4); in usb4_switch_remove_ports()
1072 port->usb4 = NULL; in usb4_switch_remove_ports()
1078 * usb4_port_unlock() - Unlock USB4 downstream port
1079 * @port: USB4 port to unlock
1081 * Unlocks USB4 downstream port so that the connection manager can
1082 * access the router below this port.
1084 int usb4_port_unlock(struct tb_port *port) in usb4_port_unlock() argument
1089 ret = tb_port_read(port, &val, TB_CFG_PORT, ADP_CS_4, 1); in usb4_port_unlock()
1094 return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_4, 1); in usb4_port_unlock()
1098 * usb4_port_hotplug_enable() - Enables hotplug for a port
1099 * @port: USB4 port to operate on
1101 * Enables hot plug events on a given port. This is only intended
1102 * to be used on lane, DP-IN, and DP-OUT adapters.
1104 int usb4_port_hotplug_enable(struct tb_port *port) in usb4_port_hotplug_enable() argument
1109 ret = tb_port_read(port, &val, TB_CFG_PORT, ADP_CS_5, 1); in usb4_port_hotplug_enable()
1114 return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_5, 1); in usb4_port_hotplug_enable()
1118 * usb4_port_reset() - Issue downstream port reset
1119 * @port: USB4 port to reset
1121 * Issues downstream port reset to @port.
1123 int usb4_port_reset(struct tb_port *port) in usb4_port_reset() argument
1128 if (!port->cap_usb4) in usb4_port_reset()
1129 return -EINVAL; in usb4_port_reset()
1131 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_reset()
1132 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1138 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_reset()
1139 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1145 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_reset()
1146 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1152 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_reset()
1153 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1156 static int usb4_port_set_configured(struct tb_port *port, bool configured) in usb4_port_set_configured() argument
1161 if (!port->cap_usb4) in usb4_port_set_configured()
1162 return -EINVAL; in usb4_port_set_configured()
1164 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_set_configured()
1165 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_set_configured()
1174 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_set_configured()
1175 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_set_configured()
1179 * usb4_port_configure() - Set USB4 port configured
1180 * @port: USB4 router
1184 int usb4_port_configure(struct tb_port *port) in usb4_port_configure() argument
1186 return usb4_port_set_configured(port, true); in usb4_port_configure()
1190 * usb4_port_unconfigure() - Set USB4 port unconfigured
1191 * @port: USB4 router
1195 void usb4_port_unconfigure(struct tb_port *port) in usb4_port_unconfigure() argument
1197 usb4_port_set_configured(port, false); in usb4_port_unconfigure()
1200 static int usb4_set_xdomain_configured(struct tb_port *port, bool configured) in usb4_set_xdomain_configured() argument
1205 if (!port->cap_usb4) in usb4_set_xdomain_configured()
1206 return -EINVAL; in usb4_set_xdomain_configured()
1208 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_set_xdomain_configured()
1209 port->cap_usb4 + PORT_CS_19, 1); in usb4_set_xdomain_configured()
1218 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_set_xdomain_configured()
1219 port->cap_usb4 + PORT_CS_19, 1); in usb4_set_xdomain_configured()
1223 * usb4_port_configure_xdomain() - Configure port for XDomain
1224 * @port: USB4 port connected to another host
1225 * @xd: XDomain that is connected to the port
1227 * Marks the USB4 port as being connected to another host and updates
1230 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd) in usb4_port_configure_xdomain() argument
1232 xd->link_usb4 = link_is_usb4(port); in usb4_port_configure_xdomain()
1233 return usb4_set_xdomain_configured(port, true); in usb4_port_configure_xdomain()
1237 * usb4_port_unconfigure_xdomain() - Unconfigure port for XDomain
1238 * @port: USB4 port that was connected to another host
1240 * Clears USB4 port from being marked as XDomain.
1242 void usb4_port_unconfigure_xdomain(struct tb_port *port) in usb4_port_unconfigure_xdomain() argument
1244 usb4_set_xdomain_configured(port, false); in usb4_port_unconfigure_xdomain()
1247 static int usb4_port_wait_for_bit(struct tb_port *port, u32 offset, u32 bit, in usb4_port_wait_for_bit() argument
1256 ret = tb_port_read(port, &val, TB_CFG_PORT, offset, 1); in usb4_port_wait_for_bit()
1266 return -ETIMEDOUT; in usb4_port_wait_for_bit()
1269 static int usb4_port_read_data(struct tb_port *port, void *data, size_t dwords) in usb4_port_read_data() argument
1272 return -EINVAL; in usb4_port_read_data()
1274 return tb_port_read(port, data, TB_CFG_PORT, port->cap_usb4 + PORT_CS_2, in usb4_port_read_data()
1278 static int usb4_port_write_data(struct tb_port *port, const void *data, in usb4_port_write_data() argument
1282 return -EINVAL; in usb4_port_write_data()
1284 return tb_port_write(port, data, TB_CFG_PORT, port->cap_usb4 + PORT_CS_2, in usb4_port_write_data()
1288 static int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_read() argument
1295 if (!port->cap_usb4) in usb4_port_sb_read()
1296 return -EINVAL; in usb4_port_sb_read()
1305 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_sb_read()
1306 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1310 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_read()
1315 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_sb_read()
1316 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1321 return -ENODEV; in usb4_port_sb_read()
1323 return -EIO; in usb4_port_sb_read()
1325 return buf ? usb4_port_read_data(port, buf, dwords) : 0; in usb4_port_sb_read()
1328 static int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_write() argument
1335 if (!port->cap_usb4) in usb4_port_sb_write()
1336 return -EINVAL; in usb4_port_sb_write()
1339 ret = usb4_port_write_data(port, buf, dwords); in usb4_port_sb_write()
1352 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_sb_write()
1353 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1357 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_write()
1362 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_sb_write()
1363 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1368 return -ENODEV; in usb4_port_sb_write()
1370 return -EIO; in usb4_port_sb_write()
1381 return -EAGAIN; in usb4_port_sb_opcode_err_to_errno()
1383 return -EOPNOTSUPP; in usb4_port_sb_opcode_err_to_errno()
1385 return -EIO; in usb4_port_sb_opcode_err_to_errno()
1389 static int usb4_port_sb_op(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_op() argument
1397 ret = usb4_port_sb_write(port, target, index, USB4_SB_OPCODE, &val, in usb4_port_sb_op()
1406 ret = usb4_port_sb_read(port, target, index, USB4_SB_OPCODE, in usb4_port_sb_op()
1415 return -ETIMEDOUT; in usb4_port_sb_op()
1418 static int usb4_port_set_router_offline(struct tb_port *port, bool offline) in usb4_port_set_router_offline() argument
1423 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_set_router_offline()
1429 return usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_set_router_offline()
1434 * usb4_port_router_offline() - Put the USB4 port to offline mode
1435 * @port: USB4 port
1437 * This function puts the USB4 port into offline mode. In this mode the
1438 * port does not react on hotplug events anymore. This needs to be
1444 int usb4_port_router_offline(struct tb_port *port) in usb4_port_router_offline() argument
1446 return usb4_port_set_router_offline(port, true); in usb4_port_router_offline()
1450 * usb4_port_router_online() - Put the USB4 port back to online
1451 * @port: USB4 port
1453 * Makes the USB4 port functional again.
1455 int usb4_port_router_online(struct tb_port *port) in usb4_port_router_online() argument
1457 return usb4_port_set_router_offline(port, false); in usb4_port_router_online()
1461 * usb4_port_enumerate_retimers() - Send RT broadcast transaction
1462 * @port: USB4 port
1464 * This forces the USB4 port to send broadcast RT transaction which
1468 int usb4_port_enumerate_retimers(struct tb_port *port) in usb4_port_enumerate_retimers() argument
1473 return usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_enumerate_retimers()
1478 * usb4_port_clx_supported() - Check if CLx is supported by the link
1479 * @port: Port to check for CLx support for
1484 bool usb4_port_clx_supported(struct tb_port *port) in usb4_port_clx_supported() argument
1489 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_clx_supported()
1490 port->cap_usb4 + PORT_CS_18, 1); in usb4_port_clx_supported()
1498 * usb4_port_asym_supported() - If the port supports asymmetric link
1499 * @port: USB4 port
1501 * Checks if the port and the cable supports asymmetric link and returns
1504 bool usb4_port_asym_supported(struct tb_port *port) in usb4_port_asym_supported() argument
1508 if (!port->cap_usb4) in usb4_port_asym_supported()
1511 if (tb_port_read(port, &val, TB_CFG_PORT, port->cap_usb4 + PORT_CS_18, 1)) in usb4_port_asym_supported()
1518 * usb4_port_asym_set_link_width() - Set link width to asymmetric or symmetric
1519 * @port: USB4 port
1522 * Sets USB4 port link width to @width. Can be called for widths where
1525 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width) in usb4_port_asym_set_link_width() argument
1530 if (!port->cap_phy) in usb4_port_asym_set_link_width()
1531 return -EINVAL; in usb4_port_asym_set_link_width()
1533 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_asym_set_link_width()
1534 port->cap_phy + LANE_ADP_CS_1, 1); in usb4_port_asym_set_link_width()
1553 return -EINVAL; in usb4_port_asym_set_link_width()
1556 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_asym_set_link_width()
1557 port->cap_phy + LANE_ADP_CS_1, 1); in usb4_port_asym_set_link_width()
1561 * usb4_port_asym_start() - Start symmetry change and wait for completion
1562 * @port: USB4 port
1568 * Returns %0 in case of success, %-ETIMEDOUT if case of timeout or
1571 int usb4_port_asym_start(struct tb_port *port) in usb4_port_asym_start() argument
1576 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_asym_start()
1577 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_asym_start()
1582 val |= FIELD_PREP(PORT_CS_19_START_ASYM, 1); in usb4_port_asym_start()
1584 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_asym_start()
1585 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_asym_start()
1591 * port started the symmetry transition. in usb4_port_asym_start()
1593 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_19, in usb4_port_asym_start()
1599 return usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_18, in usb4_port_asym_start()
1604 * usb4_port_margining_caps() - Read USB4 port marginig capabilities
1605 * @port: USB4 port
1608 * Reads the USB4 port lane margining capabilities into @caps.
1610 int usb4_port_margining_caps(struct tb_port *port, u32 *caps) in usb4_port_margining_caps() argument
1614 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_margining_caps()
1619 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_margining_caps()
1624 * usb4_port_hw_margin() - Run hardware lane margining on port
1625 * @port: USB4 port
1626 * @lanes: Which lanes to run (must match the port capabilities). Can be
1627 * %0, %1 or %7.
1633 * Runs hardware lane margining on USB4 port and returns the result in
1636 int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes, in usb4_port_hw_margin() argument
1652 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1657 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1662 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1667 * usb4_port_sw_margin() - Run software lane margining on port
1668 * @port: USB4 port
1669 * @lanes: Which lanes to run (must match the port capabilities). Can be
1670 * %0, %1 or %7.
1675 * Runs software lane margining on USB4 port. Read back the error
1679 int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing, in usb4_port_sw_margin() argument
1693 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin()
1698 return usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin()
1703 * usb4_port_sw_margin_errors() - Read the software margining error counters
1704 * @port: USB4 port
1707 * This reads back the software margining error counters from the port.
1710 int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors) in usb4_port_sw_margin_errors() argument
1714 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin_errors()
1719 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin_errors()
1723 static inline int usb4_port_retimer_op(struct tb_port *port, u8 index, in usb4_port_retimer_op() argument
1727 return usb4_port_sb_op(port, USB4_SB_TARGET_RETIMER, index, opcode, in usb4_port_retimer_op()
1732 * usb4_port_retimer_set_inbound_sbtx() - Enable sideband channel transactions
1733 * @port: USB4 port
1739 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_set_inbound_sbtx() argument
1743 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1746 if (ret != -ENODEV) in usb4_port_retimer_set_inbound_sbtx()
1754 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1759 * usb4_port_retimer_unset_inbound_sbtx() - Disable sideband channel transactions
1760 * @port: USB4 port
1766 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_unset_inbound_sbtx() argument
1768 return usb4_port_retimer_op(port, index, in usb4_port_retimer_unset_inbound_sbtx()
1773 * usb4_port_retimer_read() - Read from retimer sideband registers
1774 * @port: USB4 port
1781 * retimer is connected to @port at @index. Returns %0 in case of
1783 * present at given @index returns %-ENODEV. In any other failure
1786 int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf, in usb4_port_retimer_read() argument
1789 return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, reg, buf, in usb4_port_retimer_read()
1794 * usb4_port_retimer_write() - Write to retimer sideband registers
1795 * @port: USB4 port
1802 * connected to @port at @index. Returns %0 in case of success. If there
1803 * is no retimer present at given @index returns %-ENODEV. In any other
1806 int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg, in usb4_port_retimer_write() argument
1809 return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, reg, buf, in usb4_port_retimer_write()
1814 * usb4_port_retimer_is_last() - Is the retimer last on-board retimer
1815 * @port: USB4 port
1819 * Type-C port) this function returns %1. If it is not returns %0. If
1820 * the retimer is not present returns %-ENODEV. Otherwise returns
1823 int usb4_port_retimer_is_last(struct tb_port *port, u8 index) in usb4_port_retimer_is_last() argument
1828 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_QUERY_LAST_RETIMER, in usb4_port_retimer_is_last()
1833 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_is_last()
1835 return ret ? ret : metadata & 1; in usb4_port_retimer_is_last()
1839 * usb4_port_retimer_nvm_sector_size() - Read retimer NVM sector size
1840 * @port: USB4 port
1846 * in case of error. Specifically returns %-ENODEV if there is no
1849 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_sector_size() argument
1854 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_GET_NVM_SECTOR_SIZE, in usb4_port_retimer_nvm_sector_size()
1859 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_sector_size()
1865 * usb4_port_retimer_nvm_set_offset() - Set NVM write offset
1866 * @port: USB4 port
1875 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_set_offset() argument
1885 ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_set_offset()
1890 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_SET_OFFSET, in usb4_port_retimer_nvm_set_offset()
1895 struct tb_port *port; member
1904 struct tb_port *port = info->port; in usb4_port_retimer_nvm_write_next_block() local
1905 u8 index = info->index; in usb4_port_retimer_nvm_write_next_block()
1908 ret = usb4_port_retimer_write(port, index, USB4_SB_DATA, in usb4_port_retimer_nvm_write_next_block()
1913 return usb4_port_retimer_op(port, index, in usb4_port_retimer_nvm_write_next_block()
1918 * usb4_port_retimer_nvm_write() - Write to retimer NVM
1919 * @port: USB4 port
1927 * errno in case of failure. Specifically returns %-ENODEV if there is
1930 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index, unsigned int address, in usb4_port_retimer_nvm_write() argument
1933 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_write()
1936 ret = usb4_port_retimer_nvm_set_offset(port, index, address); in usb4_port_retimer_nvm_write()
1945 * usb4_port_retimer_nvm_authenticate() - Start retimer NVM upgrade
1946 * @port: USB4 port
1955 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_authenticate() argument
1965 return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate()
1970 * usb4_port_retimer_nvm_authenticate_status() - Read status of NVM upgrade
1971 * @port: USB4 port
1982 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_authenticate_status() argument
1988 ret = usb4_port_retimer_read(port, index, USB4_SB_OPCODE, &val, in usb4_port_retimer_nvm_authenticate_status()
1999 case -EAGAIN: in usb4_port_retimer_nvm_authenticate_status()
2000 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, in usb4_port_retimer_nvm_authenticate_status()
2017 struct tb_port *port = info->port; in usb4_port_retimer_nvm_read_block() local
2018 u8 index = info->index; in usb4_port_retimer_nvm_read_block()
2026 ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_read_block()
2031 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_READ, 500); in usb4_port_retimer_nvm_read_block()
2035 return usb4_port_retimer_read(port, index, USB4_SB_DATA, buf, in usb4_port_retimer_nvm_read_block()
2040 * usb4_port_retimer_nvm_read() - Read contents of retimer NVM
2041 * @port: USB4 port
2049 * Specifically returns %-ENODEV if there is no retimer at @index.
2051 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_read() argument
2054 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_read()
2061 usb4_usb3_port_max_bandwidth(const struct tb_port *port, unsigned int bw) in usb4_usb3_port_max_bandwidth() argument
2064 if (port->max_bw) in usb4_usb3_port_max_bandwidth()
2065 return min(bw, port->max_bw); in usb4_usb3_port_max_bandwidth()
2070 * usb4_usb3_port_max_link_rate() - Maximum support USB3 link rate
2071 * @port: USB3 adapter port
2076 int usb4_usb3_port_max_link_rate(struct tb_port *port) in usb4_usb3_port_max_link_rate() argument
2081 if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port)) in usb4_usb3_port_max_link_rate()
2082 return -EINVAL; in usb4_usb3_port_max_link_rate()
2084 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_max_link_rate()
2085 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_max_link_rate()
2092 return usb4_usb3_port_max_bandwidth(port, ret); in usb4_usb3_port_max_link_rate()
2096 * usb4_usb3_port_actual_link_rate() - Established USB3 link rate
2097 * @port: USB3 adapter port
2102 int usb4_usb3_port_actual_link_rate(struct tb_port *port) in usb4_usb3_port_actual_link_rate() argument
2107 if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port)) in usb4_usb3_port_actual_link_rate()
2108 return -EINVAL; in usb4_usb3_port_actual_link_rate()
2110 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_actual_link_rate()
2111 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_actual_link_rate()
2121 return usb4_usb3_port_max_bandwidth(port, ret); in usb4_usb3_port_actual_link_rate()
2124 static int usb4_usb3_port_cm_request(struct tb_port *port, bool request) in usb4_usb3_port_cm_request() argument
2129 if (!tb_port_is_usb3_down(port)) in usb4_usb3_port_cm_request()
2130 return -EINVAL; in usb4_usb3_port_cm_request()
2131 if (tb_route(port->sw)) in usb4_usb3_port_cm_request()
2132 return -EINVAL; in usb4_usb3_port_cm_request()
2134 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
2135 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2144 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
2145 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2154 return usb4_port_wait_for_bit(port, port->cap_adap + ADP_USB3_CS_1, in usb4_usb3_port_cm_request()
2158 static inline int usb4_usb3_port_set_cm_request(struct tb_port *port) in usb4_usb3_port_set_cm_request() argument
2160 return usb4_usb3_port_cm_request(port, true); in usb4_usb3_port_set_cm_request()
2163 static inline int usb4_usb3_port_clear_cm_request(struct tb_port *port) in usb4_usb3_port_clear_cm_request() argument
2165 return usb4_usb3_port_cm_request(port, false); in usb4_usb3_port_clear_cm_request()
2180 /* 1 uframe is 1/8 ms (125 us) -> 1 / 8000 s */ in mbps_to_usb3_bw()
2185 static int usb4_usb3_port_read_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_read_allocated_bandwidth() argument
2192 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2193 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_read_allocated_bandwidth()
2197 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2198 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_allocated_bandwidth()
2214 * usb4_usb3_port_allocated_bandwidth() - Bandwidth allocated for USB3
2215 * @port: USB3 adapter port
2223 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocated_bandwidth() argument
2228 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2232 ret = usb4_usb3_port_read_allocated_bandwidth(port, upstream_bw, in usb4_usb3_port_allocated_bandwidth()
2234 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2239 static int usb4_usb3_port_read_consumed_bandwidth(struct tb_port *port, in usb4_usb3_port_read_consumed_bandwidth() argument
2246 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2247 port->cap_adap + ADP_USB3_CS_1, 1); in usb4_usb3_port_read_consumed_bandwidth()
2251 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2252 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_consumed_bandwidth()
2267 static int usb4_usb3_port_write_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_write_allocated_bandwidth() argument
2284 return -EINVAL; in usb4_usb3_port_write_allocated_bandwidth()
2286 ret = tb_port_write(port, &scale, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2287 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_write_allocated_bandwidth()
2294 tb_port_dbg(port, "scaled bandwidth %u/%u, scale %u\n", ubw, dbw, scale); in usb4_usb3_port_write_allocated_bandwidth()
2296 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2297 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2305 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2306 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2310 * usb4_usb3_port_allocate_bandwidth() - Allocate bandwidth for USB3
2311 * @port: USB3 adapter port
2326 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocate_bandwidth() argument
2331 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2335 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_allocate_bandwidth()
2344 ret = usb4_usb3_port_write_allocated_bandwidth(port, allocate_up, in usb4_usb3_port_allocate_bandwidth()
2353 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2358 * usb4_usb3_port_release_bandwidth() - Release allocated USB3 bandwidth
2359 * @port: USB3 adapter port
2368 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_release_bandwidth() argument
2373 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_release_bandwidth()
2377 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_release_bandwidth()
2391 ret = usb4_usb3_port_write_allocated_bandwidth(port, consumed_up, in usb4_usb3_port_release_bandwidth()
2400 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_release_bandwidth()
2404 static bool is_usb4_dpin(const struct tb_port *port) in is_usb4_dpin() argument
2406 if (!tb_port_is_dpin(port)) in is_usb4_dpin()
2408 if (!tb_switch_is_usb4(port->sw)) in is_usb4_dpin()
2414 * usb4_dp_port_set_cm_id() - Assign CM ID to the DP IN adapter
2415 * @port: DP IN adapter
2418 * Sets CM ID for the @port. Returns %0 on success and negative errno
2419 * otherwise. Speficially returns %-EOPNOTSUPP if the @port does not
2422 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id) in usb4_dp_port_set_cm_id() argument
2427 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_id()
2428 return -EOPNOTSUPP; in usb4_dp_port_set_cm_id()
2430 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2431 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2438 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2439 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2443 * usb4_dp_port_bandwidth_mode_supported() - Is the bandwidth allocation mode
2445 * @port: DP IN adapter to check
2450 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port) in usb4_dp_port_bandwidth_mode_supported() argument
2455 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_supported()
2458 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_supported()
2459 port->cap_adap + DP_LOCAL_CAP, 1); in usb4_dp_port_bandwidth_mode_supported()
2467 * usb4_dp_port_bandwidth_mode_enabled() - Is the bandwidth allocation mode
2469 * @port: DP IN adapter to check
2474 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port) in usb4_dp_port_bandwidth_mode_enabled() argument
2479 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_enabled()
2482 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_enabled()
2483 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_bandwidth_mode_enabled()
2491 * usb4_dp_port_set_cm_bandwidth_mode_supported() - Set/clear CM support for
2493 * @port: DP IN adapter
2498 * otherwise. Specifically returns %-OPNOTSUPP if the passed in adapter
2501 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port, in usb4_dp_port_set_cm_bandwidth_mode_supported() argument
2507 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_bandwidth_mode_supported()
2508 return -EOPNOTSUPP; in usb4_dp_port_set_cm_bandwidth_mode_supported()
2510 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2511 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2520 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2521 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2525 * usb4_dp_port_group_id() - Return Group ID assigned for the adapter
2526 * @port: DP IN adapter
2530 * %-EOPNOTSUPP is returned.
2532 int usb4_dp_port_group_id(struct tb_port *port) in usb4_dp_port_group_id() argument
2537 if (!is_usb4_dpin(port)) in usb4_dp_port_group_id()
2538 return -EOPNOTSUPP; in usb4_dp_port_group_id()
2540 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_group_id()
2541 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_group_id()
2549 * usb4_dp_port_set_group_id() - Set adapter Group ID
2550 * @port: DP IN adapter
2555 * Specifically returns %-EOPNOTSUPP if the adapter does not support
2558 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id) in usb4_dp_port_set_group_id() argument
2563 if (!is_usb4_dpin(port)) in usb4_dp_port_set_group_id()
2564 return -EOPNOTSUPP; in usb4_dp_port_set_group_id()
2566 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2567 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2574 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2575 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2579 * usb4_dp_port_nrd() - Read non-reduced rate and lanes
2580 * @port: DP IN adapter
2581 * @rate: Non-reduced rate in Mb/s is placed here
2582 * @lanes: Non-reduced lanes are placed here
2584 * Reads the non-reduced rate and lanes from the DP IN adapter. Returns
2586 * %-EOPNOTSUPP if the adapter does not support this.
2588 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes) in usb4_dp_port_nrd() argument
2593 if (!is_usb4_dpin(port)) in usb4_dp_port_nrd()
2594 return -EOPNOTSUPP; in usb4_dp_port_nrd()
2596 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_nrd()
2597 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_nrd()
2620 *lanes = 1; in usb4_dp_port_nrd()
2634 * usb4_dp_port_set_nrd() - Set non-reduced rate and lanes
2635 * @port: DP IN adapter
2636 * @rate: Non-reduced rate in Mb/s
2637 * @lanes: Non-reduced lanes
2640 * the non-reduced values for the DP IN adapter. Returns %0 in success
2642 * %-EOPNOTSUPP is returned.
2644 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes) in usb4_dp_port_set_nrd() argument
2649 if (!is_usb4_dpin(port)) in usb4_dp_port_set_nrd()
2650 return -EOPNOTSUPP; in usb4_dp_port_set_nrd()
2652 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2653 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2675 return -EINVAL; in usb4_dp_port_set_nrd()
2681 case 1: in usb4_dp_port_set_nrd()
2690 return -EINVAL; in usb4_dp_port_set_nrd()
2693 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2694 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2698 * usb4_dp_port_granularity() - Return granularity for the bandwidth values
2699 * @port: DP IN adapter
2701 * Reads the programmed granularity from @port. If the DP IN adapter does
2702 * not support bandwidth allocation mode returns %-EOPNOTSUPP and negative
2705 int usb4_dp_port_granularity(struct tb_port *port) in usb4_dp_port_granularity() argument
2710 if (!is_usb4_dpin(port)) in usb4_dp_port_granularity()
2711 return -EOPNOTSUPP; in usb4_dp_port_granularity()
2713 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_granularity()
2714 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_granularity()
2730 return -EINVAL; in usb4_dp_port_granularity()
2734 * usb4_dp_port_set_granularity() - Set granularity for the bandwidth values
2735 * @port: DP IN adapter
2740 * adapter does not support this %-EOPNOTSUPP is returned.
2742 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity) in usb4_dp_port_set_granularity() argument
2747 if (!is_usb4_dpin(port)) in usb4_dp_port_set_granularity()
2748 return -EOPNOTSUPP; in usb4_dp_port_set_granularity()
2750 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2751 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2768 return -EINVAL; in usb4_dp_port_set_granularity()
2771 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2772 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2776 * usb4_dp_port_set_estimated_bandwidth() - Set estimated bandwidth
2777 * @port: DP IN adapter
2783 * and negative errno otherwise. Specifically returns %-EOPNOTSUPP if
2786 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_set_estimated_bandwidth() argument
2791 if (!is_usb4_dpin(port)) in usb4_dp_port_set_estimated_bandwidth()
2792 return -EOPNOTSUPP; in usb4_dp_port_set_estimated_bandwidth()
2794 ret = usb4_dp_port_granularity(port); in usb4_dp_port_set_estimated_bandwidth()
2799 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2800 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2807 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2808 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2812 * usb4_dp_port_allocated_bandwidth() - Return allocated bandwidth
2813 * @port: DP IN adapter
2815 * Reads and returns allocated bandwidth for @port in Mb/s (taking into
2819 int usb4_dp_port_allocated_bandwidth(struct tb_port *port) in usb4_dp_port_allocated_bandwidth() argument
2824 if (!is_usb4_dpin(port)) in usb4_dp_port_allocated_bandwidth()
2825 return -EOPNOTSUPP; in usb4_dp_port_allocated_bandwidth()
2827 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocated_bandwidth()
2832 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocated_bandwidth()
2833 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocated_bandwidth()
2843 static int __usb4_dp_port_set_cm_ack(struct tb_port *port, bool ack) in __usb4_dp_port_set_cm_ack() argument
2848 ret = tb_port_read(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2849 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2858 return tb_port_write(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2859 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2862 static inline int usb4_dp_port_set_cm_ack(struct tb_port *port) in usb4_dp_port_set_cm_ack() argument
2864 return __usb4_dp_port_set_cm_ack(port, true); in usb4_dp_port_set_cm_ack()
2867 static int usb4_dp_port_wait_and_clear_cm_ack(struct tb_port *port, in usb4_dp_port_wait_and_clear_cm_ack() argument
2874 ret = __usb4_dp_port_set_cm_ack(port, false); in usb4_dp_port_wait_and_clear_cm_ack()
2880 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2881 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2892 return -ETIMEDOUT; in usb4_dp_port_wait_and_clear_cm_ack()
2894 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2895 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2900 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2901 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2905 * usb4_dp_port_allocate_bandwidth() - Set allocated bandwidth
2906 * @port: DP IN adapter
2913 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_allocate_bandwidth() argument
2918 if (!is_usb4_dpin(port)) in usb4_dp_port_allocate_bandwidth()
2919 return -EOPNOTSUPP; in usb4_dp_port_allocate_bandwidth()
2921 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocate_bandwidth()
2926 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2927 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2934 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2935 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2939 ret = usb4_dp_port_set_cm_ack(port); in usb4_dp_port_allocate_bandwidth()
2943 return usb4_dp_port_wait_and_clear_cm_ack(port, 500); in usb4_dp_port_allocate_bandwidth()
2947 * usb4_dp_port_requested_bandwidth() - Read requested bandwidth
2948 * @port: DP IN adapter
2952 * error returns negative errno. Specifically returns %-EOPNOTSUPP if
2956 int usb4_dp_port_requested_bandwidth(struct tb_port *port) in usb4_dp_port_requested_bandwidth() argument
2961 if (!is_usb4_dpin(port)) in usb4_dp_port_requested_bandwidth()
2962 return -EOPNOTSUPP; in usb4_dp_port_requested_bandwidth()
2964 ret = usb4_dp_port_granularity(port); in usb4_dp_port_requested_bandwidth()
2969 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_requested_bandwidth()
2970 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_requested_bandwidth()
2975 return -ENODATA; in usb4_dp_port_requested_bandwidth()
2981 * usb4_pci_port_set_ext_encapsulation() - Enable/disable extended encapsulation
2982 * @port: PCIe adapter
2989 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable) in usb4_pci_port_set_ext_encapsulation() argument
2994 if (!tb_port_is_pcie_up(port) && !tb_port_is_pcie_down(port)) in usb4_pci_port_set_ext_encapsulation()
2995 return -EINVAL; in usb4_pci_port_set_ext_encapsulation()
2997 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
2998 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()
3007 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
3008 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()