• Home
  • Raw
  • Download

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()
162 struct tb_port *port; in usb4_switch_check_wakes() local
166 if (!device_may_wakeup(&sw->dev)) in usb4_switch_check_wakes()
170 if (tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1)) in usb4_switch_check_wakes()
184 tb_switch_for_each_port(sw, port) { in usb4_switch_check_wakes()
185 if (!port->cap_usb4) in usb4_switch_check_wakes()
188 if (tb_port_read(port, &val, TB_CFG_PORT, in usb4_switch_check_wakes()
189 port->cap_usb4 + PORT_CS_18, 1)) in usb4_switch_check_wakes()
192 tb_port_dbg(port, "USB4 wake: %s, connection wake: %s, disconnection wake: %s\n", in usb4_switch_check_wakes()
200 usb4 = port->usb4; in usb4_switch_check_wakes()
201 if (device_may_wakeup(&usb4->dev) && wakeup_usb4) in usb4_switch_check_wakes()
202 pm_wakeup_event(&usb4->dev, 0); in usb4_switch_check_wakes()
208 pm_wakeup_event(&sw->dev, 0); in usb4_switch_check_wakes()
211 static bool link_is_usb4(struct tb_port *port) in link_is_usb4() argument
215 if (!port->cap_usb4) in link_is_usb4()
218 if (tb_port_read(port, &val, TB_CFG_PORT, in link_is_usb4()
219 port->cap_usb4 + PORT_CS_18, 1)) in link_is_usb4()
226 * usb4_switch_setup() - Additional setup for USB4 device
252 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1); in usb4_switch_setup()
257 sw->link_usb4 = link_is_usb4(down); in usb4_switch_setup()
258 tb_sw_dbg(sw, "link: %s\n", sw->link_usb4 ? "USB4" : "TBT"); in usb4_switch_setup()
266 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_setup()
270 if (tb_acpi_may_tunnel_usb3() && sw->link_usb4 && in usb4_switch_setup()
295 return tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_setup()
299 * usb4_switch_configuration_valid() - Set tunneling configuration to be valid
317 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_configuration_valid()
323 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_configuration_valid()
332 * usb4_switch_read_uid() - Read UID from USB4 router
336 * Reads 64-bit UID from USB4 router config space.
361 return status ? -EIO : 0; in usb4_switch_drom_read_block()
365 * usb4_switch_drom_read() - Read arbitrary bytes from USB4 router DROM
372 * should always work but for hosts it may return %-EOPNOTSUPP in which
383 * usb4_switch_lane_bonding_possible() - Are conditions met for lane bonding
396 ret = tb_port_read(up, &val, TB_CFG_PORT, up->cap_usb4 + PORT_CS_18, 1); in usb4_switch_lane_bonding_possible()
404 * usb4_switch_set_wake() - Enabled/disable wake
413 struct tb_port *port; in usb4_switch_set_wake() local
421 * upstream USB4 port. in usb4_switch_set_wake()
423 tb_switch_for_each_port(sw, port) { in usb4_switch_set_wake()
424 if (!tb_port_is_null(port)) in usb4_switch_set_wake()
426 if (!route && tb_is_upstream_port(port)) in usb4_switch_set_wake()
428 if (!port->cap_usb4) in usb4_switch_set_wake()
431 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_switch_set_wake()
432 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
438 if (tb_is_upstream_port(port)) { in usb4_switch_set_wake()
442 usb4 = port->usb4; in usb4_switch_set_wake()
445 device_may_wakeup(&usb4->dev)) && !configured) in usb4_switch_set_wake()
448 device_may_wakeup(&usb4->dev)) && configured) in usb4_switch_set_wake()
454 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_switch_set_wake()
455 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
465 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_wake()
477 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_wake()
486 * usb4_switch_set_sleep() - Prepare the router to enter sleep
498 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_sleep()
504 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_sleep()
513 * usb4_switch_nvm_sector_size() - Return router NVM sector size
518 * %-EOPNOTSUPP.
532 return status == 0x2 ? -EOPNOTSUPP : -EIO; in usb4_switch_nvm_sector_size()
555 return status ? -EIO : 0; in usb4_switch_nvm_read_block()
559 * usb4_switch_nvm_read() - Read arbitrary bytes from router NVM
566 * %-EOPNOTSUPP.
576 * usb4_switch_nvm_set_offset() - Set NVM write offset
600 return status ? -EIO : 0; in usb4_switch_nvm_set_offset()
615 return status ? -EIO : 0; in usb4_switch_nvm_write_next_block()
619 * usb4_switch_nvm_write() - Write to the router NVM
626 * write is not supported returns %-EOPNOTSUPP.
642 * usb4_switch_nvm_authenticate() - Authenticate new NVM
664 case -EACCES: in usb4_switch_nvm_authenticate()
665 case -ENOTCONN: in usb4_switch_nvm_authenticate()
666 case -ETIMEDOUT: in usb4_switch_nvm_authenticate()
675 * usb4_switch_nvm_authenticate_status() - Read status of last NVM authenticate
688 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in usb4_switch_nvm_authenticate_status()
693 if (cm_ops->usb4_switch_nvm_authenticate_status) { in usb4_switch_nvm_authenticate_status()
694 ret = cm_ops->usb4_switch_nvm_authenticate_status(sw, status); in usb4_switch_nvm_authenticate_status()
695 if (ret != -EOPNOTSUPP) in usb4_switch_nvm_authenticate_status()
699 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_switch_nvm_authenticate_status()
707 return -EBUSY; in usb4_switch_nvm_authenticate_status()
709 return -EOPNOTSUPP; in usb4_switch_nvm_authenticate_status()
721 * usb4_switch_credits_init() - Read buffer allocation parameters
725 * allocation fields accordingly. Specifically @sw->credits_allocation
734 const struct tb_port *port; in usb4_switch_credits_init() local
745 return -EIO; in usb4_switch_credits_init()
749 return -EMSGSIZE; in usb4_switch_credits_init()
751 max_usb3 = -1; in usb4_switch_credits_init()
752 min_dp_aux = -1; in usb4_switch_credits_init()
753 min_dp_main = -1; in usb4_switch_credits_init()
754 max_pcie = -1; in usb4_switch_credits_init()
755 max_dma = -1; in usb4_switch_credits_init()
795 * issues, log a warning and fall back using the hard-coded in usb4_switch_credits_init()
806 tb_switch_for_each_port(sw, port) { in usb4_switch_credits_init()
807 if (tb_port_is_null(port)) in usb4_switch_credits_init()
817 tb_switch_for_each_port(sw, port) { in usb4_switch_credits_init()
818 if (tb_port_is_dpout(port) && min_dp_main < 0) { in usb4_switch_credits_init()
822 if ((tb_port_is_dpin(port) || tb_port_is_dpout(port)) && in usb4_switch_credits_init()
827 if ((tb_port_is_usb3_down(port) || tb_port_is_usb3_up(port)) && in usb4_switch_credits_init()
832 if ((tb_port_is_pcie_down(port) || tb_port_is_pcie_up(port)) && in usb4_switch_credits_init()
843 sw->credit_allocation = true; in usb4_switch_credits_init()
845 sw->max_usb3_credits = max_usb3; in usb4_switch_credits_init()
847 sw->min_dp_aux_credits = min_dp_aux; in usb4_switch_credits_init()
849 sw->min_dp_main_credits = min_dp_main; in usb4_switch_credits_init()
851 sw->max_pcie_credits = max_pcie; in usb4_switch_credits_init()
853 sw->max_dma_credits = max_dma; in usb4_switch_credits_init()
858 return -EINVAL; in usb4_switch_credits_init()
862 * usb4_switch_query_dp_resource() - Query availability of DP IN resource
872 u32 metadata = in->port; in usb4_switch_query_dp_resource()
882 if (ret == -EOPNOTSUPP) in usb4_switch_query_dp_resource()
891 * usb4_switch_alloc_dp_resource() - Allocate DP IN resource
897 * returns negative errno, in particular %-EBUSY if the resource is
902 u32 metadata = in->port; in usb4_switch_alloc_dp_resource()
908 if (ret == -EOPNOTSUPP) in usb4_switch_alloc_dp_resource()
913 return status ? -EBUSY : 0; in usb4_switch_alloc_dp_resource()
917 * usb4_switch_dealloc_dp_resource() - Releases allocated DP IN resource
925 u32 metadata = in->port; in usb4_switch_dealloc_dp_resource()
931 if (ret == -EOPNOTSUPP) in usb4_switch_dealloc_dp_resource()
936 return status ? -EIO : 0; in usb4_switch_dealloc_dp_resource()
939 static int usb4_port_idx(const struct tb_switch *sw, const struct tb_port *port) in usb4_port_idx() argument
944 /* Assume port is primary */ in usb4_port_idx()
950 if (!p->link_nr) { in usb4_port_idx()
951 if (p == port) in usb4_port_idx()
961 * usb4_switch_map_pcie_down() - Map USB4 port to a PCIe downstream adapter
963 * @port: USB4 port
971 const struct tb_port *port) in usb4_switch_map_pcie_down() argument
973 int usb4_idx = usb4_port_idx(sw, port); in usb4_switch_map_pcie_down()
977 /* Find PCIe down port matching usb4_port */ in usb4_switch_map_pcie_down()
992 * usb4_switch_map_usb3_down() - Map USB4 port to a USB3 downstream adapter
994 * @port: USB4 port
1002 const struct tb_port *port) in usb4_switch_map_usb3_down() argument
1004 int usb4_idx = usb4_port_idx(sw, port); in usb4_switch_map_usb3_down()
1008 /* Find USB3 down port matching usb4_port */ in usb4_switch_map_usb3_down()
1023 * usb4_switch_add_ports() - Add USB4 ports for this router
1033 struct tb_port *port; in usb4_switch_add_ports() local
1038 tb_switch_for_each_port(sw, port) { in usb4_switch_add_ports()
1041 if (!tb_port_is_null(port)) in usb4_switch_add_ports()
1043 if (!port->cap_usb4) in usb4_switch_add_ports()
1046 usb4 = usb4_port_device_add(port); in usb4_switch_add_ports()
1052 port->usb4 = usb4; in usb4_switch_add_ports()
1059 * usb4_switch_remove_ports() - Removes USB4 ports from this router
1066 struct tb_port *port; in usb4_switch_remove_ports() local
1068 tb_switch_for_each_port(sw, port) { in usb4_switch_remove_ports()
1069 if (port->usb4) { in usb4_switch_remove_ports()
1070 usb4_port_device_remove(port->usb4); in usb4_switch_remove_ports()
1071 port->usb4 = NULL; in usb4_switch_remove_ports()
1077 * usb4_port_unlock() - Unlock USB4 downstream port
1078 * @port: USB4 port to unlock
1080 * Unlocks USB4 downstream port so that the connection manager can
1081 * access the router below this port.
1083 int usb4_port_unlock(struct tb_port *port) in usb4_port_unlock() argument
1088 ret = tb_port_read(port, &val, TB_CFG_PORT, ADP_CS_4, 1); in usb4_port_unlock()
1093 return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_4, 1); in usb4_port_unlock()
1097 * usb4_port_hotplug_enable() - Enables hotplug for a port
1098 * @port: USB4 port to operate on
1100 * Enables hot plug events on a given port. This is only intended
1101 * to be used on lane, DP-IN, and DP-OUT adapters.
1103 int usb4_port_hotplug_enable(struct tb_port *port) in usb4_port_hotplug_enable() argument
1108 ret = tb_port_read(port, &val, TB_CFG_PORT, ADP_CS_5, 1); in usb4_port_hotplug_enable()
1113 return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_5, 1); in usb4_port_hotplug_enable()
1116 static int usb4_port_set_configured(struct tb_port *port, bool configured) in usb4_port_set_configured() argument
1121 if (!port->cap_usb4) in usb4_port_set_configured()
1122 return -EINVAL; in usb4_port_set_configured()
1124 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_set_configured()
1125 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_set_configured()
1134 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_set_configured()
1135 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_set_configured()
1139 * usb4_port_configure() - Set USB4 port configured
1140 * @port: USB4 router
1144 int usb4_port_configure(struct tb_port *port) in usb4_port_configure() argument
1146 return usb4_port_set_configured(port, true); in usb4_port_configure()
1150 * usb4_port_unconfigure() - Set USB4 port unconfigured
1151 * @port: USB4 router
1155 void usb4_port_unconfigure(struct tb_port *port) in usb4_port_unconfigure() argument
1157 usb4_port_set_configured(port, false); in usb4_port_unconfigure()
1160 static int usb4_set_xdomain_configured(struct tb_port *port, bool configured) in usb4_set_xdomain_configured() argument
1165 if (!port->cap_usb4) in usb4_set_xdomain_configured()
1166 return -EINVAL; in usb4_set_xdomain_configured()
1168 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_set_xdomain_configured()
1169 port->cap_usb4 + PORT_CS_19, 1); in usb4_set_xdomain_configured()
1178 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_set_xdomain_configured()
1179 port->cap_usb4 + PORT_CS_19, 1); in usb4_set_xdomain_configured()
1183 * usb4_port_configure_xdomain() - Configure port for XDomain
1184 * @port: USB4 port connected to another host
1185 * @xd: XDomain that is connected to the port
1187 * Marks the USB4 port as being connected to another host and updates
1190 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd) in usb4_port_configure_xdomain() argument
1192 xd->link_usb4 = link_is_usb4(port); in usb4_port_configure_xdomain()
1193 return usb4_set_xdomain_configured(port, true); in usb4_port_configure_xdomain()
1197 * usb4_port_unconfigure_xdomain() - Unconfigure port for XDomain
1198 * @port: USB4 port that was connected to another host
1200 * Clears USB4 port from being marked as XDomain.
1202 void usb4_port_unconfigure_xdomain(struct tb_port *port) in usb4_port_unconfigure_xdomain() argument
1204 usb4_set_xdomain_configured(port, false); in usb4_port_unconfigure_xdomain()
1207 static int usb4_port_wait_for_bit(struct tb_port *port, u32 offset, u32 bit, in usb4_port_wait_for_bit() argument
1216 ret = tb_port_read(port, &val, TB_CFG_PORT, offset, 1); in usb4_port_wait_for_bit()
1226 return -ETIMEDOUT; in usb4_port_wait_for_bit()
1229 static int usb4_port_read_data(struct tb_port *port, void *data, size_t dwords) in usb4_port_read_data() argument
1232 return -EINVAL; in usb4_port_read_data()
1234 return tb_port_read(port, data, TB_CFG_PORT, port->cap_usb4 + PORT_CS_2, in usb4_port_read_data()
1238 static int usb4_port_write_data(struct tb_port *port, const void *data, in usb4_port_write_data() argument
1242 return -EINVAL; in usb4_port_write_data()
1244 return tb_port_write(port, data, TB_CFG_PORT, port->cap_usb4 + PORT_CS_2, in usb4_port_write_data()
1248 static int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_read() argument
1255 if (!port->cap_usb4) in usb4_port_sb_read()
1256 return -EINVAL; in usb4_port_sb_read()
1265 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_sb_read()
1266 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1270 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_read()
1275 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_sb_read()
1276 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1281 return -ENODEV; in usb4_port_sb_read()
1283 return -EIO; in usb4_port_sb_read()
1285 return buf ? usb4_port_read_data(port, buf, dwords) : 0; in usb4_port_sb_read()
1288 static int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_write() argument
1295 if (!port->cap_usb4) in usb4_port_sb_write()
1296 return -EINVAL; in usb4_port_sb_write()
1299 ret = usb4_port_write_data(port, buf, dwords); in usb4_port_sb_write()
1312 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_sb_write()
1313 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1317 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_write()
1322 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_sb_write()
1323 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1328 return -ENODEV; in usb4_port_sb_write()
1330 return -EIO; in usb4_port_sb_write()
1341 return -EAGAIN; in usb4_port_sb_opcode_err_to_errno()
1343 return -EOPNOTSUPP; in usb4_port_sb_opcode_err_to_errno()
1345 return -EIO; in usb4_port_sb_opcode_err_to_errno()
1349 static int usb4_port_sb_op(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_op() argument
1357 ret = usb4_port_sb_write(port, target, index, USB4_SB_OPCODE, &val, in usb4_port_sb_op()
1366 ret = usb4_port_sb_read(port, target, index, USB4_SB_OPCODE, in usb4_port_sb_op()
1375 return -ETIMEDOUT; in usb4_port_sb_op()
1378 static int usb4_port_set_router_offline(struct tb_port *port, bool offline) in usb4_port_set_router_offline() argument
1383 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_set_router_offline()
1389 return usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_set_router_offline()
1394 * usb4_port_router_offline() - Put the USB4 port to offline mode
1395 * @port: USB4 port
1397 * This function puts the USB4 port into offline mode. In this mode the
1398 * port does not react on hotplug events anymore. This needs to be
1404 int usb4_port_router_offline(struct tb_port *port) in usb4_port_router_offline() argument
1406 return usb4_port_set_router_offline(port, true); in usb4_port_router_offline()
1410 * usb4_port_router_online() - Put the USB4 port back to online
1411 * @port: USB4 port
1413 * Makes the USB4 port functional again.
1415 int usb4_port_router_online(struct tb_port *port) in usb4_port_router_online() argument
1417 return usb4_port_set_router_offline(port, false); in usb4_port_router_online()
1421 * usb4_port_enumerate_retimers() - Send RT broadcast transaction
1422 * @port: USB4 port
1424 * This forces the USB4 port to send broadcast RT transaction which
1428 int usb4_port_enumerate_retimers(struct tb_port *port) in usb4_port_enumerate_retimers() argument
1433 return usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_enumerate_retimers()
1438 * usb4_port_clx_supported() - Check if CLx is supported by the link
1439 * @port: Port to check for CLx support for
1444 bool usb4_port_clx_supported(struct tb_port *port) in usb4_port_clx_supported() argument
1449 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_clx_supported()
1450 port->cap_usb4 + PORT_CS_18, 1); in usb4_port_clx_supported()
1458 * usb4_port_margining_caps() - Read USB4 port marginig capabilities
1459 * @port: USB4 port
1462 * Reads the USB4 port lane margining capabilities into @caps.
1464 int usb4_port_margining_caps(struct tb_port *port, u32 *caps) in usb4_port_margining_caps() argument
1468 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_margining_caps()
1473 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_margining_caps()
1478 * usb4_port_hw_margin() - Run hardware lane margining on port
1479 * @port: USB4 port
1480 * @lanes: Which lanes to run (must match the port capabilities). Can be
1481 * %0, %1 or %7.
1487 * Runs hardware lane margining on USB4 port and returns the result in
1490 int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes, in usb4_port_hw_margin() argument
1506 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1511 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1516 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1521 * usb4_port_sw_margin() - Run software lane margining on port
1522 * @port: USB4 port
1523 * @lanes: Which lanes to run (must match the port capabilities). Can be
1524 * %0, %1 or %7.
1529 * Runs software lane margining on USB4 port. Read back the error
1533 int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing, in usb4_port_sw_margin() argument
1547 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin()
1552 return usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin()
1557 * usb4_port_sw_margin_errors() - Read the software margining error counters
1558 * @port: USB4 port
1561 * This reads back the software margining error counters from the port.
1564 int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors) in usb4_port_sw_margin_errors() argument
1568 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin_errors()
1573 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin_errors()
1577 static inline int usb4_port_retimer_op(struct tb_port *port, u8 index, in usb4_port_retimer_op() argument
1581 return usb4_port_sb_op(port, USB4_SB_TARGET_RETIMER, index, opcode, in usb4_port_retimer_op()
1586 * usb4_port_retimer_set_inbound_sbtx() - Enable sideband channel transactions
1587 * @port: USB4 port
1593 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_set_inbound_sbtx() argument
1597 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1600 if (ret != -ENODEV) in usb4_port_retimer_set_inbound_sbtx()
1608 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1613 * usb4_port_retimer_unset_inbound_sbtx() - Disable sideband channel transactions
1614 * @port: USB4 port
1620 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_unset_inbound_sbtx() argument
1622 return usb4_port_retimer_op(port, index, in usb4_port_retimer_unset_inbound_sbtx()
1627 * usb4_port_retimer_read() - Read from retimer sideband registers
1628 * @port: USB4 port
1635 * retimer is connected to @port at @index. Returns %0 in case of
1637 * present at given @index returns %-ENODEV. In any other failure
1640 int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf, in usb4_port_retimer_read() argument
1643 return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, reg, buf, in usb4_port_retimer_read()
1648 * usb4_port_retimer_write() - Write to retimer sideband registers
1649 * @port: USB4 port
1656 * connected to @port at @index. Returns %0 in case of success. If there
1657 * is no retimer present at given @index returns %-ENODEV. In any other
1660 int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg, in usb4_port_retimer_write() argument
1663 return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, reg, buf, in usb4_port_retimer_write()
1668 * usb4_port_retimer_is_last() - Is the retimer last on-board retimer
1669 * @port: USB4 port
1673 * Type-C port) this function returns %1. If it is not returns %0. If
1674 * the retimer is not present returns %-ENODEV. Otherwise returns
1677 int usb4_port_retimer_is_last(struct tb_port *port, u8 index) in usb4_port_retimer_is_last() argument
1682 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_QUERY_LAST_RETIMER, in usb4_port_retimer_is_last()
1687 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_is_last()
1689 return ret ? ret : metadata & 1; in usb4_port_retimer_is_last()
1693 * usb4_port_retimer_nvm_sector_size() - Read retimer NVM sector size
1694 * @port: USB4 port
1700 * in case of error. Specifically returns %-ENODEV if there is no
1703 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_sector_size() argument
1708 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_GET_NVM_SECTOR_SIZE, in usb4_port_retimer_nvm_sector_size()
1713 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_sector_size()
1719 * usb4_port_retimer_nvm_set_offset() - Set NVM write offset
1720 * @port: USB4 port
1729 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_set_offset() argument
1739 ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_set_offset()
1744 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_SET_OFFSET, in usb4_port_retimer_nvm_set_offset()
1749 struct tb_port *port; member
1758 struct tb_port *port = info->port; in usb4_port_retimer_nvm_write_next_block() local
1759 u8 index = info->index; in usb4_port_retimer_nvm_write_next_block()
1762 ret = usb4_port_retimer_write(port, index, USB4_SB_DATA, in usb4_port_retimer_nvm_write_next_block()
1767 return usb4_port_retimer_op(port, index, in usb4_port_retimer_nvm_write_next_block()
1772 * usb4_port_retimer_nvm_write() - Write to retimer NVM
1773 * @port: USB4 port
1781 * errno in case of failure. Specifically returns %-ENODEV if there is
1784 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index, unsigned int address, in usb4_port_retimer_nvm_write() argument
1787 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_write()
1790 ret = usb4_port_retimer_nvm_set_offset(port, index, address); in usb4_port_retimer_nvm_write()
1799 * usb4_port_retimer_nvm_authenticate() - Start retimer NVM upgrade
1800 * @port: USB4 port
1809 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_authenticate() argument
1819 return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate()
1824 * usb4_port_retimer_nvm_authenticate_status() - Read status of NVM upgrade
1825 * @port: USB4 port
1836 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_authenticate_status() argument
1842 ret = usb4_port_retimer_read(port, index, USB4_SB_OPCODE, &val, in usb4_port_retimer_nvm_authenticate_status()
1853 case -EAGAIN: in usb4_port_retimer_nvm_authenticate_status()
1854 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, in usb4_port_retimer_nvm_authenticate_status()
1871 struct tb_port *port = info->port; in usb4_port_retimer_nvm_read_block() local
1872 u8 index = info->index; in usb4_port_retimer_nvm_read_block()
1880 ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_read_block()
1885 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_READ, 500); in usb4_port_retimer_nvm_read_block()
1889 return usb4_port_retimer_read(port, index, USB4_SB_DATA, buf, in usb4_port_retimer_nvm_read_block()
1894 * usb4_port_retimer_nvm_read() - Read contents of retimer NVM
1895 * @port: USB4 port
1903 * Specifically returns %-ENODEV if there is no retimer at @index.
1905 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_read() argument
1908 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_read()
1915 usb4_usb3_port_max_bandwidth(const struct tb_port *port, unsigned int bw) in usb4_usb3_port_max_bandwidth() argument
1918 if (port->max_bw) in usb4_usb3_port_max_bandwidth()
1919 return min(bw, port->max_bw); in usb4_usb3_port_max_bandwidth()
1924 * usb4_usb3_port_max_link_rate() - Maximum support USB3 link rate
1925 * @port: USB3 adapter port
1930 int usb4_usb3_port_max_link_rate(struct tb_port *port) in usb4_usb3_port_max_link_rate() argument
1935 if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port)) in usb4_usb3_port_max_link_rate()
1936 return -EINVAL; in usb4_usb3_port_max_link_rate()
1938 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_max_link_rate()
1939 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_max_link_rate()
1946 return usb4_usb3_port_max_bandwidth(port, ret); in usb4_usb3_port_max_link_rate()
1950 * usb4_usb3_port_actual_link_rate() - Established USB3 link rate
1951 * @port: USB3 adapter port
1956 int usb4_usb3_port_actual_link_rate(struct tb_port *port) in usb4_usb3_port_actual_link_rate() argument
1961 if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port)) in usb4_usb3_port_actual_link_rate()
1962 return -EINVAL; in usb4_usb3_port_actual_link_rate()
1964 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_actual_link_rate()
1965 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_actual_link_rate()
1975 return usb4_usb3_port_max_bandwidth(port, ret); in usb4_usb3_port_actual_link_rate()
1978 static int usb4_usb3_port_cm_request(struct tb_port *port, bool request) in usb4_usb3_port_cm_request() argument
1983 if (!tb_port_is_usb3_down(port)) in usb4_usb3_port_cm_request()
1984 return -EINVAL; in usb4_usb3_port_cm_request()
1985 if (tb_route(port->sw)) in usb4_usb3_port_cm_request()
1986 return -EINVAL; in usb4_usb3_port_cm_request()
1988 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
1989 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
1998 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
1999 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2008 return usb4_port_wait_for_bit(port, port->cap_adap + ADP_USB3_CS_1, in usb4_usb3_port_cm_request()
2012 static inline int usb4_usb3_port_set_cm_request(struct tb_port *port) in usb4_usb3_port_set_cm_request() argument
2014 return usb4_usb3_port_cm_request(port, true); in usb4_usb3_port_set_cm_request()
2017 static inline int usb4_usb3_port_clear_cm_request(struct tb_port *port) in usb4_usb3_port_clear_cm_request() argument
2019 return usb4_usb3_port_cm_request(port, false); in usb4_usb3_port_clear_cm_request()
2034 /* 1 uframe is 1/8 ms (125 us) -> 1 / 8000 s */ in mbps_to_usb3_bw()
2039 static int usb4_usb3_port_read_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_read_allocated_bandwidth() argument
2046 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2047 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_read_allocated_bandwidth()
2051 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2052 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_allocated_bandwidth()
2068 * usb4_usb3_port_allocated_bandwidth() - Bandwidth allocated for USB3
2069 * @port: USB3 adapter port
2077 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocated_bandwidth() argument
2082 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2086 ret = usb4_usb3_port_read_allocated_bandwidth(port, upstream_bw, in usb4_usb3_port_allocated_bandwidth()
2088 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2093 static int usb4_usb3_port_read_consumed_bandwidth(struct tb_port *port, in usb4_usb3_port_read_consumed_bandwidth() argument
2100 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2101 port->cap_adap + ADP_USB3_CS_1, 1); in usb4_usb3_port_read_consumed_bandwidth()
2105 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2106 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_consumed_bandwidth()
2121 static int usb4_usb3_port_write_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_write_allocated_bandwidth() argument
2138 return -EINVAL; in usb4_usb3_port_write_allocated_bandwidth()
2140 ret = tb_port_write(port, &scale, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2141 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_write_allocated_bandwidth()
2148 tb_port_dbg(port, "scaled bandwidth %u/%u, scale %u\n", ubw, dbw, scale); in usb4_usb3_port_write_allocated_bandwidth()
2150 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2151 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2159 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2160 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2164 * usb4_usb3_port_allocate_bandwidth() - Allocate bandwidth for USB3
2165 * @port: USB3 adapter port
2180 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocate_bandwidth() argument
2185 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2189 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_allocate_bandwidth()
2198 ret = usb4_usb3_port_write_allocated_bandwidth(port, allocate_up, in usb4_usb3_port_allocate_bandwidth()
2207 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2212 * usb4_usb3_port_release_bandwidth() - Release allocated USB3 bandwidth
2213 * @port: USB3 adapter port
2222 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_release_bandwidth() argument
2227 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_release_bandwidth()
2231 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_release_bandwidth()
2245 ret = usb4_usb3_port_write_allocated_bandwidth(port, consumed_up, in usb4_usb3_port_release_bandwidth()
2254 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_release_bandwidth()
2258 static bool is_usb4_dpin(const struct tb_port *port) in is_usb4_dpin() argument
2260 if (!tb_port_is_dpin(port)) in is_usb4_dpin()
2262 if (!tb_switch_is_usb4(port->sw)) in is_usb4_dpin()
2268 * usb4_dp_port_set_cm_id() - Assign CM ID to the DP IN adapter
2269 * @port: DP IN adapter
2272 * Sets CM ID for the @port. Returns %0 on success and negative errno
2273 * otherwise. Speficially returns %-EOPNOTSUPP if the @port does not
2276 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id) in usb4_dp_port_set_cm_id() argument
2281 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_id()
2282 return -EOPNOTSUPP; in usb4_dp_port_set_cm_id()
2284 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2285 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2292 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2293 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2297 * usb4_dp_port_bandwidth_mode_supported() - Is the bandwidth allocation mode
2299 * @port: DP IN adapter to check
2304 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port) in usb4_dp_port_bandwidth_mode_supported() argument
2309 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_supported()
2312 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_supported()
2313 port->cap_adap + DP_LOCAL_CAP, 1); in usb4_dp_port_bandwidth_mode_supported()
2321 * usb4_dp_port_bandwidth_mode_enabled() - Is the bandwidth allocation mode
2323 * @port: DP IN adapter to check
2328 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port) in usb4_dp_port_bandwidth_mode_enabled() argument
2333 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_enabled()
2336 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_enabled()
2337 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_bandwidth_mode_enabled()
2345 * usb4_dp_port_set_cm_bandwidth_mode_supported() - Set/clear CM support for
2347 * @port: DP IN adapter
2352 * otherwise. Specifically returns %-OPNOTSUPP if the passed in adapter
2355 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port, in usb4_dp_port_set_cm_bandwidth_mode_supported() argument
2361 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_bandwidth_mode_supported()
2362 return -EOPNOTSUPP; in usb4_dp_port_set_cm_bandwidth_mode_supported()
2364 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2365 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2374 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2375 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2379 * usb4_dp_port_group_id() - Return Group ID assigned for the adapter
2380 * @port: DP IN adapter
2384 * %-EOPNOTSUPP is returned.
2386 int usb4_dp_port_group_id(struct tb_port *port) in usb4_dp_port_group_id() argument
2391 if (!is_usb4_dpin(port)) in usb4_dp_port_group_id()
2392 return -EOPNOTSUPP; in usb4_dp_port_group_id()
2394 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_group_id()
2395 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_group_id()
2403 * usb4_dp_port_set_group_id() - Set adapter Group ID
2404 * @port: DP IN adapter
2409 * Specifically returns %-EOPNOTSUPP if the adapter does not support
2412 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id) in usb4_dp_port_set_group_id() argument
2417 if (!is_usb4_dpin(port)) in usb4_dp_port_set_group_id()
2418 return -EOPNOTSUPP; in usb4_dp_port_set_group_id()
2420 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2421 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2428 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2429 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2433 * usb4_dp_port_nrd() - Read non-reduced rate and lanes
2434 * @port: DP IN adapter
2435 * @rate: Non-reduced rate in Mb/s is placed here
2436 * @lanes: Non-reduced lanes are placed here
2438 * Reads the non-reduced rate and lanes from the DP IN adapter. Returns
2440 * %-EOPNOTSUPP if the adapter does not support this.
2442 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes) in usb4_dp_port_nrd() argument
2447 if (!is_usb4_dpin(port)) in usb4_dp_port_nrd()
2448 return -EOPNOTSUPP; in usb4_dp_port_nrd()
2450 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_nrd()
2451 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_nrd()
2474 *lanes = 1; in usb4_dp_port_nrd()
2488 * usb4_dp_port_set_nrd() - Set non-reduced rate and lanes
2489 * @port: DP IN adapter
2490 * @rate: Non-reduced rate in Mb/s
2491 * @lanes: Non-reduced lanes
2494 * the non-reduced values for the DP IN adapter. Returns %0 in success
2496 * %-EOPNOTSUPP is returned.
2498 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes) in usb4_dp_port_set_nrd() argument
2503 if (!is_usb4_dpin(port)) in usb4_dp_port_set_nrd()
2504 return -EOPNOTSUPP; in usb4_dp_port_set_nrd()
2506 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2507 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2529 return -EINVAL; in usb4_dp_port_set_nrd()
2535 case 1: in usb4_dp_port_set_nrd()
2544 return -EINVAL; in usb4_dp_port_set_nrd()
2547 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2548 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2552 * usb4_dp_port_granularity() - Return granularity for the bandwidth values
2553 * @port: DP IN adapter
2555 * Reads the programmed granularity from @port. If the DP IN adapter does
2556 * not support bandwidth allocation mode returns %-EOPNOTSUPP and negative
2559 int usb4_dp_port_granularity(struct tb_port *port) in usb4_dp_port_granularity() argument
2564 if (!is_usb4_dpin(port)) in usb4_dp_port_granularity()
2565 return -EOPNOTSUPP; in usb4_dp_port_granularity()
2567 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_granularity()
2568 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_granularity()
2584 return -EINVAL; in usb4_dp_port_granularity()
2588 * usb4_dp_port_set_granularity() - Set granularity for the bandwidth values
2589 * @port: DP IN adapter
2594 * adapter does not support this %-EOPNOTSUPP is returned.
2596 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity) in usb4_dp_port_set_granularity() argument
2601 if (!is_usb4_dpin(port)) in usb4_dp_port_set_granularity()
2602 return -EOPNOTSUPP; in usb4_dp_port_set_granularity()
2604 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2605 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2622 return -EINVAL; in usb4_dp_port_set_granularity()
2625 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2626 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2630 * usb4_dp_port_set_estimated_bandwidth() - Set estimated bandwidth
2631 * @port: DP IN adapter
2637 * and negative errno otherwise. Specifically returns %-EOPNOTSUPP if
2640 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_set_estimated_bandwidth() argument
2645 if (!is_usb4_dpin(port)) in usb4_dp_port_set_estimated_bandwidth()
2646 return -EOPNOTSUPP; in usb4_dp_port_set_estimated_bandwidth()
2648 ret = usb4_dp_port_granularity(port); in usb4_dp_port_set_estimated_bandwidth()
2653 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2654 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2661 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2662 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2666 * usb4_dp_port_allocated_bandwidth() - Return allocated bandwidth
2667 * @port: DP IN adapter
2669 * Reads and returns allocated bandwidth for @port in Mb/s (taking into
2673 int usb4_dp_port_allocated_bandwidth(struct tb_port *port) in usb4_dp_port_allocated_bandwidth() argument
2678 if (!is_usb4_dpin(port)) in usb4_dp_port_allocated_bandwidth()
2679 return -EOPNOTSUPP; in usb4_dp_port_allocated_bandwidth()
2681 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocated_bandwidth()
2686 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocated_bandwidth()
2687 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocated_bandwidth()
2697 static int __usb4_dp_port_set_cm_ack(struct tb_port *port, bool ack) in __usb4_dp_port_set_cm_ack() argument
2702 ret = tb_port_read(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2703 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2712 return tb_port_write(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2713 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2716 static inline int usb4_dp_port_set_cm_ack(struct tb_port *port) in usb4_dp_port_set_cm_ack() argument
2718 return __usb4_dp_port_set_cm_ack(port, true); in usb4_dp_port_set_cm_ack()
2721 static int usb4_dp_port_wait_and_clear_cm_ack(struct tb_port *port, in usb4_dp_port_wait_and_clear_cm_ack() argument
2728 ret = __usb4_dp_port_set_cm_ack(port, false); in usb4_dp_port_wait_and_clear_cm_ack()
2734 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2735 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2746 return -ETIMEDOUT; in usb4_dp_port_wait_and_clear_cm_ack()
2748 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2749 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2754 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2755 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2759 * usb4_dp_port_allocate_bandwidth() - Set allocated bandwidth
2760 * @port: DP IN adapter
2767 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_allocate_bandwidth() argument
2772 if (!is_usb4_dpin(port)) in usb4_dp_port_allocate_bandwidth()
2773 return -EOPNOTSUPP; in usb4_dp_port_allocate_bandwidth()
2775 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocate_bandwidth()
2780 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2781 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2788 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2789 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2793 ret = usb4_dp_port_set_cm_ack(port); in usb4_dp_port_allocate_bandwidth()
2797 return usb4_dp_port_wait_and_clear_cm_ack(port, 500); in usb4_dp_port_allocate_bandwidth()
2801 * usb4_dp_port_requested_bandwidth() - Read requested bandwidth
2802 * @port: DP IN adapter
2806 * error returns negative errno. Specifically returns %-EOPNOTSUPP if
2810 int usb4_dp_port_requested_bandwidth(struct tb_port *port) in usb4_dp_port_requested_bandwidth() argument
2815 if (!is_usb4_dpin(port)) in usb4_dp_port_requested_bandwidth()
2816 return -EOPNOTSUPP; in usb4_dp_port_requested_bandwidth()
2818 ret = usb4_dp_port_granularity(port); in usb4_dp_port_requested_bandwidth()
2823 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_requested_bandwidth()
2824 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_requested_bandwidth()
2829 return -ENODATA; in usb4_dp_port_requested_bandwidth()
2835 * usb4_pci_port_set_ext_encapsulation() - Enable/disable extended encapsulation
2836 * @port: PCIe adapter
2843 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable) in usb4_pci_port_set_ext_encapsulation() argument
2848 if (!tb_port_is_pcie_up(port) && !tb_port_is_pcie_down(port)) in usb4_pci_port_set_ext_encapsulation()
2849 return -EINVAL; in usb4_pci_port_set_ext_encapsulation()
2851 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
2852 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()
2861 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
2862 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()