• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0
64 ret = tb_sw_write(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1); in usb4_native_switch_op()
76 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_native_switch_op()
84 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_native_switch_op()
89 return -EOPNOTSUPP; in usb4_native_switch_op()
96 ret = tb_sw_read(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1); in usb4_native_switch_op()
114 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in __usb4_switch_op()
117 return -EINVAL; in __usb4_switch_op()
124 if (cm_ops->usb4_switch_op) { in __usb4_switch_op()
127 ret = cm_ops->usb4_switch_op(sw, opcode, metadata, status, in __usb4_switch_op()
130 if (ret != -EOPNOTSUPP) in __usb4_switch_op()
159 * usb4_switch_check_wakes() - Check for wakes and notify PM core about them
168 struct tb_port *port; in usb4_switch_check_wakes() local
173 if (tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1)) in usb4_switch_check_wakes()
187 tb_switch_for_each_port(sw, port) { in usb4_switch_check_wakes()
188 if (!port->cap_usb4) in usb4_switch_check_wakes()
191 if (tb_port_read(port, &val, TB_CFG_PORT, in usb4_switch_check_wakes()
192 port->cap_usb4 + PORT_CS_18, 1)) in usb4_switch_check_wakes()
195 tb_port_dbg(port, "USB4 wake: %s, connection wake: %s, disconnection wake: %s\n", in usb4_switch_check_wakes()
203 usb4 = port->usb4; in usb4_switch_check_wakes()
204 if (device_may_wakeup(&usb4->dev) && wakeup_usb4) in usb4_switch_check_wakes()
205 pm_wakeup_event(&usb4->dev, 0); in usb4_switch_check_wakes()
211 pm_wakeup_event(&sw->dev, 0); in usb4_switch_check_wakes()
214 static bool link_is_usb4(struct tb_port *port) in link_is_usb4() argument
218 if (!port->cap_usb4) in link_is_usb4()
221 if (tb_port_read(port, &val, TB_CFG_PORT, in link_is_usb4()
222 port->cap_usb4 + PORT_CS_18, 1)) in link_is_usb4()
229 * usb4_switch_setup() - Additional setup for USB4 device
253 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1); in usb4_switch_setup()
258 sw->link_usb4 = link_is_usb4(down); in usb4_switch_setup()
259 tb_sw_dbg(sw, "link: %s\n", sw->link_usb4 ? "USB4" : "TBT"); in usb4_switch_setup()
267 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_setup()
271 if (tb_acpi_may_tunnel_usb3() && sw->link_usb4 && in usb4_switch_setup()
296 return tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_setup()
300 * usb4_switch_configuration_valid() - Set tunneling configuration to be valid
318 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_configuration_valid()
324 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_configuration_valid()
333 * usb4_switch_read_uid() - Read UID from USB4 router
337 * Reads 64-bit UID from USB4 router config space.
362 return status ? -EIO : 0; in usb4_switch_drom_read_block()
366 * usb4_switch_drom_read() - Read arbitrary bytes from USB4 router DROM
373 * should always work but for hosts it may return %-EOPNOTSUPP in which
384 * usb4_switch_lane_bonding_possible() - Are conditions met for lane bonding
397 ret = tb_port_read(up, &val, TB_CFG_PORT, up->cap_usb4 + PORT_CS_18, 1); in usb4_switch_lane_bonding_possible()
405 * usb4_switch_set_wake() - Enabled/disable wake
414 struct tb_port *port; in usb4_switch_set_wake() local
422 * upstream USB4 port. in usb4_switch_set_wake()
424 tb_switch_for_each_port(sw, port) { in usb4_switch_set_wake()
425 if (!tb_port_is_null(port)) in usb4_switch_set_wake()
427 if (!route && tb_is_upstream_port(port)) in usb4_switch_set_wake()
429 if (!port->cap_usb4) in usb4_switch_set_wake()
432 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_switch_set_wake()
433 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
439 if (tb_is_upstream_port(port)) { in usb4_switch_set_wake()
443 bool wakeup = runtime || device_may_wakeup(&port->usb4->dev); 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()
1286 static int usb4_port_sb_read(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_read() argument
1293 if (!port->cap_usb4) in usb4_port_sb_read()
1294 return -EINVAL; in usb4_port_sb_read()
1303 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_sb_read()
1304 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1308 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_read()
1313 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_sb_read()
1314 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1319 return -ENODEV; in usb4_port_sb_read()
1321 return -EIO; in usb4_port_sb_read()
1323 return buf ? usb4_port_read_data(port, buf, dwords) : 0; in usb4_port_sb_read()
1326 static int usb4_port_sb_write(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_write() argument
1333 if (!port->cap_usb4) in usb4_port_sb_write()
1334 return -EINVAL; in usb4_port_sb_write()
1337 ret = usb4_port_write_data(port, buf, dwords); in usb4_port_sb_write()
1350 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_sb_write()
1351 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1355 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_write()
1360 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_sb_write()
1361 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1366 return -ENODEV; in usb4_port_sb_write()
1368 return -EIO; in usb4_port_sb_write()
1379 return -EAGAIN; in usb4_port_sb_opcode_err_to_errno()
1381 return -EOPNOTSUPP; in usb4_port_sb_opcode_err_to_errno()
1383 return -EIO; in usb4_port_sb_opcode_err_to_errno()
1387 static int usb4_port_sb_op(struct tb_port *port, enum usb4_sb_target target, in usb4_port_sb_op() argument
1395 ret = usb4_port_sb_write(port, target, index, USB4_SB_OPCODE, &val, in usb4_port_sb_op()
1404 ret = usb4_port_sb_read(port, target, index, USB4_SB_OPCODE, in usb4_port_sb_op()
1413 return -ETIMEDOUT; in usb4_port_sb_op()
1416 static int usb4_port_set_router_offline(struct tb_port *port, bool offline) in usb4_port_set_router_offline() argument
1421 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_set_router_offline()
1427 return usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_set_router_offline()
1432 * usb4_port_router_offline() - Put the USB4 port to offline mode
1433 * @port: USB4 port
1435 * This function puts the USB4 port into offline mode. In this mode the
1436 * port does not react on hotplug events anymore. This needs to be
1442 int usb4_port_router_offline(struct tb_port *port) in usb4_port_router_offline() argument
1444 return usb4_port_set_router_offline(port, true); in usb4_port_router_offline()
1448 * usb4_port_router_online() - Put the USB4 port back to online
1449 * @port: USB4 port
1451 * Makes the USB4 port functional again.
1453 int usb4_port_router_online(struct tb_port *port) in usb4_port_router_online() argument
1455 return usb4_port_set_router_offline(port, false); in usb4_port_router_online()
1459 * usb4_port_enumerate_retimers() - Send RT broadcast transaction
1460 * @port: USB4 port
1462 * This forces the USB4 port to send broadcast RT transaction which
1466 int usb4_port_enumerate_retimers(struct tb_port *port) in usb4_port_enumerate_retimers() argument
1471 return usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_enumerate_retimers()
1476 * usb4_port_clx_supported() - Check if CLx is supported by the link
1477 * @port: Port to check for CLx support for
1482 bool usb4_port_clx_supported(struct tb_port *port) in usb4_port_clx_supported() argument
1487 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_clx_supported()
1488 port->cap_usb4 + PORT_CS_18, 1); in usb4_port_clx_supported()
1496 * usb4_port_asym_supported() - If the port supports asymmetric link
1497 * @port: USB4 port
1499 * Checks if the port and the cable supports asymmetric link and returns
1502 bool usb4_port_asym_supported(struct tb_port *port) in usb4_port_asym_supported() argument
1506 if (!port->cap_usb4) in usb4_port_asym_supported()
1509 if (tb_port_read(port, &val, TB_CFG_PORT, port->cap_usb4 + PORT_CS_18, 1)) in usb4_port_asym_supported()
1516 * usb4_port_asym_set_link_width() - Set link width to asymmetric or symmetric
1517 * @port: USB4 port
1520 * Sets USB4 port link width to @width. Can be called for widths where
1523 int usb4_port_asym_set_link_width(struct tb_port *port, enum tb_link_width width) in usb4_port_asym_set_link_width() argument
1528 if (!port->cap_phy) in usb4_port_asym_set_link_width()
1529 return -EINVAL; in usb4_port_asym_set_link_width()
1531 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_asym_set_link_width()
1532 port->cap_phy + LANE_ADP_CS_1, 1); in usb4_port_asym_set_link_width()
1551 return -EINVAL; in usb4_port_asym_set_link_width()
1554 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_asym_set_link_width()
1555 port->cap_phy + LANE_ADP_CS_1, 1); in usb4_port_asym_set_link_width()
1559 * usb4_port_asym_start() - Start symmetry change and wait for completion
1560 * @port: USB4 port
1566 * Returns %0 in case of success, %-ETIMEDOUT if case of timeout or
1569 int usb4_port_asym_start(struct tb_port *port) in usb4_port_asym_start() argument
1574 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_port_asym_start()
1575 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_asym_start()
1580 val |= FIELD_PREP(PORT_CS_19_START_ASYM, 1); in usb4_port_asym_start()
1582 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_port_asym_start()
1583 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_asym_start()
1589 * port started the symmetry transition. in usb4_port_asym_start()
1591 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_19, in usb4_port_asym_start()
1597 return usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_18, in usb4_port_asym_start()
1602 * usb4_port_margining_caps() - Read USB4 port marginig capabilities
1603 * @port: USB4 port
1606 * Reads the USB4 port lane margining capabilities into @caps.
1608 int usb4_port_margining_caps(struct tb_port *port, u32 *caps) in usb4_port_margining_caps() argument
1612 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_margining_caps()
1617 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_margining_caps()
1622 * usb4_port_hw_margin() - Run hardware lane margining on port
1623 * @port: USB4 port
1624 * @lanes: Which lanes to run (must match the port capabilities). Can be
1625 * %0, %1 or %7.
1631 * Runs hardware lane margining on USB4 port and returns the result in
1634 int usb4_port_hw_margin(struct tb_port *port, unsigned int lanes, in usb4_port_hw_margin() argument
1650 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1655 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1660 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_hw_margin()
1665 * usb4_port_sw_margin() - Run software lane margining on port
1666 * @port: USB4 port
1667 * @lanes: Which lanes to run (must match the port capabilities). Can be
1668 * %0, %1 or %7.
1673 * Runs software lane margining on USB4 port. Read back the error
1677 int usb4_port_sw_margin(struct tb_port *port, unsigned int lanes, bool timing, in usb4_port_sw_margin() argument
1691 ret = usb4_port_sb_write(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin()
1696 return usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin()
1701 * usb4_port_sw_margin_errors() - Read the software margining error counters
1702 * @port: USB4 port
1705 * This reads back the software margining error counters from the port.
1708 int usb4_port_sw_margin_errors(struct tb_port *port, u32 *errors) in usb4_port_sw_margin_errors() argument
1712 ret = usb4_port_sb_op(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin_errors()
1717 return usb4_port_sb_read(port, USB4_SB_TARGET_ROUTER, 0, in usb4_port_sw_margin_errors()
1721 static inline int usb4_port_retimer_op(struct tb_port *port, u8 index, in usb4_port_retimer_op() argument
1725 return usb4_port_sb_op(port, USB4_SB_TARGET_RETIMER, index, opcode, in usb4_port_retimer_op()
1730 * usb4_port_retimer_set_inbound_sbtx() - Enable sideband channel transactions
1731 * @port: USB4 port
1737 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_set_inbound_sbtx() argument
1741 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1744 if (ret != -ENODEV) in usb4_port_retimer_set_inbound_sbtx()
1752 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_SET_INBOUND_SBTX, in usb4_port_retimer_set_inbound_sbtx()
1757 * usb4_port_retimer_unset_inbound_sbtx() - Disable sideband channel transactions
1758 * @port: USB4 port
1764 int usb4_port_retimer_unset_inbound_sbtx(struct tb_port *port, u8 index) in usb4_port_retimer_unset_inbound_sbtx() argument
1766 return usb4_port_retimer_op(port, index, in usb4_port_retimer_unset_inbound_sbtx()
1771 * usb4_port_retimer_read() - Read from retimer sideband registers
1772 * @port: USB4 port
1779 * retimer is connected to @port at @index. Returns %0 in case of
1781 * present at given @index returns %-ENODEV. In any other failure
1784 int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf, in usb4_port_retimer_read() argument
1787 return usb4_port_sb_read(port, USB4_SB_TARGET_RETIMER, index, reg, buf, in usb4_port_retimer_read()
1792 * usb4_port_retimer_write() - Write to retimer sideband registers
1793 * @port: USB4 port
1800 * connected to @port at @index. Returns %0 in case of success. If there
1801 * is no retimer present at given @index returns %-ENODEV. In any other
1804 int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg, in usb4_port_retimer_write() argument
1807 return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, reg, buf, in usb4_port_retimer_write()
1812 * usb4_port_retimer_is_last() - Is the retimer last on-board retimer
1813 * @port: USB4 port
1817 * Type-C port) this function returns %1. If it is not returns %0. If
1818 * the retimer is not present returns %-ENODEV. Otherwise returns
1821 int usb4_port_retimer_is_last(struct tb_port *port, u8 index) in usb4_port_retimer_is_last() argument
1826 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_QUERY_LAST_RETIMER, in usb4_port_retimer_is_last()
1831 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_is_last()
1833 return ret ? ret : metadata & 1; in usb4_port_retimer_is_last()
1837 * usb4_port_retimer_nvm_sector_size() - Read retimer NVM sector size
1838 * @port: USB4 port
1844 * in case of error. Specifically returns %-ENODEV if there is no
1847 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_sector_size() argument
1852 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_GET_NVM_SECTOR_SIZE, in usb4_port_retimer_nvm_sector_size()
1857 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_sector_size()
1863 * usb4_port_retimer_nvm_set_offset() - Set NVM write offset
1864 * @port: USB4 port
1873 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_set_offset() argument
1883 ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_set_offset()
1888 return usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_SET_OFFSET, in usb4_port_retimer_nvm_set_offset()
1893 struct tb_port *port; member
1902 struct tb_port *port = info->port; in usb4_port_retimer_nvm_write_next_block() local
1903 u8 index = info->index; in usb4_port_retimer_nvm_write_next_block()
1906 ret = usb4_port_retimer_write(port, index, USB4_SB_DATA, in usb4_port_retimer_nvm_write_next_block()
1911 return usb4_port_retimer_op(port, index, in usb4_port_retimer_nvm_write_next_block()
1916 * usb4_port_retimer_nvm_write() - Write to retimer NVM
1917 * @port: USB4 port
1925 * errno in case of failure. Specifically returns %-ENODEV if there is
1928 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index, unsigned int address, in usb4_port_retimer_nvm_write() argument
1931 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_write()
1934 ret = usb4_port_retimer_nvm_set_offset(port, index, address); in usb4_port_retimer_nvm_write()
1943 * usb4_port_retimer_nvm_authenticate() - Start retimer NVM upgrade
1944 * @port: USB4 port
1953 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index) in usb4_port_retimer_nvm_authenticate() argument
1963 return usb4_port_sb_write(port, USB4_SB_TARGET_RETIMER, index, in usb4_port_retimer_nvm_authenticate()
1968 * usb4_port_retimer_nvm_authenticate_status() - Read status of NVM upgrade
1969 * @port: USB4 port
1980 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_authenticate_status() argument
1986 ret = usb4_port_retimer_read(port, index, USB4_SB_OPCODE, &val, in usb4_port_retimer_nvm_authenticate_status()
1997 case -EAGAIN: in usb4_port_retimer_nvm_authenticate_status()
1998 ret = usb4_port_retimer_read(port, index, USB4_SB_METADATA, in usb4_port_retimer_nvm_authenticate_status()
2015 struct tb_port *port = info->port; in usb4_port_retimer_nvm_read_block() local
2016 u8 index = info->index; in usb4_port_retimer_nvm_read_block()
2024 ret = usb4_port_retimer_write(port, index, USB4_SB_METADATA, &metadata, in usb4_port_retimer_nvm_read_block()
2029 ret = usb4_port_retimer_op(port, index, USB4_SB_OPCODE_NVM_READ, 500); in usb4_port_retimer_nvm_read_block()
2033 return usb4_port_retimer_read(port, index, USB4_SB_DATA, buf, in usb4_port_retimer_nvm_read_block()
2038 * usb4_port_retimer_nvm_read() - Read contents of retimer NVM
2039 * @port: USB4 port
2047 * Specifically returns %-ENODEV if there is no retimer at @index.
2049 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index, in usb4_port_retimer_nvm_read() argument
2052 struct retimer_info info = { .port = port, .index = index }; in usb4_port_retimer_nvm_read()
2059 usb4_usb3_port_max_bandwidth(const struct tb_port *port, unsigned int bw) in usb4_usb3_port_max_bandwidth() argument
2062 if (port->max_bw) in usb4_usb3_port_max_bandwidth()
2063 return min(bw, port->max_bw); in usb4_usb3_port_max_bandwidth()
2068 * usb4_usb3_port_max_link_rate() - Maximum support USB3 link rate
2069 * @port: USB3 adapter port
2074 int usb4_usb3_port_max_link_rate(struct tb_port *port) in usb4_usb3_port_max_link_rate() argument
2079 if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port)) in usb4_usb3_port_max_link_rate()
2080 return -EINVAL; in usb4_usb3_port_max_link_rate()
2082 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_max_link_rate()
2083 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_max_link_rate()
2090 return usb4_usb3_port_max_bandwidth(port, ret); in usb4_usb3_port_max_link_rate()
2094 * usb4_usb3_port_actual_link_rate() - Established USB3 link rate
2095 * @port: USB3 adapter port
2100 int usb4_usb3_port_actual_link_rate(struct tb_port *port) in usb4_usb3_port_actual_link_rate() argument
2105 if (!tb_port_is_usb3_down(port) && !tb_port_is_usb3_up(port)) in usb4_usb3_port_actual_link_rate()
2106 return -EINVAL; in usb4_usb3_port_actual_link_rate()
2108 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_actual_link_rate()
2109 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_actual_link_rate()
2119 return usb4_usb3_port_max_bandwidth(port, ret); in usb4_usb3_port_actual_link_rate()
2122 static int usb4_usb3_port_cm_request(struct tb_port *port, bool request) in usb4_usb3_port_cm_request() argument
2127 if (!tb_port_is_usb3_down(port)) in usb4_usb3_port_cm_request()
2128 return -EINVAL; in usb4_usb3_port_cm_request()
2129 if (tb_route(port->sw)) in usb4_usb3_port_cm_request()
2130 return -EINVAL; in usb4_usb3_port_cm_request()
2132 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
2133 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2142 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_cm_request()
2143 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2152 return usb4_port_wait_for_bit(port, port->cap_adap + ADP_USB3_CS_1, in usb4_usb3_port_cm_request()
2156 static inline int usb4_usb3_port_set_cm_request(struct tb_port *port) in usb4_usb3_port_set_cm_request() argument
2158 return usb4_usb3_port_cm_request(port, true); in usb4_usb3_port_set_cm_request()
2161 static inline int usb4_usb3_port_clear_cm_request(struct tb_port *port) in usb4_usb3_port_clear_cm_request() argument
2163 return usb4_usb3_port_cm_request(port, false); in usb4_usb3_port_clear_cm_request()
2178 /* 1 uframe is 1/8 ms (125 us) -> 1 / 8000 s */ in mbps_to_usb3_bw()
2183 static int usb4_usb3_port_read_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_read_allocated_bandwidth() argument
2190 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2191 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_read_allocated_bandwidth()
2195 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_allocated_bandwidth()
2196 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_allocated_bandwidth()
2212 * usb4_usb3_port_allocated_bandwidth() - Bandwidth allocated for USB3
2213 * @port: USB3 adapter port
2221 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocated_bandwidth() argument
2226 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2230 ret = usb4_usb3_port_read_allocated_bandwidth(port, upstream_bw, in usb4_usb3_port_allocated_bandwidth()
2232 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocated_bandwidth()
2237 static int usb4_usb3_port_read_consumed_bandwidth(struct tb_port *port, in usb4_usb3_port_read_consumed_bandwidth() argument
2244 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2245 port->cap_adap + ADP_USB3_CS_1, 1); in usb4_usb3_port_read_consumed_bandwidth()
2249 ret = tb_port_read(port, &scale, TB_CFG_PORT, in usb4_usb3_port_read_consumed_bandwidth()
2250 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_consumed_bandwidth()
2265 static int usb4_usb3_port_write_allocated_bandwidth(struct tb_port *port, in usb4_usb3_port_write_allocated_bandwidth() argument
2282 return -EINVAL; in usb4_usb3_port_write_allocated_bandwidth()
2284 ret = tb_port_write(port, &scale, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2285 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_write_allocated_bandwidth()
2292 tb_port_dbg(port, "scaled bandwidth %u/%u, scale %u\n", ubw, dbw, scale); in usb4_usb3_port_write_allocated_bandwidth()
2294 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2295 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2303 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_usb3_port_write_allocated_bandwidth()
2304 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2308 * usb4_usb3_port_allocate_bandwidth() - Allocate bandwidth for USB3
2309 * @port: USB3 adapter port
2324 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_allocate_bandwidth() argument
2329 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2333 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_allocate_bandwidth()
2342 ret = usb4_usb3_port_write_allocated_bandwidth(port, allocate_up, in usb4_usb3_port_allocate_bandwidth()
2351 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_allocate_bandwidth()
2356 * usb4_usb3_port_release_bandwidth() - Release allocated USB3 bandwidth
2357 * @port: USB3 adapter port
2366 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw, in usb4_usb3_port_release_bandwidth() argument
2371 ret = usb4_usb3_port_set_cm_request(port); in usb4_usb3_port_release_bandwidth()
2375 ret = usb4_usb3_port_read_consumed_bandwidth(port, &consumed_up, in usb4_usb3_port_release_bandwidth()
2389 ret = usb4_usb3_port_write_allocated_bandwidth(port, consumed_up, in usb4_usb3_port_release_bandwidth()
2398 usb4_usb3_port_clear_cm_request(port); in usb4_usb3_port_release_bandwidth()
2402 static bool is_usb4_dpin(const struct tb_port *port) in is_usb4_dpin() argument
2404 if (!tb_port_is_dpin(port)) in is_usb4_dpin()
2406 if (!tb_switch_is_usb4(port->sw)) in is_usb4_dpin()
2412 * usb4_dp_port_set_cm_id() - Assign CM ID to the DP IN adapter
2413 * @port: DP IN adapter
2416 * Sets CM ID for the @port. Returns %0 on success and negative errno
2417 * otherwise. Speficially returns %-EOPNOTSUPP if the @port does not
2420 int usb4_dp_port_set_cm_id(struct tb_port *port, int cm_id) in usb4_dp_port_set_cm_id() argument
2425 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_id()
2426 return -EOPNOTSUPP; in usb4_dp_port_set_cm_id()
2428 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2429 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2436 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_id()
2437 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2441 * usb4_dp_port_bandwidth_mode_supported() - Is the bandwidth allocation mode
2443 * @port: DP IN adapter to check
2448 bool usb4_dp_port_bandwidth_mode_supported(struct tb_port *port) in usb4_dp_port_bandwidth_mode_supported() argument
2453 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_supported()
2456 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_supported()
2457 port->cap_adap + DP_LOCAL_CAP, 1); in usb4_dp_port_bandwidth_mode_supported()
2465 * usb4_dp_port_bandwidth_mode_enabled() - Is the bandwidth allocation mode
2467 * @port: DP IN adapter to check
2472 bool usb4_dp_port_bandwidth_mode_enabled(struct tb_port *port) in usb4_dp_port_bandwidth_mode_enabled() argument
2477 if (!is_usb4_dpin(port)) in usb4_dp_port_bandwidth_mode_enabled()
2480 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_bandwidth_mode_enabled()
2481 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_bandwidth_mode_enabled()
2489 * usb4_dp_port_set_cm_bandwidth_mode_supported() - Set/clear CM support for
2491 * @port: DP IN adapter
2496 * otherwise. Specifically returns %-OPNOTSUPP if the passed in adapter
2499 int usb4_dp_port_set_cm_bandwidth_mode_supported(struct tb_port *port, in usb4_dp_port_set_cm_bandwidth_mode_supported() argument
2505 if (!is_usb4_dpin(port)) in usb4_dp_port_set_cm_bandwidth_mode_supported()
2506 return -EOPNOTSUPP; in usb4_dp_port_set_cm_bandwidth_mode_supported()
2508 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2509 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2518 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_cm_bandwidth_mode_supported()
2519 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2523 * usb4_dp_port_group_id() - Return Group ID assigned for the adapter
2524 * @port: DP IN adapter
2528 * %-EOPNOTSUPP is returned.
2530 int usb4_dp_port_group_id(struct tb_port *port) in usb4_dp_port_group_id() argument
2535 if (!is_usb4_dpin(port)) in usb4_dp_port_group_id()
2536 return -EOPNOTSUPP; in usb4_dp_port_group_id()
2538 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_group_id()
2539 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_group_id()
2547 * usb4_dp_port_set_group_id() - Set adapter Group ID
2548 * @port: DP IN adapter
2553 * Specifically returns %-EOPNOTSUPP if the adapter does not support
2556 int usb4_dp_port_set_group_id(struct tb_port *port, int group_id) in usb4_dp_port_set_group_id() argument
2561 if (!is_usb4_dpin(port)) in usb4_dp_port_set_group_id()
2562 return -EOPNOTSUPP; in usb4_dp_port_set_group_id()
2564 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2565 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2572 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_group_id()
2573 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2577 * usb4_dp_port_nrd() - Read non-reduced rate and lanes
2578 * @port: DP IN adapter
2579 * @rate: Non-reduced rate in Mb/s is placed here
2580 * @lanes: Non-reduced lanes are placed here
2582 * Reads the non-reduced rate and lanes from the DP IN adapter. Returns
2584 * %-EOPNOTSUPP if the adapter does not support this.
2586 int usb4_dp_port_nrd(struct tb_port *port, int *rate, int *lanes) in usb4_dp_port_nrd() argument
2591 if (!is_usb4_dpin(port)) in usb4_dp_port_nrd()
2592 return -EOPNOTSUPP; in usb4_dp_port_nrd()
2594 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_nrd()
2595 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_nrd()
2618 *lanes = 1; in usb4_dp_port_nrd()
2632 * usb4_dp_port_set_nrd() - Set non-reduced rate and lanes
2633 * @port: DP IN adapter
2634 * @rate: Non-reduced rate in Mb/s
2635 * @lanes: Non-reduced lanes
2638 * the non-reduced values for the DP IN adapter. Returns %0 in success
2640 * %-EOPNOTSUPP is returned.
2642 int usb4_dp_port_set_nrd(struct tb_port *port, int rate, int lanes) in usb4_dp_port_set_nrd() argument
2647 if (!is_usb4_dpin(port)) in usb4_dp_port_set_nrd()
2648 return -EOPNOTSUPP; in usb4_dp_port_set_nrd()
2650 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2651 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2673 return -EINVAL; in usb4_dp_port_set_nrd()
2679 case 1: in usb4_dp_port_set_nrd()
2688 return -EINVAL; in usb4_dp_port_set_nrd()
2691 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_nrd()
2692 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2696 * usb4_dp_port_granularity() - Return granularity for the bandwidth values
2697 * @port: DP IN adapter
2699 * Reads the programmed granularity from @port. If the DP IN adapter does
2700 * not support bandwidth allocation mode returns %-EOPNOTSUPP and negative
2703 int usb4_dp_port_granularity(struct tb_port *port) in usb4_dp_port_granularity() argument
2708 if (!is_usb4_dpin(port)) in usb4_dp_port_granularity()
2709 return -EOPNOTSUPP; in usb4_dp_port_granularity()
2711 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_granularity()
2712 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_granularity()
2728 return -EINVAL; in usb4_dp_port_granularity()
2732 * usb4_dp_port_set_granularity() - Set granularity for the bandwidth values
2733 * @port: DP IN adapter
2738 * adapter does not support this %-EOPNOTSUPP is returned.
2740 int usb4_dp_port_set_granularity(struct tb_port *port, int granularity) in usb4_dp_port_set_granularity() argument
2745 if (!is_usb4_dpin(port)) in usb4_dp_port_set_granularity()
2746 return -EOPNOTSUPP; in usb4_dp_port_set_granularity()
2748 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2749 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2766 return -EINVAL; in usb4_dp_port_set_granularity()
2769 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_granularity()
2770 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2774 * usb4_dp_port_set_estimated_bandwidth() - Set estimated bandwidth
2775 * @port: DP IN adapter
2781 * and negative errno otherwise. Specifically returns %-EOPNOTSUPP if
2784 int usb4_dp_port_set_estimated_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_set_estimated_bandwidth() argument
2789 if (!is_usb4_dpin(port)) in usb4_dp_port_set_estimated_bandwidth()
2790 return -EOPNOTSUPP; in usb4_dp_port_set_estimated_bandwidth()
2792 ret = usb4_dp_port_granularity(port); in usb4_dp_port_set_estimated_bandwidth()
2797 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2798 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2805 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_set_estimated_bandwidth()
2806 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2810 * usb4_dp_port_allocated_bandwidth() - Return allocated bandwidth
2811 * @port: DP IN adapter
2813 * Reads and returns allocated bandwidth for @port in Mb/s (taking into
2817 int usb4_dp_port_allocated_bandwidth(struct tb_port *port) in usb4_dp_port_allocated_bandwidth() argument
2822 if (!is_usb4_dpin(port)) in usb4_dp_port_allocated_bandwidth()
2823 return -EOPNOTSUPP; in usb4_dp_port_allocated_bandwidth()
2825 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocated_bandwidth()
2830 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocated_bandwidth()
2831 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocated_bandwidth()
2841 static int __usb4_dp_port_set_cm_ack(struct tb_port *port, bool ack) in __usb4_dp_port_set_cm_ack() argument
2846 ret = tb_port_read(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2847 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2856 return tb_port_write(port, &val, TB_CFG_PORT, in __usb4_dp_port_set_cm_ack()
2857 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2860 static inline int usb4_dp_port_set_cm_ack(struct tb_port *port) in usb4_dp_port_set_cm_ack() argument
2862 return __usb4_dp_port_set_cm_ack(port, true); in usb4_dp_port_set_cm_ack()
2865 static int usb4_dp_port_wait_and_clear_cm_ack(struct tb_port *port, in usb4_dp_port_wait_and_clear_cm_ack() argument
2872 ret = __usb4_dp_port_set_cm_ack(port, false); in usb4_dp_port_wait_and_clear_cm_ack()
2878 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2879 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2890 return -ETIMEDOUT; in usb4_dp_port_wait_and_clear_cm_ack()
2892 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2893 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2898 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_wait_and_clear_cm_ack()
2899 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2903 * usb4_dp_port_allocate_bandwidth() - Set allocated bandwidth
2904 * @port: DP IN adapter
2911 int usb4_dp_port_allocate_bandwidth(struct tb_port *port, int bw) in usb4_dp_port_allocate_bandwidth() argument
2916 if (!is_usb4_dpin(port)) in usb4_dp_port_allocate_bandwidth()
2917 return -EOPNOTSUPP; in usb4_dp_port_allocate_bandwidth()
2919 ret = usb4_dp_port_granularity(port); in usb4_dp_port_allocate_bandwidth()
2924 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2925 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2932 ret = tb_port_write(port, &val, TB_CFG_PORT, in usb4_dp_port_allocate_bandwidth()
2933 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2937 ret = usb4_dp_port_set_cm_ack(port); in usb4_dp_port_allocate_bandwidth()
2941 return usb4_dp_port_wait_and_clear_cm_ack(port, 500); in usb4_dp_port_allocate_bandwidth()
2945 * usb4_dp_port_requested_bandwidth() - Read requested bandwidth
2946 * @port: DP IN adapter
2950 * error returns negative errno. Specifically returns %-EOPNOTSUPP if
2954 int usb4_dp_port_requested_bandwidth(struct tb_port *port) in usb4_dp_port_requested_bandwidth() argument
2959 if (!is_usb4_dpin(port)) in usb4_dp_port_requested_bandwidth()
2960 return -EOPNOTSUPP; in usb4_dp_port_requested_bandwidth()
2962 ret = usb4_dp_port_granularity(port); in usb4_dp_port_requested_bandwidth()
2967 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_dp_port_requested_bandwidth()
2968 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_requested_bandwidth()
2973 return -ENODATA; in usb4_dp_port_requested_bandwidth()
2979 * usb4_pci_port_set_ext_encapsulation() - Enable/disable extended encapsulation
2980 * @port: PCIe adapter
2987 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable) in usb4_pci_port_set_ext_encapsulation() argument
2992 if (!tb_port_is_pcie_up(port) && !tb_port_is_pcie_down(port)) in usb4_pci_port_set_ext_encapsulation()
2993 return -EINVAL; in usb4_pci_port_set_ext_encapsulation()
2995 ret = tb_port_read(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
2996 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()
3005 return tb_port_write(port, &val, TB_CFG_PORT, in usb4_pci_port_set_ext_encapsulation()
3006 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()