Lines Matching +full:1 +full:- +full:port
1 // SPDX-License-Identifier: GPL-2.0
62 ret = tb_sw_write(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1); in usb4_native_switch_op()
74 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_native_switch_op()
82 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_native_switch_op()
87 return -EOPNOTSUPP; in usb4_native_switch_op()
94 ret = tb_sw_read(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1); in usb4_native_switch_op()
112 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in __usb4_switch_op()
115 return -EINVAL; in __usb4_switch_op()
122 if (cm_ops->usb4_switch_op) { in __usb4_switch_op()
125 ret = cm_ops->usb4_switch_op(sw, opcode, metadata, status, in __usb4_switch_op()
128 if (ret != -EOPNOTSUPP) in __usb4_switch_op()
157 * usb4_switch_check_wakes() - Check for wakes and notify PM core about them
166 struct tb_port *port; in usb4_switch_check_wakes() local
171 if (tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1)) in usb4_switch_check_wakes()
185 tb_switch_for_each_port(sw, port) { in usb4_switch_check_wakes()
186 if (!port->cap_usb4) in usb4_switch_check_wakes()
189 if (tb_port_read(port, &val, TB_CFG_PORT, in usb4_switch_check_wakes()
190 port->cap_usb4 + PORT_CS_18, 1)) in usb4_switch_check_wakes()
193 tb_port_dbg(port, "USB4 wake: %s, connection wake: %s, disconnection wake: %s\n", in usb4_switch_check_wakes()
201 usb4 = port->usb4; in usb4_switch_check_wakes()
202 if (device_may_wakeup(&usb4->dev) && wakeup_usb4) in usb4_switch_check_wakes()
203 pm_wakeup_event(&usb4->dev, 0); in usb4_switch_check_wakes()
209 pm_wakeup_event(&sw->dev, 0); in usb4_switch_check_wakes()
212 static bool link_is_usb4(struct tb_port *port) in link_is_usb4() argument
216 if (!port->cap_usb4) in link_is_usb4()
219 if (tb_port_read(port, &val, TB_CFG_PORT, in link_is_usb4()
220 port->cap_usb4 + PORT_CS_18, 1)) in link_is_usb4()
227 * usb4_switch_setup() - Additional setup for USB4 device
251 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1); in usb4_switch_setup()
256 sw->link_usb4 = link_is_usb4(down); in usb4_switch_setup()
257 tb_sw_dbg(sw, "link: %s\n", sw->link_usb4 ? "USB4" : "TBT"); in usb4_switch_setup()
265 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_setup()
269 if (tb_acpi_may_tunnel_usb3() && sw->link_usb4 && in usb4_switch_setup()
294 return tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_setup()
298 * usb4_switch_configuration_valid() - Set tunneling configuration to be valid
316 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_configuration_valid()
322 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_configuration_valid()
331 * usb4_switch_read_uid() - Read UID from USB4 router
335 * Reads 64-bit UID from USB4 router config space.
360 return status ? -EIO : 0; in usb4_switch_drom_read_block()
364 * usb4_switch_drom_read() - Read arbitrary bytes from USB4 router DROM
371 * should always work but for hosts it may return %-EOPNOTSUPP in which
382 * usb4_switch_lane_bonding_possible() - Are conditions met for lane bonding
395 ret = tb_port_read(up, &val, TB_CFG_PORT, up->cap_usb4 + PORT_CS_18, 1); in usb4_switch_lane_bonding_possible()
403 * usb4_switch_set_wake() - Enabled/disable wake
412 struct tb_port *port; in usb4_switch_set_wake() local
420 * upstream USB4 port. in usb4_switch_set_wake()
422 tb_switch_for_each_port(sw, port) { in usb4_switch_set_wake()
423 if (!tb_port_is_null(port)) in usb4_switch_set_wake()
425 if (!route && tb_is_upstream_port(port)) in usb4_switch_set_wake()
427 if (!port->cap_usb4) in usb4_switch_set_wake()
430 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_switch_set_wake()
431 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
437 if (tb_is_upstream_port(port)) { in usb4_switch_set_wake()
441 usb4 = port->usb4; in usb4_switch_set_wake()
444 device_may_wakeup(&usb4->dev)) && !configured) in usb4_switch_set_wake()
447 device_may_wakeup(&usb4->dev)) && configured) in usb4_switch_set_wake()
453 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_switch_set_wake()
454 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
464 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_wake()
476 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_wake()
485 * usb4_switch_set_sleep() - Prepare the router to enter sleep
497 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_sleep()
503 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_sleep()
512 * usb4_switch_nvm_sector_size() - Return router NVM sector size
517 * %-EOPNOTSUPP.
531 return status == 0x2 ? -EOPNOTSUPP : -EIO; in usb4_switch_nvm_sector_size()
554 return status ? -EIO : 0; in usb4_switch_nvm_read_block()
558 * usb4_switch_nvm_read() - Read arbitrary bytes from router NVM
565 * %-EOPNOTSUPP.
575 * usb4_switch_nvm_set_offset() - Set NVM write offset
599 return status ? -EIO : 0; in usb4_switch_nvm_set_offset()
614 return status ? -EIO : 0; in usb4_switch_nvm_write_next_block()
618 * usb4_switch_nvm_write() - Write to the router NVM
625 * write is not supported returns %-EOPNOTSUPP.
641 * usb4_switch_nvm_authenticate() - Authenticate new NVM
663 case -EACCES: in usb4_switch_nvm_authenticate()
664 case -ENOTCONN: in usb4_switch_nvm_authenticate()
665 case -ETIMEDOUT: in usb4_switch_nvm_authenticate()
674 * usb4_switch_nvm_authenticate_status() - Read status of last NVM authenticate
687 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in usb4_switch_nvm_authenticate_status()
692 if (cm_ops->usb4_switch_nvm_authenticate_status) { in usb4_switch_nvm_authenticate_status()
693 ret = cm_ops->usb4_switch_nvm_authenticate_status(sw, status); in usb4_switch_nvm_authenticate_status()
694 if (ret != -EOPNOTSUPP) in usb4_switch_nvm_authenticate_status()
698 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_switch_nvm_authenticate_status()
706 return -EBUSY; in usb4_switch_nvm_authenticate_status()
708 return -EOPNOTSUPP; in usb4_switch_nvm_authenticate_status()
720 * usb4_switch_credits_init() - Read buffer allocation parameters
724 * allocation fields accordingly. Specifically @sw->credits_allocation
733 const struct tb_port *port; in usb4_switch_credits_init() local
744 return -EIO; in usb4_switch_credits_init()
748 return -EMSGSIZE; in usb4_switch_credits_init()
750 max_usb3 = -1; in usb4_switch_credits_init()
751 min_dp_aux = -1; in usb4_switch_credits_init()
752 min_dp_main = -1; in usb4_switch_credits_init()
753 max_pcie = -1; in usb4_switch_credits_init()
754 max_dma = -1; in usb4_switch_credits_init()
794 * issues, log a warning and fall back using the hard-coded in usb4_switch_credits_init()
805 tb_switch_for_each_port(sw, port) { in usb4_switch_credits_init()
806 if (tb_port_is_null(port)) in usb4_switch_credits_init()
816 tb_switch_for_each_port(sw, port) { in usb4_switch_credits_init()
817 if (tb_port_is_dpout(port) && min_dp_main < 0) { in usb4_switch_credits_init()
821 if ((tb_port_is_dpin(port) || tb_port_is_dpout(port)) && in usb4_switch_credits_init()
826 if ((tb_port_is_usb3_down(port) || tb_port_is_usb3_up(port)) && in usb4_switch_credits_init()
831 if ((tb_port_is_pcie_down(port) || tb_port_is_pcie_up(port)) && in usb4_switch_credits_init()
842 sw->credit_allocation = true; in usb4_switch_credits_init()
844 sw->max_usb3_credits = max_usb3; in usb4_switch_credits_init()
846 sw->min_dp_aux_credits = min_dp_aux; in usb4_switch_credits_init()
848 sw->min_dp_main_credits = min_dp_main; in usb4_switch_credits_init()
850 sw->max_pcie_credits = max_pcie; in usb4_switch_credits_init()
852 sw->max_dma_credits = max_dma; in usb4_switch_credits_init()
857 return -EINVAL; in usb4_switch_credits_init()
861 * usb4_switch_query_dp_resource() - Query availability of DP IN resource
871 u32 metadata = in->port; in usb4_switch_query_dp_resource()
881 if (ret == -EOPNOTSUPP) in usb4_switch_query_dp_resource()
890 * usb4_switch_alloc_dp_resource() - Allocate DP IN resource
896 * returns negative errno, in particular %-EBUSY if the resource is
901 u32 metadata = in->port; in usb4_switch_alloc_dp_resource()
907 if (ret == -EOPNOTSUPP) in usb4_switch_alloc_dp_resource()
912 return status ? -EBUSY : 0; in usb4_switch_alloc_dp_resource()
916 * usb4_switch_dealloc_dp_resource() - Releases allocated DP IN resource
924 u32 metadata = in->port; in usb4_switch_dealloc_dp_resource()
930 if (ret == -EOPNOTSUPP) in usb4_switch_dealloc_dp_resource()
935 return status ? -EIO : 0; in usb4_switch_dealloc_dp_resource()
938 static int usb4_port_idx(const struct tb_switch *sw, const struct tb_port *port) in usb4_port_idx() argument
943 /* Assume port is primary */ in usb4_port_idx()
949 if (!p->link_nr) { in usb4_port_idx()
950 if (p == port) in usb4_port_idx()
960 * usb4_switch_map_pcie_down() - Map USB4 port to a PCIe downstream adapter
962 * @port: USB4 port
970 const struct tb_port *port) in usb4_switch_map_pcie_down() argument
972 int usb4_idx = usb4_port_idx(sw, port); in usb4_switch_map_pcie_down()
976 /* Find PCIe down port matching usb4_port */ in usb4_switch_map_pcie_down()
991 * usb4_switch_map_usb3_down() - Map USB4 port to a USB3 downstream adapter
993 * @port: USB4 port
1001 const struct tb_port *port) in usb4_switch_map_usb3_down() argument
1003 int usb4_idx = usb4_port_idx(sw, port); in usb4_switch_map_usb3_down()
1007 /* Find USB3 down port matching usb4_port */ in usb4_switch_map_usb3_down()
1022 * usb4_switch_add_ports() - Add USB4 ports for this router
1032 struct tb_port *port; in usb4_switch_add_ports() local
1037 tb_switch_for_each_port(sw, port) { in usb4_switch_add_ports()
1040 if (!tb_port_is_null(port)) in usb4_switch_add_ports()
1042 if (!port->cap_usb4) in usb4_switch_add_ports()
1045 usb4 = usb4_port_device_add(port); in usb4_switch_add_ports()
1051 port->usb4 = usb4; in usb4_switch_add_ports()
1058 * usb4_switch_remove_ports() - Removes USB4 ports from this router
1065 struct tb_port *port; in usb4_switch_remove_ports() local
1067 tb_switch_for_each_port(sw, port) { in usb4_switch_remove_ports()
1068 if (port->usb4) { in usb4_switch_remove_ports()
1069 usb4_port_device_remove(port->usb4); in usb4_switch_remove_ports()
1070 port->usb4 = NULL; in usb4_switch_remove_ports()
1076 * usb4_port_unlock() - Unlock USB4 downstream port
1077 * @port: USB4 port to unlock
1079 * Unlocks USB4 downstream port so that the connection manager can
1080 * access the router below this port.
1082 int usb4_port_unlock(struct tb_port *port) in usb4_port_unlock() argument
1087 ret = tb_port_read(port, &val, TB_CFG_PORT, ADP_CS_4, 1); in usb4_port_unlock()
1092 return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_4, 1); in usb4_port_unlock()
1096 * usb4_port_hotplug_enable() - Enables hotplug for a port
1097 * @port: USB4 port to operate on
1099 * Enables hot plug events on a given port. This is only intended
1100 * to be used on lane, DP-IN, and DP-OUT adapters.
1102 int usb4_port_hotplug_enable(struct tb_port *port) in usb4_port_hotplug_enable() argument
1107 ret = tb_port_read(port, &val, TB_CFG_PORT, ADP_CS_5, 1); in usb4_port_hotplug_enable()
1112 return tb_port_write(port, &val, TB_CFG_PORT, ADP_CS_5, 1); in usb4_port_hotplug_enable()
1116 * usb4_port_reset() - Issue downstream port reset
1117 * @port: USB4 port to reset
1119 * Issues downstream port reset to @port.
1121 int usb4_port_reset(struct tb_port *port) in usb4_port_reset() argument
1126 if (!port->cap_usb4) in usb4_port_reset()
1127 return -EINVAL; in usb4_port_reset()
1129 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_reset()
1130 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1136 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_reset()
1137 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1143 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_reset()
1144 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1150 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_reset()
1151 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1154 static int usb4_port_set_configured(struct tb_port *port, bool configured) in usb4_port_set_configured() argument
1159 if (!port->cap_usb4) in usb4_port_set_configured()
1160 return -EINVAL; in usb4_port_set_configured()
1162 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_set_configured()
1163 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_set_configured()
1172 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_set_configured()
1173 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_set_configured()
1177 * usb4_port_configure() - Set USB4 port configured
1178 * @port: USB4 router
1182 int usb4_port_configure(struct tb_port *port) in usb4_port_configure() argument
1184 return usb4_port_set_configured(port, true); in usb4_port_configure()
1188 * usb4_port_unconfigure() - Set USB4 port unconfigured
1189 * @port: USB4 router
1193 void usb4_port_unconfigure(struct tb_port *port) in usb4_port_unconfigure() argument
1195 usb4_port_set_configured(port, false); in usb4_port_unconfigure()
1198 static int usb4_set_xdomain_configured(struct tb_port *port, bool configured) in usb4_set_xdomain_configured() argument
1203 if (!port->cap_usb4) in usb4_set_xdomain_configured()
1204 return -EINVAL; in usb4_set_xdomain_configured()
1206 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_set_xdomain_configured()
1207 port->cap_usb4 + PORT_CS_19, 1); in usb4_set_xdomain_configured()
1216 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_set_xdomain_configured()
1217 port->cap_usb4 + PORT_CS_19, 1); in usb4_set_xdomain_configured()
1221 * usb4_port_configure_xdomain() - Configure port for XDomain
1222 * @port: USB4 port connected to another host
1223 * @xd: XDomain that is connected to the port
1225 * Marks the USB4 port as being connected to another host and updates
1228 int usb4_port_configure_xdomain(struct tb_port *port, struct tb_xdomain *xd) in usb4_port_configure_xdomain() argument
1230 xd->link_usb4 = link_is_usb4(port); in usb4_port_configure_xdomain()
1231 return usb4_set_xdomain_configured(port, true); in usb4_port_configure_xdomain()
1235 * usb4_port_unconfigure_xdomain() - Unconfigure port for XDomain
1236 * @port: USB4 port that was connected to another host
1238 * Clears USB4 port from being marked as XDomain.
1240 void usb4_port_unconfigure_xdomain(struct tb_port *port) in usb4_port_unconfigure_xdomain() argument
1242 usb4_set_xdomain_configured(port, false); in usb4_port_unconfigure_xdomain()
1245 static int usb4_port_wait_for_bit(struct tb_port *port, u32 offset, u32 bit, in usb4_port_wait_for_bit() argument
1254 ret = tb_port_read(port, &val, TB_CFG_PORT, offset, 1); in usb4_port_wait_for_bit()
1264 return -ETIMEDOUT; in usb4_port_wait_for_bit()
1267 static int usb4_port_read_data(struct tb_port *port, void *data, size_t dwords) in usb4_port_read_data() argument
1270 return -EINVAL; in usb4_port_read_data()
1272 return tb_port_read(port, data, TB_CFG_PORT, port->cap_usb4 + PORT_CS_2, in usb4_port_read_data()
1276 static int usb4_port_write_data(struct tb_port *port, const void *data, in usb4_port_write_data() argument
1280 return -EINVAL; in usb4_port_write_data()
1282 return tb_port_write(port, data, TB_CFG_PORT, port->cap_usb4 + PORT_CS_2, in usb4_port_write_data()
1287 * usb4_port_sb_read() - Read from sideband register
1288 * @port: USB4 port to read
1298 int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, u8 index, in usb4_port_sb_read() argument
1305 if (!port->cap_usb4) in usb4_port_sb_read()
1306 return -EINVAL; in usb4_port_sb_read()
1315 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_sb_read()
1316 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1320 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_read()
1325 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_sb_read()
1326 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1331 return -ENODEV; in usb4_port_sb_read()
1333 return -EIO; in usb4_port_sb_read()
1335 return buf ? usb4_port_read_data(port, buf, dwords) : 0; in usb4_port_sb_read()
1339 * usb4_port_sb_write() - Write to sideband register
1340 * @port: USB4 port to write
1350 int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_write() argument
1357 if (!port->cap_usb4) in usb4_port_sb_write()
1358 return -EINVAL; in usb4_port_sb_write()
1361 ret = usb4_port_write_data(port, buf, dwords); in usb4_port_sb_write()
1374 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_sb_write()
1375 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1379 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_write()
1384 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_sb_write()
1385 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1390 return -ENODEV; in usb4_port_sb_write()
1392 return -EIO; in usb4_port_sb_write()
1403 return -EAGAIN; in usb4_port_sb_opcode_err_to_errno()
1405 return -EOPNOTSUPP; in usb4_port_sb_opcode_err_to_errno()
1407 return -EIO; in usb4_port_sb_opcode_err_to_errno()
1411 static int usb4_port_sb_op(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_op() argument
1419 ret = usb4_port_sb_write(port, target, index, USB4_SB_OPCODE, &val, in usb4_port_sb_op()
1428 ret = usb4_port_sb_read(port, target, index, USB4_SB_OPCODE, in usb4_port_sb_op()
1439 return -ETIMEDOUT; in usb4_port_sb_op()
1442 static int usb4_port_set_router_offline(struct tb_port *port, bool offline) in usb4_port_set_router_offline() argument
1447 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_set_router_offline()
1453 return usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_set_router_offline()
1458 * usb4_port_router_offline() - Put the USB4 port to offline mode
1459 * @port: USB4 port
1461 * This function puts the USB4 port into offline mode. In this mode the
1462 * port does not react on hotplug events anymore. This needs to be
1468 int usb4_port_router_offline(struct tb_port *port) in usb4_port_router_offline() argument
1470 return usb4_port_set_router_offline(port, true); in usb4_port_router_offline()
1474 * usb4_port_router_online() - Put the USB4 port back to online
1475 * @port: USB4 port
1477 * Makes the USB4 port functional again.
1479 int usb4_port_router_online(struct tb_port *port) in usb4_port_router_online() argument
1481 return usb4_port_set_router_offline(port, false); in usb4_port_router_online()
1485 * usb4_port_enumerate_retimers() - Send RT broadcast transaction
1486 * @port: USB4 port
1488 * This forces the USB4 port to send broadcast RT transaction which
1492 int usb4_port_enumerate_retimers(struct tb_port *port) in usb4_port_enumerate_retimers() argument
1497 return usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_enumerate_retimers()
1502 * usb4_port_clx_supported() - Check if CLx is supported by the link
1503 * @port: Port to check for CLx support for
1508 bool usb4_port_clx_supported(struct tb_port *port) in usb4_port_clx_supported() argument
1513 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_clx_supported()
1514 port->cap_usb4 + PORT_CS_18, 1); in usb4_port_clx_supported()
1522 * usb4_port_asym_supported() - If the port supports asymmetric link
1523 * @port: USB4 port
1525 * Checks if the port and the cable supports asymmetric link and returns
1528 bool usb4_port_asym_supported(struct tb_port *port) in usb4_port_asym_supported() argument
1532 if (!port->cap_usb4) in usb4_port_asym_supported()
1535 if (tb_port_read(port, &val, TB_CFG_PORT, port->cap_usb4 + PORT_CS_18, 1)) in usb4_port_asym_supported()
1542 * usb4_port_asym_set_link_width() - Set link width to asymmetric or symmetric
1543 * @port: USB4 port
1546 * Sets USB4 port link width to @width. Can be called for widths where
1549 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width) in usb4_port_asym_set_link_width() argument
1554 if (!port->cap_phy) in usb4_port_asym_set_link_width()
1555 return -EINVAL; in usb4_port_asym_set_link_width()
1557 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_asym_set_link_width()
1558 port->cap_phy + LANE_ADP_CS_1, 1); in usb4_port_asym_set_link_width()
1577 return -EINVAL; in usb4_port_asym_set_link_width()
1580 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_asym_set_link_width()
1581 port->cap_phy + LANE_ADP_CS_1, 1); in usb4_port_asym_set_link_width()
1585 * usb4_port_asym_start() - Start symmetry change and wait for completion
1586 * @port: USB4 port
1592 * Returns %0 in case of success, %-ETIMEDOUT if case of timeout or
1595 int usb4_port_asym_start(struct tb_port *port) in usb4_port_asym_start() argument
1600 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_asym_start()
1601 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_asym_start()
1606 val |= FIELD_PREP(PORT_CS_19_START_ASYM, 1); in usb4_port_asym_start()
1608 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_asym_start()
1609 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_asym_start()
1615 * port started the symmetry transition. in usb4_port_asym_start()
1617 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_19, in usb4_port_asym_start()
1624 return usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_18, in usb4_port_asym_start()
1629 * usb4_port_margining_caps() - Read USB4 port marginig capabilities
1630 * @port: USB4 port
1636 * Reads the USB4 port lane margining capabilities into @caps.
1638 int usb4_port_margining_caps(struct tb_port *port, enum usb4_sb_target target, in usb4_port_margining_caps() argument
1643 ret = usb4_port_sb_op(port, target, index, in usb4_port_margining_caps()
1648 return usb4_port_sb_read(port, target, index, USB4_SB_DATA, caps, in usb4_port_margining_caps()
1653 * usb4_port_hw_margin() - Run hardware lane margining on port
1654 * @port: USB4 port
1661 * Runs hardware lane margining on USB4 port and returns the result in
1664 int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target, in usb4_port_hw_margin() argument
1672 return -EINVAL; in usb4_port_hw_margin()
1674 val = params->lanes; in usb4_port_hw_margin()
1675 if (params->time) in usb4_port_hw_margin()
1677 if (params->right_high || params->upper_eye) in usb4_port_hw_margin()
1679 if (params->ber_level) in usb4_port_hw_margin()
1680 val |= FIELD_PREP(USB4_MARGIN_HW_BER_MASK, params->ber_level); in usb4_port_hw_margin()
1681 if (params->optional_voltage_offset_range) in usb4_port_hw_margin()
1684 ret = usb4_port_sb_write(port, target, index, USB4_SB_METADATA, &val, in usb4_port_hw_margin()
1689 ret = usb4_port_sb_op(port, target, index, in usb4_port_hw_margin()
1694 return usb4_port_sb_read(port, target, index, USB4_SB_DATA, results, in usb4_port_hw_margin()
1699 * usb4_port_sw_margin() - Run software lane margining on port
1700 * @port: USB4 port
1706 * Runs software lane margining on USB4 port. Read back the error
1710 int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sw_margin() argument
1718 return -EINVAL; in usb4_port_sw_margin()
1720 val = params->lanes; in usb4_port_sw_margin()
1721 if (params->time) in usb4_port_sw_margin()
1723 if (params->optional_voltage_offset_range) in usb4_port_sw_margin()
1725 if (params->right_high) in usb4_port_sw_margin()
1727 if (params->upper_eye) in usb4_port_sw_margin()
1729 val |= FIELD_PREP(USB4_MARGIN_SW_COUNTER_MASK, params->error_counter); in usb4_port_sw_margin()
1730 val |= FIELD_PREP(USB4_MARGIN_SW_VT_MASK, params->voltage_time_offset); in usb4_port_sw_margin()
1732 ret = usb4_port_sb_write(port, target, index, USB4_SB_METADATA, &val, in usb4_port_sw_margin()
1737 ret = usb4_port_sb_op(port, target, index, in usb4_port_sw_margin()
1742 return usb4_port_sb_read(port, target, index, USB4_SB_DATA, results, in usb4_port_sw_margin()
1748 * usb4_port_sw_margin_errors() - Read the software margining error counters
1749 * @port: USB4 port
1754 * This reads back the software margining error counters from the port.
1757 int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sw_margin_errors() argument
1762 ret = usb4_port_sb_op(port, target, index, in usb4_port_sw_margin_errors()
1767 return usb4_port_sb_read(port, target, index, USB4_SB_METADATA, errors, in usb4_port_sw_margin_errors()
1771 static inline int usb4_port_retimer_op(struct tb_port *port, u8 index, in usb4_port_retimer_op() argument
1775 return usb4_port_sb_op(port, USB4_SB_TARGET_RETIMER, index, opcode, in usb4_port_retimer_op()
1780 * usb4_port_retimer_set_inbound_sbtx() - Enable sideband channel transactions
1781 * @port: USB4 port
1787 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_set_inbound_sbtx() argument
1791 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1794 if (ret != -ENODEV) in usb4_port_retimer_set_inbound_sbtx()
1802 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1807 * usb4_port_retimer_unset_inbound_sbtx() - Disable sideband channel transactions
1808 * @port: USB4 port
1814 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_unset_inbound_sbtx() argument
1816 return usb4_port_retimer_op(port, index, in usb4_port_retimer_unset_inbound_sbtx()
1821 * usb4_port_retimer_is_last() - Is the retimer last on-board retimer
1822 * @port: USB4 port
1826 * Type-C port) this function returns %1. If it is not returns %0. If
1827 * the retimer is not present returns %-ENODEV. Otherwise returns
1830 int usb4_port_retimer_is_last(struct tb_port *port, u8 index) in usb4_port_retimer_is_last() argument
1835 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_QUERY_LAST_RETIMER, in usb4_port_retimer_is_last()
1840 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_is_last()
1842 return ret ? ret : metadata & 1; in usb4_port_retimer_is_last()
1846 * usb4_port_retimer_is_cable() - Is the retimer cable retimer
1847 * @port: USB4 port
1851 * %1 and %0 if it is on-board retimer. In case a retimer is not present
1852 * at @index returns %-ENODEV. Otherwise returns negative errno.
1854 int usb4_port_retimer_is_cable(struct tb_port *port, u8 index) in usb4_port_retimer_is_cable() argument
1859 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_QUERY_CABLE_RETIMER, in usb4_port_retimer_is_cable()
1864 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_is_cable()
1866 return ret ? ret : metadata & 1; in usb4_port_retimer_is_cable()
1870 * usb4_port_retimer_nvm_sector_size() - Read retimer NVM sector size
1871 * @port: USB4 port
1877 * in case of error. Specifically returns %-ENODEV if there is no
1880 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_sector_size() argument
1885 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_GET_NVM_SECTOR_SIZE, in usb4_port_retimer_nvm_sector_size()
1890 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_sector_size()
1896 * usb4_port_retimer_nvm_set_offset() - Set NVM write offset
1897 * @port: USB4 port
1906 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_set_offset() argument
1916 ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_set_offset()
1921 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_SET_OFFSET, in usb4_port_retimer_nvm_set_offset()
1926 struct tb_port *port; member
1935 struct tb_port *port = info->port; in usb4_port_retimer_nvm_write_next_block() local
1936 u8 index = info->index; in usb4_port_retimer_nvm_write_next_block()
1939 ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_write_next_block()
1944 return usb4_port_retimer_op(port, index, in usb4_port_retimer_nvm_write_next_block()
1949 * usb4_port_retimer_nvm_write() - Write to retimer NVM
1950 * @port: USB4 port
1958 * errno in case of failure. Specifically returns %-ENODEV if there is
1961 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index, unsigned int address, in usb4_port_retimer_nvm_write() argument
1964 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_write()
1967 ret = usb4_port_retimer_nvm_set_offset(port, index, address); in usb4_port_retimer_nvm_write()
1976 * usb4_port_retimer_nvm_authenticate() - Start retimer NVM upgrade
1977 * @port: USB4 port
1986 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_authenticate() argument
1996 return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate()
2001 * usb4_port_retimer_nvm_authenticate_status() - Read status of NVM upgrade
2002 * @port: USB4 port
2013 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_authenticate_status() argument
2019 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate_status()
2030 case -EAGAIN: in usb4_port_retimer_nvm_authenticate_status()
2031 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate_status()
2049 struct tb_port *port = info->port; in usb4_port_retimer_nvm_read_block() local
2050 u8 index = info->index; in usb4_port_retimer_nvm_read_block()
2058 ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_read_block()
2063 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_READ, 500); in usb4_port_retimer_nvm_read_block()
2067 return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_read_block()
2072 * usb4_port_retimer_nvm_read() - Read contents of retimer NVM
2073 * @port: USB4 port
2081 * Specifically returns %-ENODEV if there is no retimer at @index.
2083 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_read() argument
2086 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_read()
2093 usb4_usb3_port_max_bandwidth(const struct tb_port *port, unsigned int bw) in usb4_usb3_port_max_bandwidth() argument
2096 if (port->max_bw) in usb4_usb3_port_max_bandwidth()
2097 return min(bw, port->max_bw); in usb4_usb3_port_max_bandwidth()
2102 * usb4_usb3_port_max_link_rate() - Maximum support USB3 link rate
2103 * @port: USB3 adapter port
2108 int usb4_usb3_port_max_link_rate(struct tb_port *port) in usb4_usb3_port_max_link_rate() argument
2113 if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port)) in usb4_usb3_port_max_link_rate()
2114 return -EINVAL; in usb4_usb3_port_max_link_rate()
2116 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_max_link_rate()
2117 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_max_link_rate()
2124 return usb4_usb3_port_max_bandwidth(port, ret); in usb4_usb3_port_max_link_rate()
2127 static int usb4_usb3_port_cm_request(struct tb_port *port, bool request) in usb4_usb3_port_cm_request() argument
2132 if (!tb_port_is_usb3_down(port)) in usb4_usb3_port_cm_request()
2133 return -EINVAL; in usb4_usb3_port_cm_request()
2134 if (tb_route(port->sw)) in usb4_usb3_port_cm_request()
2135 return -EINVAL; in usb4_usb3_port_cm_request()
2137 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
2138 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2147 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
2148 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2157 return usb4_port_wait_for_bit(port, port->cap_adap + ADP_USB3_CS_1, in usb4_usb3_port_cm_request()
2162 static inline int usb4_usb3_port_set_cm_request(struct tb_port *port) in usb4_usb3_port_set_cm_request() argument
2164 return usb4_usb3_port_cm_request(port, true); in usb4_usb3_port_set_cm_request()
2167 static inline int usb4_usb3_port_clear_cm_request(struct tb_port *port) in usb4_usb3_port_clear_cm_request() argument
2169 return usb4_usb3_port_cm_request(port, false); in usb4_usb3_port_clear_cm_request()
2184 /* 1 uframe is 1/8 ms (125 us) -> 1 / 8000 s */ in mbps_to_usb3_bw()
2189 static int usb4_usb3_port_read_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_read_allocated_bandwidth() argument
2196 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2197 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_read_allocated_bandwidth()
2201 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2202 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_allocated_bandwidth()
2218 * usb4_usb3_port_allocated_bandwidth() - Bandwidth allocated for USB3
2219 * @port: USB3 adapter port
2227 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocated_bandwidth() argument
2232 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2236 ret = usb4_usb3_port_read_allocated_bandwidth(port, upstream_bw, in usb4_usb3_port_allocated_bandwidth()
2238 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2243 static int usb4_usb3_port_read_consumed_bandwidth(struct tb_port *port, in usb4_usb3_port_read_consumed_bandwidth() argument
2250 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2251 port->cap_adap + ADP_USB3_CS_1, 1); in usb4_usb3_port_read_consumed_bandwidth()
2255 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2256 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_consumed_bandwidth()
2271 static int usb4_usb3_port_write_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_write_allocated_bandwidth() argument
2288 return -EINVAL; in usb4_usb3_port_write_allocated_bandwidth()
2290 ret = tb_port_write(port, &scale, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2291 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_write_allocated_bandwidth()
2298 tb_port_dbg(port, "scaled bandwidth %u/%u, scale %u\n", ubw, dbw, scale); in usb4_usb3_port_write_allocated_bandwidth()
2300 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2301 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2309 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2310 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2314 * usb4_usb3_port_allocate_bandwidth() - Allocate bandwidth for USB3
2315 * @port: USB3 adapter port
2330 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocate_bandwidth() argument
2335 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2339 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_allocate_bandwidth()
2348 ret = usb4_usb3_port_write_allocated_bandwidth(port, allocate_up, in usb4_usb3_port_allocate_bandwidth()
2357 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2362 * usb4_usb3_port_release_bandwidth() - Release allocated USB3 bandwidth
2363 * @port: USB3 adapter port
2372 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_release_bandwidth() argument
2377 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_release_bandwidth()
2381 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_release_bandwidth()
2395 ret = usb4_usb3_port_write_allocated_bandwidth(port, consumed_up, in usb4_usb3_port_release_bandwidth()
2404 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_release_bandwidth()
2408 static bool is_usb4_dpin(const struct tb_port *port) in is_usb4_dpin() argument
2410 if (!tb_port_is_dpin(port)) in is_usb4_dpin()
2412 if (!tb_switch_is_usb4(port->sw)) in is_usb4_dpin()
2418 * usb4_dp_port_set_cm_id() - Assign CM ID to the DP IN adapter
2419 * @port: DP IN adapter
2422 * Sets CM ID for the @port. Returns %0 on success and negative errno
2423 * otherwise. Speficially returns %-EOPNOTSUPP if the @port does not
2426 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id) in usb4_dp_port_set_cm_id() argument
2431 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_id()
2432 return -EOPNOTSUPP; in usb4_dp_port_set_cm_id()
2434 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2435 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2442 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2443 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2447 * usb4_dp_port_bandwidth_mode_supported() - Is the bandwidth allocation mode
2449 * @port: DP IN adapter to check
2454 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port) in usb4_dp_port_bandwidth_mode_supported() argument
2459 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_supported()
2462 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_supported()
2463 port->cap_adap + DP_LOCAL_CAP, 1); in usb4_dp_port_bandwidth_mode_supported()
2471 * usb4_dp_port_bandwidth_mode_enabled() - Is the bandwidth allocation mode
2473 * @port: DP IN adapter to check
2478 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port) in usb4_dp_port_bandwidth_mode_enabled() argument
2483 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_enabled()
2486 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_enabled()
2487 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_bandwidth_mode_enabled()
2495 * usb4_dp_port_set_cm_bandwidth_mode_supported() - Set/clear CM support for
2497 * @port: DP IN adapter
2502 * otherwise. Specifically returns %-OPNOTSUPP if the passed in adapter
2505 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port, in usb4_dp_port_set_cm_bandwidth_mode_supported() argument
2511 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_bandwidth_mode_supported()
2512 return -EOPNOTSUPP; in usb4_dp_port_set_cm_bandwidth_mode_supported()
2514 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2515 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2524 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2525 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2529 * usb4_dp_port_group_id() - Return Group ID assigned for the adapter
2530 * @port: DP IN adapter
2534 * %-EOPNOTSUPP is returned.
2536 int usb4_dp_port_group_id(struct tb_port *port) in usb4_dp_port_group_id() argument
2541 if (!is_usb4_dpin(port)) in usb4_dp_port_group_id()
2542 return -EOPNOTSUPP; in usb4_dp_port_group_id()
2544 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_group_id()
2545 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_group_id()
2553 * usb4_dp_port_set_group_id() - Set adapter Group ID
2554 * @port: DP IN adapter
2559 * Specifically returns %-EOPNOTSUPP if the adapter does not support
2562 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id) in usb4_dp_port_set_group_id() argument
2567 if (!is_usb4_dpin(port)) in usb4_dp_port_set_group_id()
2568 return -EOPNOTSUPP; in usb4_dp_port_set_group_id()
2570 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2571 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2578 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2579 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2583 * usb4_dp_port_nrd() - Read non-reduced rate and lanes
2584 * @port: DP IN adapter
2585 * @rate: Non-reduced rate in Mb/s is placed here
2586 * @lanes: Non-reduced lanes are placed here
2588 * Reads the non-reduced rate and lanes from the DP IN adapter. Returns
2590 * %-EOPNOTSUPP if the adapter does not support this.
2592 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes) in usb4_dp_port_nrd() argument
2597 if (!is_usb4_dpin(port)) in usb4_dp_port_nrd()
2598 return -EOPNOTSUPP; in usb4_dp_port_nrd()
2600 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_nrd()
2601 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_nrd()
2624 *lanes = 1; in usb4_dp_port_nrd()
2638 * usb4_dp_port_set_nrd() - Set non-reduced rate and lanes
2639 * @port: DP IN adapter
2640 * @rate: Non-reduced rate in Mb/s
2641 * @lanes: Non-reduced lanes
2644 * the non-reduced values for the DP IN adapter. Returns %0 in success
2646 * %-EOPNOTSUPP is returned.
2648 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes) in usb4_dp_port_set_nrd() argument
2653 if (!is_usb4_dpin(port)) in usb4_dp_port_set_nrd()
2654 return -EOPNOTSUPP; in usb4_dp_port_set_nrd()
2656 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2657 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2679 return -EINVAL; in usb4_dp_port_set_nrd()
2685 case 1: in usb4_dp_port_set_nrd()
2694 return -EINVAL; in usb4_dp_port_set_nrd()
2697 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2698 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2702 * usb4_dp_port_granularity() - Return granularity for the bandwidth values
2703 * @port: DP IN adapter
2705 * Reads the programmed granularity from @port. If the DP IN adapter does
2706 * not support bandwidth allocation mode returns %-EOPNOTSUPP and negative
2709 int usb4_dp_port_granularity(struct tb_port *port) in usb4_dp_port_granularity() argument
2714 if (!is_usb4_dpin(port)) in usb4_dp_port_granularity()
2715 return -EOPNOTSUPP; in usb4_dp_port_granularity()
2717 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_granularity()
2718 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_granularity()
2734 return -EINVAL; in usb4_dp_port_granularity()
2738 * usb4_dp_port_set_granularity() - Set granularity for the bandwidth values
2739 * @port: DP IN adapter
2744 * adapter does not support this %-EOPNOTSUPP is returned.
2746 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity) in usb4_dp_port_set_granularity() argument
2751 if (!is_usb4_dpin(port)) in usb4_dp_port_set_granularity()
2752 return -EOPNOTSUPP; in usb4_dp_port_set_granularity()
2754 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2755 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2772 return -EINVAL; in usb4_dp_port_set_granularity()
2775 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2776 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2780 * usb4_dp_port_set_estimated_bandwidth() - Set estimated bandwidth
2781 * @port: DP IN adapter
2787 * and negative errno otherwise. Specifically returns %-EOPNOTSUPP if
2790 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_set_estimated_bandwidth() argument
2795 if (!is_usb4_dpin(port)) in usb4_dp_port_set_estimated_bandwidth()
2796 return -EOPNOTSUPP; in usb4_dp_port_set_estimated_bandwidth()
2798 ret = usb4_dp_port_granularity(port); in usb4_dp_port_set_estimated_bandwidth()
2803 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2804 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2811 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2812 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2816 * usb4_dp_port_allocated_bandwidth() - Return allocated bandwidth
2817 * @port: DP IN adapter
2819 * Reads and returns allocated bandwidth for @port in Mb/s (taking into
2823 int usb4_dp_port_allocated_bandwidth(struct tb_port *port) in usb4_dp_port_allocated_bandwidth() argument
2828 if (!is_usb4_dpin(port)) in usb4_dp_port_allocated_bandwidth()
2829 return -EOPNOTSUPP; in usb4_dp_port_allocated_bandwidth()
2831 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocated_bandwidth()
2836 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocated_bandwidth()
2837 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocated_bandwidth()
2847 static int __usb4_dp_port_set_cm_ack(struct tb_port *port, bool ack) in __usb4_dp_port_set_cm_ack() argument
2852 ret = tb_port_read(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2853 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2862 return tb_port_write(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2863 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2866 static inline int usb4_dp_port_set_cm_ack(struct tb_port *port) in usb4_dp_port_set_cm_ack() argument
2868 return __usb4_dp_port_set_cm_ack(port, true); in usb4_dp_port_set_cm_ack()
2871 static int usb4_dp_port_wait_and_clear_cm_ack(struct tb_port *port, in usb4_dp_port_wait_and_clear_cm_ack() argument
2878 ret = __usb4_dp_port_set_cm_ack(port, false); in usb4_dp_port_wait_and_clear_cm_ack()
2884 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2885 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2896 tb_port_warn(port, "timeout waiting for DPTX request to clear\n"); in usb4_dp_port_wait_and_clear_cm_ack()
2897 return -ETIMEDOUT; in usb4_dp_port_wait_and_clear_cm_ack()
2900 ret = tb_port_read(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()
2906 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2907 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2911 * usb4_dp_port_allocate_bandwidth() - Set allocated bandwidth
2912 * @port: DP IN adapter
2919 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_allocate_bandwidth() argument
2924 if (!is_usb4_dpin(port)) in usb4_dp_port_allocate_bandwidth()
2925 return -EOPNOTSUPP; in usb4_dp_port_allocate_bandwidth()
2927 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocate_bandwidth()
2932 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2933 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2940 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2941 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2945 ret = usb4_dp_port_set_cm_ack(port); in usb4_dp_port_allocate_bandwidth()
2949 return usb4_dp_port_wait_and_clear_cm_ack(port, 500); in usb4_dp_port_allocate_bandwidth()
2953 * usb4_dp_port_requested_bandwidth() - Read requested bandwidth
2954 * @port: DP IN adapter
2958 * error returns negative errno. Specifically returns %-EOPNOTSUPP if
2962 int usb4_dp_port_requested_bandwidth(struct tb_port *port) in usb4_dp_port_requested_bandwidth() argument
2967 if (!is_usb4_dpin(port)) in usb4_dp_port_requested_bandwidth()
2968 return -EOPNOTSUPP; in usb4_dp_port_requested_bandwidth()
2970 ret = usb4_dp_port_granularity(port); in usb4_dp_port_requested_bandwidth()
2975 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_requested_bandwidth()
2976 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_requested_bandwidth()
2981 return -ENODATA; in usb4_dp_port_requested_bandwidth()
2987 * usb4_pci_port_set_ext_encapsulation() - Enable/disable extended encapsulation
2988 * @port: PCIe adapter
2995 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable) in usb4_pci_port_set_ext_encapsulation() argument
3000 if (!tb_port_is_pcie_up(port) && !tb_port_is_pcie_down(port)) in usb4_pci_port_set_ext_encapsulation()
3001 return -EINVAL; in usb4_pci_port_set_ext_encapsulation()
3003 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
3004 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()
3013 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
3014 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()