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

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
1635 * Reads the USB4 port lane margining capabilities into @caps.
1637 int usb4_port_margining_caps(struct tb_port *port, enum usb4_sb_target target, in usb4_port_margining_caps() argument
1642 ret = usb4_port_sb_op(port, target, index, in usb4_port_margining_caps()
1647 return usb4_port_sb_read(port, target, index, USB4_SB_DATA, caps, in usb4_port_margining_caps()
1652 * usb4_port_hw_margin() - Run hardware lane margining on port
1653 * @port: USB4 port
1659 * Runs hardware lane margining on USB4 port and returns the result in
1662 int usb4_port_hw_margin(struct tb_port *port, enum usb4_sb_target target, in usb4_port_hw_margin() argument
1670 return -EINVAL; in usb4_port_hw_margin()
1672 val = params->lanes; in usb4_port_hw_margin()
1673 if (params->time) in usb4_port_hw_margin()
1675 if (params->right_high) in usb4_port_hw_margin()
1677 if (params->ber_level) in usb4_port_hw_margin()
1678 val |= FIELD_PREP(USB4_MARGIN_HW_BER_MASK, params->ber_level); in usb4_port_hw_margin()
1679 if (params->optional_voltage_offset_range) in usb4_port_hw_margin()
1682 ret = usb4_port_sb_write(port, target, index, USB4_SB_METADATA, &val, in usb4_port_hw_margin()
1687 ret = usb4_port_sb_op(port, target, index, in usb4_port_hw_margin()
1692 return usb4_port_sb_read(port, target, index, USB4_SB_DATA, results, in usb4_port_hw_margin()
1697 * usb4_port_sw_margin() - Run software lane margining on port
1698 * @port: USB4 port
1704 * Runs software lane margining on USB4 port. Read back the error
1708 int usb4_port_sw_margin(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sw_margin() argument
1716 return -EINVAL; in usb4_port_sw_margin()
1718 val = params->lanes; in usb4_port_sw_margin()
1719 if (params->time) in usb4_port_sw_margin()
1721 if (params->optional_voltage_offset_range) in usb4_port_sw_margin()
1723 if (params->right_high) in usb4_port_sw_margin()
1725 val |= FIELD_PREP(USB4_MARGIN_SW_COUNTER_MASK, params->error_counter); in usb4_port_sw_margin()
1726 val |= FIELD_PREP(USB4_MARGIN_SW_VT_MASK, params->voltage_time_offset); in usb4_port_sw_margin()
1728 ret = usb4_port_sb_write(port, target, index, USB4_SB_METADATA, &val, in usb4_port_sw_margin()
1733 ret = usb4_port_sb_op(port, target, index, in usb4_port_sw_margin()
1738 return usb4_port_sb_read(port, target, index, USB4_SB_DATA, results, in usb4_port_sw_margin()
1744 * usb4_port_sw_margin_errors() - Read the software margining error counters
1745 * @port: USB4 port
1750 * This reads back the software margining error counters from the port.
1753 int usb4_port_sw_margin_errors(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sw_margin_errors() argument
1758 ret = usb4_port_sb_op(port, target, index, in usb4_port_sw_margin_errors()
1763 return usb4_port_sb_read(port, target, index, USB4_SB_METADATA, errors, in usb4_port_sw_margin_errors()
1767 static inline int usb4_port_retimer_op(struct tb_port *port, u8 index, in usb4_port_retimer_op() argument
1771 return usb4_port_sb_op(port, USB4_SB_TARGET_RETIMER, index, opcode, in usb4_port_retimer_op()
1776 * usb4_port_retimer_set_inbound_sbtx() - Enable sideband channel transactions
1777 * @port: USB4 port
1783 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_set_inbound_sbtx() argument
1787 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1790 if (ret != -ENODEV) in usb4_port_retimer_set_inbound_sbtx()
1798 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1803 * usb4_port_retimer_unset_inbound_sbtx() - Disable sideband channel transactions
1804 * @port: USB4 port
1810 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_unset_inbound_sbtx() argument
1812 return usb4_port_retimer_op(port, index, in usb4_port_retimer_unset_inbound_sbtx()
1817 * usb4_port_retimer_is_last() - Is the retimer last on-board retimer
1818 * @port: USB4 port
1822 * Type-C port) this function returns %1. If it is not returns %0. If
1823 * the retimer is not present returns %-ENODEV. Otherwise returns
1826 int usb4_port_retimer_is_last(struct tb_port *port, u8 index) in usb4_port_retimer_is_last() argument
1831 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_QUERY_LAST_RETIMER, in usb4_port_retimer_is_last()
1836 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_is_last()
1838 return ret ? ret : metadata & 1; in usb4_port_retimer_is_last()
1842 * usb4_port_retimer_is_cable() - Is the retimer cable retimer
1843 * @port: USB4 port
1847 * %1 and %0 if it is on-board retimer. In case a retimer is not present
1848 * at @index returns %-ENODEV. Otherwise returns negative errno.
1850 int usb4_port_retimer_is_cable(struct tb_port *port, u8 index) in usb4_port_retimer_is_cable() argument
1855 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_QUERY_CABLE_RETIMER, in usb4_port_retimer_is_cable()
1860 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_is_cable()
1862 return ret ? ret : metadata & 1; in usb4_port_retimer_is_cable()
1866 * usb4_port_retimer_nvm_sector_size() - Read retimer NVM sector size
1867 * @port: USB4 port
1873 * in case of error. Specifically returns %-ENODEV if there is no
1876 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_sector_size() argument
1881 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_GET_NVM_SECTOR_SIZE, in usb4_port_retimer_nvm_sector_size()
1886 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_sector_size()
1892 * usb4_port_retimer_nvm_set_offset() - Set NVM write offset
1893 * @port: USB4 port
1902 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_set_offset() argument
1912 ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_set_offset()
1917 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_SET_OFFSET, in usb4_port_retimer_nvm_set_offset()
1922 struct tb_port *port; member
1931 struct tb_port *port = info->port; in usb4_port_retimer_nvm_write_next_block() local
1932 u8 index = info->index; in usb4_port_retimer_nvm_write_next_block()
1935 ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_write_next_block()
1940 return usb4_port_retimer_op(port, index, in usb4_port_retimer_nvm_write_next_block()
1945 * usb4_port_retimer_nvm_write() - Write to retimer NVM
1946 * @port: USB4 port
1954 * errno in case of failure. Specifically returns %-ENODEV if there is
1957 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index, unsigned int address, in usb4_port_retimer_nvm_write() argument
1960 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_write()
1963 ret = usb4_port_retimer_nvm_set_offset(port, index, address); in usb4_port_retimer_nvm_write()
1972 * usb4_port_retimer_nvm_authenticate() - Start retimer NVM upgrade
1973 * @port: USB4 port
1982 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_authenticate() argument
1992 return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate()
1997 * usb4_port_retimer_nvm_authenticate_status() - Read status of NVM upgrade
1998 * @port: USB4 port
2009 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_authenticate_status() argument
2015 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate_status()
2026 case -EAGAIN: in usb4_port_retimer_nvm_authenticate_status()
2027 ret = usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate_status()
2045 struct tb_port *port = info->port; in usb4_port_retimer_nvm_read_block() local
2046 u8 index = info->index; in usb4_port_retimer_nvm_read_block()
2054 ret = usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_read_block()
2059 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_READ, 500); in usb4_port_retimer_nvm_read_block()
2063 return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_read_block()
2068 * usb4_port_retimer_nvm_read() - Read contents of retimer NVM
2069 * @port: USB4 port
2077 * Specifically returns %-ENODEV if there is no retimer at @index.
2079 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_read() argument
2082 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_read()
2089 usb4_usb3_port_max_bandwidth(const struct tb_port *port, unsigned int bw) in usb4_usb3_port_max_bandwidth() argument
2092 if (port->max_bw) in usb4_usb3_port_max_bandwidth()
2093 return min(bw, port->max_bw); in usb4_usb3_port_max_bandwidth()
2098 * usb4_usb3_port_max_link_rate() - Maximum support USB3 link rate
2099 * @port: USB3 adapter port
2104 int usb4_usb3_port_max_link_rate(struct tb_port *port) in usb4_usb3_port_max_link_rate() argument
2109 if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port)) in usb4_usb3_port_max_link_rate()
2110 return -EINVAL; in usb4_usb3_port_max_link_rate()
2112 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_max_link_rate()
2113 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_max_link_rate()
2120 return usb4_usb3_port_max_bandwidth(port, ret); in usb4_usb3_port_max_link_rate()
2123 static int usb4_usb3_port_cm_request(struct tb_port *port, bool request) in usb4_usb3_port_cm_request() argument
2128 if (!tb_port_is_usb3_down(port)) in usb4_usb3_port_cm_request()
2129 return -EINVAL; in usb4_usb3_port_cm_request()
2130 if (tb_route(port->sw)) in usb4_usb3_port_cm_request()
2131 return -EINVAL; in usb4_usb3_port_cm_request()
2133 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
2134 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2143 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
2144 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2153 return usb4_port_wait_for_bit(port, port->cap_adap + ADP_USB3_CS_1, in usb4_usb3_port_cm_request()
2158 static inline int usb4_usb3_port_set_cm_request(struct tb_port *port) in usb4_usb3_port_set_cm_request() argument
2160 return usb4_usb3_port_cm_request(port, true); in usb4_usb3_port_set_cm_request()
2163 static inline int usb4_usb3_port_clear_cm_request(struct tb_port *port) in usb4_usb3_port_clear_cm_request() argument
2165 return usb4_usb3_port_cm_request(port, false); in usb4_usb3_port_clear_cm_request()
2180 /* 1 uframe is 1/8 ms (125 us) -> 1 / 8000 s */ in mbps_to_usb3_bw()
2185 static int usb4_usb3_port_read_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_read_allocated_bandwidth() argument
2192 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2193 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_read_allocated_bandwidth()
2197 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2198 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_allocated_bandwidth()
2214 * usb4_usb3_port_allocated_bandwidth() - Bandwidth allocated for USB3
2215 * @port: USB3 adapter port
2223 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocated_bandwidth() argument
2228 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2232 ret = usb4_usb3_port_read_allocated_bandwidth(port, upstream_bw, in usb4_usb3_port_allocated_bandwidth()
2234 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2239 static int usb4_usb3_port_read_consumed_bandwidth(struct tb_port *port, in usb4_usb3_port_read_consumed_bandwidth() argument
2246 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2247 port->cap_adap + ADP_USB3_CS_1, 1); in usb4_usb3_port_read_consumed_bandwidth()
2251 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2252 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_consumed_bandwidth()
2267 static int usb4_usb3_port_write_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_write_allocated_bandwidth() argument
2284 return -EINVAL; in usb4_usb3_port_write_allocated_bandwidth()
2286 ret = tb_port_write(port, &scale, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2287 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_write_allocated_bandwidth()
2294 tb_port_dbg(port, "scaled bandwidth %u/%u, scale %u\n", ubw, dbw, scale); in usb4_usb3_port_write_allocated_bandwidth()
2296 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2297 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2305 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2306 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2310 * usb4_usb3_port_allocate_bandwidth() - Allocate bandwidth for USB3
2311 * @port: USB3 adapter port
2326 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocate_bandwidth() argument
2331 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2335 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_allocate_bandwidth()
2344 ret = usb4_usb3_port_write_allocated_bandwidth(port, allocate_up, in usb4_usb3_port_allocate_bandwidth()
2353 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2358 * usb4_usb3_port_release_bandwidth() - Release allocated USB3 bandwidth
2359 * @port: USB3 adapter port
2368 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_release_bandwidth() argument
2373 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_release_bandwidth()
2377 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_release_bandwidth()
2391 ret = usb4_usb3_port_write_allocated_bandwidth(port, consumed_up, in usb4_usb3_port_release_bandwidth()
2400 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_release_bandwidth()
2404 static bool is_usb4_dpin(const struct tb_port *port) in is_usb4_dpin() argument
2406 if (!tb_port_is_dpin(port)) in is_usb4_dpin()
2408 if (!tb_switch_is_usb4(port->sw)) in is_usb4_dpin()
2414 * usb4_dp_port_set_cm_id() - Assign CM ID to the DP IN adapter
2415 * @port: DP IN adapter
2418 * Sets CM ID for the @port. Returns %0 on success and negative errno
2419 * otherwise. Speficially returns %-EOPNOTSUPP if the @port does not
2422 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id) in usb4_dp_port_set_cm_id() argument
2427 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_id()
2428 return -EOPNOTSUPP; in usb4_dp_port_set_cm_id()
2430 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2431 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2438 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2439 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2443 * usb4_dp_port_bandwidth_mode_supported() - Is the bandwidth allocation mode
2445 * @port: DP IN adapter to check
2450 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port) in usb4_dp_port_bandwidth_mode_supported() argument
2455 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_supported()
2458 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_supported()
2459 port->cap_adap + DP_LOCAL_CAP, 1); in usb4_dp_port_bandwidth_mode_supported()
2467 * usb4_dp_port_bandwidth_mode_enabled() - Is the bandwidth allocation mode
2469 * @port: DP IN adapter to check
2474 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port) in usb4_dp_port_bandwidth_mode_enabled() argument
2479 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_enabled()
2482 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_enabled()
2483 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_bandwidth_mode_enabled()
2491 * usb4_dp_port_set_cm_bandwidth_mode_supported() - Set/clear CM support for
2493 * @port: DP IN adapter
2498 * otherwise. Specifically returns %-OPNOTSUPP if the passed in adapter
2501 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port, in usb4_dp_port_set_cm_bandwidth_mode_supported() argument
2507 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_bandwidth_mode_supported()
2508 return -EOPNOTSUPP; in usb4_dp_port_set_cm_bandwidth_mode_supported()
2510 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2511 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2520 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2521 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2525 * usb4_dp_port_group_id() - Return Group ID assigned for the adapter
2526 * @port: DP IN adapter
2530 * %-EOPNOTSUPP is returned.
2532 int usb4_dp_port_group_id(struct tb_port *port) in usb4_dp_port_group_id() argument
2537 if (!is_usb4_dpin(port)) in usb4_dp_port_group_id()
2538 return -EOPNOTSUPP; in usb4_dp_port_group_id()
2540 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_group_id()
2541 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_group_id()
2549 * usb4_dp_port_set_group_id() - Set adapter Group ID
2550 * @port: DP IN adapter
2555 * Specifically returns %-EOPNOTSUPP if the adapter does not support
2558 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id) in usb4_dp_port_set_group_id() argument
2563 if (!is_usb4_dpin(port)) in usb4_dp_port_set_group_id()
2564 return -EOPNOTSUPP; in usb4_dp_port_set_group_id()
2566 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2567 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2574 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2575 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2579 * usb4_dp_port_nrd() - Read non-reduced rate and lanes
2580 * @port: DP IN adapter
2581 * @rate: Non-reduced rate in Mb/s is placed here
2582 * @lanes: Non-reduced lanes are placed here
2584 * Reads the non-reduced rate and lanes from the DP IN adapter. Returns
2586 * %-EOPNOTSUPP if the adapter does not support this.
2588 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes) in usb4_dp_port_nrd() argument
2593 if (!is_usb4_dpin(port)) in usb4_dp_port_nrd()
2594 return -EOPNOTSUPP; in usb4_dp_port_nrd()
2596 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_nrd()
2597 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_nrd()
2620 *lanes = 1; in usb4_dp_port_nrd()
2634 * usb4_dp_port_set_nrd() - Set non-reduced rate and lanes
2635 * @port: DP IN adapter
2636 * @rate: Non-reduced rate in Mb/s
2637 * @lanes: Non-reduced lanes
2640 * the non-reduced values for the DP IN adapter. Returns %0 in success
2642 * %-EOPNOTSUPP is returned.
2644 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes) in usb4_dp_port_set_nrd() argument
2649 if (!is_usb4_dpin(port)) in usb4_dp_port_set_nrd()
2650 return -EOPNOTSUPP; in usb4_dp_port_set_nrd()
2652 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2653 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2675 return -EINVAL; in usb4_dp_port_set_nrd()
2681 case 1: in usb4_dp_port_set_nrd()
2690 return -EINVAL; in usb4_dp_port_set_nrd()
2693 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2694 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2698 * usb4_dp_port_granularity() - Return granularity for the bandwidth values
2699 * @port: DP IN adapter
2701 * Reads the programmed granularity from @port. If the DP IN adapter does
2702 * not support bandwidth allocation mode returns %-EOPNOTSUPP and negative
2705 int usb4_dp_port_granularity(struct tb_port *port) in usb4_dp_port_granularity() argument
2710 if (!is_usb4_dpin(port)) in usb4_dp_port_granularity()
2711 return -EOPNOTSUPP; in usb4_dp_port_granularity()
2713 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_granularity()
2714 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_granularity()
2730 return -EINVAL; in usb4_dp_port_granularity()
2734 * usb4_dp_port_set_granularity() - Set granularity for the bandwidth values
2735 * @port: DP IN adapter
2740 * adapter does not support this %-EOPNOTSUPP is returned.
2742 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity) in usb4_dp_port_set_granularity() argument
2747 if (!is_usb4_dpin(port)) in usb4_dp_port_set_granularity()
2748 return -EOPNOTSUPP; in usb4_dp_port_set_granularity()
2750 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2751 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2768 return -EINVAL; in usb4_dp_port_set_granularity()
2771 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2772 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2776 * usb4_dp_port_set_estimated_bandwidth() - Set estimated bandwidth
2777 * @port: DP IN adapter
2783 * and negative errno otherwise. Specifically returns %-EOPNOTSUPP if
2786 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_set_estimated_bandwidth() argument
2791 if (!is_usb4_dpin(port)) in usb4_dp_port_set_estimated_bandwidth()
2792 return -EOPNOTSUPP; in usb4_dp_port_set_estimated_bandwidth()
2794 ret = usb4_dp_port_granularity(port); in usb4_dp_port_set_estimated_bandwidth()
2799 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2800 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2807 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2808 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2812 * usb4_dp_port_allocated_bandwidth() - Return allocated bandwidth
2813 * @port: DP IN adapter
2815 * Reads and returns allocated bandwidth for @port in Mb/s (taking into
2819 int usb4_dp_port_allocated_bandwidth(struct tb_port *port) in usb4_dp_port_allocated_bandwidth() argument
2824 if (!is_usb4_dpin(port)) in usb4_dp_port_allocated_bandwidth()
2825 return -EOPNOTSUPP; in usb4_dp_port_allocated_bandwidth()
2827 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocated_bandwidth()
2832 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocated_bandwidth()
2833 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocated_bandwidth()
2843 static int __usb4_dp_port_set_cm_ack(struct tb_port *port, bool ack) in __usb4_dp_port_set_cm_ack() argument
2848 ret = tb_port_read(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2849 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2858 return tb_port_write(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2859 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2862 static inline int usb4_dp_port_set_cm_ack(struct tb_port *port) in usb4_dp_port_set_cm_ack() argument
2864 return __usb4_dp_port_set_cm_ack(port, true); in usb4_dp_port_set_cm_ack()
2867 static int usb4_dp_port_wait_and_clear_cm_ack(struct tb_port *port, in usb4_dp_port_wait_and_clear_cm_ack() argument
2874 ret = __usb4_dp_port_set_cm_ack(port, false); in usb4_dp_port_wait_and_clear_cm_ack()
2880 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2881 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2892 tb_port_warn(port, "timeout waiting for DPTX request to clear\n"); in usb4_dp_port_wait_and_clear_cm_ack()
2893 return -ETIMEDOUT; in usb4_dp_port_wait_and_clear_cm_ack()
2896 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2897 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2902 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2903 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2907 * usb4_dp_port_allocate_bandwidth() - Set allocated bandwidth
2908 * @port: DP IN adapter
2915 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_allocate_bandwidth() argument
2920 if (!is_usb4_dpin(port)) in usb4_dp_port_allocate_bandwidth()
2921 return -EOPNOTSUPP; in usb4_dp_port_allocate_bandwidth()
2923 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocate_bandwidth()
2928 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2929 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2936 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2937 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2941 ret = usb4_dp_port_set_cm_ack(port); in usb4_dp_port_allocate_bandwidth()
2945 return usb4_dp_port_wait_and_clear_cm_ack(port, 500); in usb4_dp_port_allocate_bandwidth()
2949 * usb4_dp_port_requested_bandwidth() - Read requested bandwidth
2950 * @port: DP IN adapter
2954 * error returns negative errno. Specifically returns %-EOPNOTSUPP if
2958 int usb4_dp_port_requested_bandwidth(struct tb_port *port) in usb4_dp_port_requested_bandwidth() argument
2963 if (!is_usb4_dpin(port)) in usb4_dp_port_requested_bandwidth()
2964 return -EOPNOTSUPP; in usb4_dp_port_requested_bandwidth()
2966 ret = usb4_dp_port_granularity(port); in usb4_dp_port_requested_bandwidth()
2971 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_requested_bandwidth()
2972 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_requested_bandwidth()
2977 return -ENODATA; in usb4_dp_port_requested_bandwidth()
2983 * usb4_pci_port_set_ext_encapsulation() - Enable/disable extended encapsulation
2984 * @port: PCIe adapter
2991 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable) in usb4_pci_port_set_ext_encapsulation() argument
2996 if (!tb_port_is_pcie_up(port) && !tb_port_is_pcie_down(port)) in usb4_pci_port_set_ext_encapsulation()
2997 return -EINVAL; in usb4_pci_port_set_ext_encapsulation()
2999 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
3000 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()
3009 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
3010 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()