Lines Matching +full:sw +full:- +full:enable +full:- +full:bit

1 // SPDX-License-Identifier: GPL-2.0
53 static int usb4_native_switch_op(struct tb_switch *sw, u16 opcode, in usb4_native_switch_op() argument
62 ret = tb_sw_write(sw, metadata, TB_CFG_SWITCH, ROUTER_CS_25, 1); in usb4_native_switch_op()
67 ret = tb_sw_write(sw, tx_data, TB_CFG_SWITCH, ROUTER_CS_9, in usb4_native_switch_op()
74 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_native_switch_op()
78 ret = tb_switch_wait_for_bit(sw, ROUTER_CS_26, ROUTER_CS_26_OV, 0, 500); 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()
99 ret = tb_sw_read(sw, rx_data, TB_CFG_SWITCH, ROUTER_CS_9, in usb4_native_switch_op()
108 static int __usb4_switch_op(struct tb_switch *sw, u16 opcode, u32 *metadata, in __usb4_switch_op() argument
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()
137 return usb4_native_switch_op(sw, opcode, metadata, status, tx_data, in __usb4_switch_op()
141 static inline int usb4_switch_op(struct tb_switch *sw, u16 opcode, in usb4_switch_op() argument
144 return __usb4_switch_op(sw, opcode, metadata, status, NULL, 0, NULL, 0); in usb4_switch_op()
147 static inline int usb4_switch_op_data(struct tb_switch *sw, u16 opcode, in usb4_switch_op_data() argument
152 return __usb4_switch_op(sw, opcode, metadata, status, tx_data, in usb4_switch_op_data()
157 * usb4_switch_check_wakes() - Check for wakes and notify PM core about them
158 * @sw: Router whose wakes to check
162 void usb4_switch_check_wakes(struct tb_switch *sw) in usb4_switch_check_wakes() argument
170 if (tb_route(sw)) { in usb4_switch_check_wakes()
171 if (tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1)) in usb4_switch_check_wakes()
174 tb_sw_dbg(sw, "PCIe wake: %s, USB3 wake: %s\n", 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()
190 port->cap_usb4 + PORT_CS_18, 1)) 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()
216 if (!port->cap_usb4) 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
228 * @sw: USB4 router to setup
230 * USB4 routers need additional settings in order to enable all the
237 * This does not set the configuration valid bit of the router. To do
240 int usb4_switch_setup(struct tb_switch *sw) in usb4_switch_setup() argument
242 struct tb_switch *parent = tb_switch_parent(sw); in usb4_switch_setup()
248 if (!tb_route(sw)) in usb4_switch_setup()
251 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_6, 1); in usb4_switch_setup()
255 down = tb_switch_downstream_port(sw); 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()
262 tb_sw_dbg(sw, "TBT3 support: %s, xHCI: %s\n", 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()
276 * Only enable PCIe tunneling if the parent router supports it 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
299 * @sw: USB4 router
301 * Sets configuration valid bit for the router. Must be called before
308 int usb4_switch_configuration_valid(struct tb_switch *sw) in usb4_switch_configuration_valid() argument
313 if (!tb_route(sw)) in usb4_switch_configuration_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()
326 return tb_switch_wait_for_bit(sw, ROUTER_CS_6, ROUTER_CS_6_CR, in usb4_switch_configuration_valid()
331 * usb4_switch_read_uid() - Read UID from USB4 router
332 * @sw: USB4 router
335 * Reads 64-bit UID from USB4 router config space.
337 int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid) in usb4_switch_read_uid() argument
339 return tb_sw_read(sw, uid, TB_CFG_SWITCH, ROUTER_CS_7, 2); in usb4_switch_read_uid()
346 struct tb_switch *sw = data; in usb4_switch_drom_read_block() local
355 ret = usb4_switch_op_data(sw, USB4_SWITCH_OP_DROM_READ, &metadata, in usb4_switch_drom_read_block()
360 return status ? -EIO : 0; in usb4_switch_drom_read_block()
364 * usb4_switch_drom_read() - Read arbitrary bytes from USB4 router DROM
365 * @sw: USB4 router
371 * should always work but for hosts it may return %-EOPNOTSUPP in which
374 int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf, in usb4_switch_drom_read() argument
378 usb4_switch_drom_read_block, sw); in usb4_switch_drom_read()
382 * usb4_switch_lane_bonding_possible() - Are conditions met for lane bonding
383 * @sw: USB4 router
388 bool usb4_switch_lane_bonding_possible(struct tb_switch *sw) in usb4_switch_lane_bonding_possible() argument
394 up = tb_upstream_port(sw); in usb4_switch_lane_bonding_possible()
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
404 * @sw: USB4 router
410 int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags, bool runtime) in usb4_switch_set_wake() argument
413 u64 route = tb_route(sw); in usb4_switch_set_wake()
418 * Enable wakes coming from all USB4 downstream ports (from in usb4_switch_set_wake()
422 tb_switch_for_each_port(sw, port) { in usb4_switch_set_wake()
427 if (!port->cap_usb4) in usb4_switch_set_wake()
431 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
441 bool wakeup = runtime || device_may_wakeup(&port->usb4->dev); in usb4_switch_set_wake()
452 port->cap_usb4 + PORT_CS_19, 1); in usb4_switch_set_wake()
458 * Enable wakes from PCIe, USB 3.x and DP on this router. Only in usb4_switch_set_wake()
462 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_wake()
474 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_wake()
483 * usb4_switch_set_sleep() - Prepare the router to enter sleep
484 * @sw: USB4 router
486 * Sets sleep bit for the router. Returns when the router sleep ready
487 * bit has been asserted.
489 int usb4_switch_set_sleep(struct tb_switch *sw) in usb4_switch_set_sleep() argument
494 /* Set sleep bit and wait for sleep ready to be asserted */ in usb4_switch_set_sleep()
495 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_sleep()
501 ret = tb_sw_write(sw, &val, TB_CFG_SWITCH, ROUTER_CS_5, 1); in usb4_switch_set_sleep()
505 return tb_switch_wait_for_bit(sw, ROUTER_CS_6, ROUTER_CS_6_SLPR, in usb4_switch_set_sleep()
510 * usb4_switch_nvm_sector_size() - Return router NVM sector size
511 * @sw: USB4 router
515 * %-EOPNOTSUPP.
517 int usb4_switch_nvm_sector_size(struct tb_switch *sw) in usb4_switch_nvm_sector_size() argument
523 ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_SECTOR_SIZE, &metadata, in usb4_switch_nvm_sector_size()
529 return status == 0x2 ? -EOPNOTSUPP : -EIO; in usb4_switch_nvm_sector_size()
537 struct tb_switch *sw = data; in usb4_switch_nvm_read_block() local
547 ret = usb4_switch_op_data(sw, USB4_SWITCH_OP_NVM_READ, &metadata, in usb4_switch_nvm_read_block()
552 return status ? -EIO : 0; in usb4_switch_nvm_read_block()
556 * usb4_switch_nvm_read() - Read arbitrary bytes from router NVM
557 * @sw: USB4 router
563 * %-EOPNOTSUPP.
565 int usb4_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf, in usb4_switch_nvm_read() argument
569 usb4_switch_nvm_read_block, sw); in usb4_switch_nvm_read()
573 * usb4_switch_nvm_set_offset() - Set NVM write offset
574 * @sw: USB4 router
582 int usb4_switch_nvm_set_offset(struct tb_switch *sw, unsigned int address) in usb4_switch_nvm_set_offset() argument
592 ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_SET_OFFSET, &metadata, in usb4_switch_nvm_set_offset()
597 return status ? -EIO : 0; in usb4_switch_nvm_set_offset()
603 struct tb_switch *sw = data; in usb4_switch_nvm_write_next_block() local
607 ret = usb4_switch_op_data(sw, USB4_SWITCH_OP_NVM_WRITE, NULL, &status, in usb4_switch_nvm_write_next_block()
612 return status ? -EIO : 0; in usb4_switch_nvm_write_next_block()
616 * usb4_switch_nvm_write() - Write to the router NVM
617 * @sw: USB4 router
623 * write is not supported returns %-EOPNOTSUPP.
625 int usb4_switch_nvm_write(struct tb_switch *sw, unsigned int address, in usb4_switch_nvm_write() argument
630 ret = usb4_switch_nvm_set_offset(sw, address); in usb4_switch_nvm_write()
635 usb4_switch_nvm_write_next_block, sw); in usb4_switch_nvm_write()
639 * usb4_switch_nvm_authenticate() - Authenticate new NVM
640 * @sw: USB4 router
651 int usb4_switch_nvm_authenticate(struct tb_switch *sw) in usb4_switch_nvm_authenticate() argument
655 ret = usb4_switch_op(sw, USB4_SWITCH_OP_NVM_AUTH, NULL, NULL); in usb4_switch_nvm_authenticate()
661 case -EACCES: in usb4_switch_nvm_authenticate()
662 case -ENOTCONN: in usb4_switch_nvm_authenticate()
663 case -ETIMEDOUT: in usb4_switch_nvm_authenticate()
672 * usb4_switch_nvm_authenticate_status() - Read status of last NVM authenticate
673 * @sw: USB4 router
683 int usb4_switch_nvm_authenticate_status(struct tb_switch *sw, u32 *status) in usb4_switch_nvm_authenticate_status() argument
685 const struct tb_cm_ops *cm_ops = sw->tb->cm_ops; in usb4_switch_nvm_authenticate_status()
690 if (cm_ops->usb4_switch_nvm_authenticate_status) { in usb4_switch_nvm_authenticate_status()
691 ret = cm_ops->usb4_switch_nvm_authenticate_status(sw, status); in usb4_switch_nvm_authenticate_status()
692 if (ret != -EOPNOTSUPP) in usb4_switch_nvm_authenticate_status()
696 ret = tb_sw_read(sw, &val, TB_CFG_SWITCH, ROUTER_CS_26, 1); in usb4_switch_nvm_authenticate_status()
704 return -EBUSY; in usb4_switch_nvm_authenticate_status()
706 return -EOPNOTSUPP; in usb4_switch_nvm_authenticate_status()
718 * usb4_switch_credits_init() - Read buffer allocation parameters
719 * @sw: USB4 router
721 * Reads @sw buffer allocation parameters and initializes @sw buffer
722 * allocation fields accordingly. Specifically @sw->credits_allocation
727 int usb4_switch_credits_init(struct tb_switch *sw) in usb4_switch_credits_init() argument
737 ret = usb4_switch_op_data(sw, USB4_SWITCH_OP_BUFFER_ALLOC, &metadata, in usb4_switch_credits_init()
742 return -EIO; in usb4_switch_credits_init()
746 return -EMSGSIZE; in usb4_switch_credits_init()
748 max_usb3 = -1; in usb4_switch_credits_init()
749 min_dp_aux = -1; in usb4_switch_credits_init()
750 min_dp_main = -1; in usb4_switch_credits_init()
751 max_pcie = -1; in usb4_switch_credits_init()
752 max_dma = -1; in usb4_switch_credits_init()
754 tb_sw_dbg(sw, "credit allocation parameters:\n"); in usb4_switch_credits_init()
764 tb_sw_dbg(sw, " USB3: %u\n", value); in usb4_switch_credits_init()
768 tb_sw_dbg(sw, " DP AUX: %u\n", value); in usb4_switch_credits_init()
772 tb_sw_dbg(sw, " DP main: %u\n", value); in usb4_switch_credits_init()
776 tb_sw_dbg(sw, " PCIe: %u\n", value); in usb4_switch_credits_init()
780 tb_sw_dbg(sw, " DMA: %u\n", value); in usb4_switch_credits_init()
784 tb_sw_dbg(sw, " unknown credit allocation index %#x, skipping\n", in usb4_switch_credits_init()
792 * issues, log a warning and fall back using the hard-coded in usb4_switch_credits_init()
797 if (!tb_route(sw) && max_dma < 0) { in usb4_switch_credits_init()
798 tb_sw_warn(sw, "host router is missing baMaxHI\n"); in usb4_switch_credits_init()
803 tb_switch_for_each_port(sw, port) { in usb4_switch_credits_init()
810 tb_sw_warn(sw, "multiple USB4 ports require baMinDPaux/baMinDPmain\n"); in usb4_switch_credits_init()
814 tb_switch_for_each_port(sw, port) { in usb4_switch_credits_init()
816 tb_sw_warn(sw, "missing baMinDPmain"); in usb4_switch_credits_init()
821 tb_sw_warn(sw, "missing baMinDPaux"); in usb4_switch_credits_init()
826 tb_sw_warn(sw, "missing baMaxUSB3"); in usb4_switch_credits_init()
831 tb_sw_warn(sw, "missing baMaxPCIe"); in usb4_switch_credits_init()
840 sw->credit_allocation = true; in usb4_switch_credits_init()
842 sw->max_usb3_credits = max_usb3; in usb4_switch_credits_init()
844 sw->min_dp_aux_credits = min_dp_aux; in usb4_switch_credits_init()
846 sw->min_dp_main_credits = min_dp_main; in usb4_switch_credits_init()
848 sw->max_pcie_credits = max_pcie; in usb4_switch_credits_init()
850 sw->max_dma_credits = max_dma; in usb4_switch_credits_init()
855 return -EINVAL; in usb4_switch_credits_init()
859 * usb4_switch_query_dp_resource() - Query availability of DP IN resource
860 * @sw: USB4 router
867 bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in) in usb4_switch_query_dp_resource() argument
869 u32 metadata = in->port; in usb4_switch_query_dp_resource()
873 ret = usb4_switch_op(sw, USB4_SWITCH_OP_QUERY_DP_RESOURCE, &metadata, in usb4_switch_query_dp_resource()
879 if (ret == -EOPNOTSUPP) in usb4_switch_query_dp_resource()
888 * usb4_switch_alloc_dp_resource() - Allocate DP IN resource
889 * @sw: USB4 router
894 * returns negative errno, in particular %-EBUSY if the resource is
897 int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in) in usb4_switch_alloc_dp_resource() argument
899 u32 metadata = in->port; in usb4_switch_alloc_dp_resource()
903 ret = usb4_switch_op(sw, USB4_SWITCH_OP_ALLOC_DP_RESOURCE, &metadata, in usb4_switch_alloc_dp_resource()
905 if (ret == -EOPNOTSUPP) in usb4_switch_alloc_dp_resource()
910 return status ? -EBUSY : 0; in usb4_switch_alloc_dp_resource()
914 * usb4_switch_dealloc_dp_resource() - Releases allocated DP IN resource
915 * @sw: USB4 router
920 int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in) in usb4_switch_dealloc_dp_resource() argument
922 u32 metadata = in->port; in usb4_switch_dealloc_dp_resource()
926 ret = usb4_switch_op(sw, USB4_SWITCH_OP_DEALLOC_DP_RESOURCE, &metadata, in usb4_switch_dealloc_dp_resource()
928 if (ret == -EOPNOTSUPP) in usb4_switch_dealloc_dp_resource()
933 return status ? -EIO : 0; in usb4_switch_dealloc_dp_resource()
937 * usb4_port_index() - Finds matching USB4 port index
938 * @sw: USB4 router
944 int usb4_port_index(const struct tb_switch *sw, const struct tb_port *port) in usb4_port_index() argument
950 tb_switch_for_each_port(sw, p) { in usb4_port_index()
955 if (!p->link_nr) { in usb4_port_index()
966 * usb4_switch_map_pcie_down() - Map USB4 port to a PCIe downstream adapter
967 * @sw: USB4 router
975 struct tb_port *usb4_switch_map_pcie_down(struct tb_switch *sw, in usb4_switch_map_pcie_down() argument
978 int usb4_idx = usb4_port_index(sw, port); in usb4_switch_map_pcie_down()
983 tb_switch_for_each_port(sw, p) { in usb4_switch_map_pcie_down()
997 * usb4_switch_map_usb3_down() - Map USB4 port to a USB3 downstream adapter
998 * @sw: USB4 router
1006 struct tb_port *usb4_switch_map_usb3_down(struct tb_switch *sw, in usb4_switch_map_usb3_down() argument
1009 int usb4_idx = usb4_port_index(sw, port); in usb4_switch_map_usb3_down()
1014 tb_switch_for_each_port(sw, p) { in usb4_switch_map_usb3_down()
1028 * usb4_switch_add_ports() - Add USB4 ports for this router
1029 * @sw: USB4 router
1036 int usb4_switch_add_ports(struct tb_switch *sw) in usb4_switch_add_ports() argument
1040 if (tb_switch_is_icm(sw) || !tb_switch_is_usb4(sw)) in usb4_switch_add_ports()
1043 tb_switch_for_each_port(sw, port) { in usb4_switch_add_ports()
1048 if (!port->cap_usb4) in usb4_switch_add_ports()
1053 usb4_switch_remove_ports(sw); in usb4_switch_add_ports()
1057 port->usb4 = usb4; in usb4_switch_add_ports()
1064 * usb4_switch_remove_ports() - Removes USB4 ports from this router
1065 * @sw: USB4 router
1069 void usb4_switch_remove_ports(struct tb_switch *sw) in usb4_switch_remove_ports() argument
1073 tb_switch_for_each_port(sw, port) { in usb4_switch_remove_ports()
1074 if (port->usb4) { in usb4_switch_remove_ports()
1075 usb4_port_device_remove(port->usb4); in usb4_switch_remove_ports()
1076 port->usb4 = NULL; in usb4_switch_remove_ports()
1082 * usb4_port_unlock() - Unlock USB4 downstream port
1102 * usb4_port_hotplug_enable() - Enables hotplug for a port
1106 * to be used on lane, DP-IN, and DP-OUT adapters.
1122 * usb4_port_reset() - Issue downstream port reset
1132 if (!port->cap_usb4) in usb4_port_reset()
1133 return -EINVAL; in usb4_port_reset()
1136 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1143 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1150 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1157 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_reset()
1165 if (!port->cap_usb4) in usb4_port_set_configured()
1166 return -EINVAL; in usb4_port_set_configured()
1169 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_set_configured()
1179 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_set_configured()
1183 * usb4_port_configure() - Set USB4 port configured
1194 * usb4_port_unconfigure() - Set USB4 port unconfigured
1209 if (!port->cap_usb4) in usb4_set_xdomain_configured()
1210 return -EINVAL; in usb4_set_xdomain_configured()
1213 port->cap_usb4 + PORT_CS_19, 1); in usb4_set_xdomain_configured()
1223 port->cap_usb4 + PORT_CS_19, 1); in usb4_set_xdomain_configured()
1227 * usb4_port_configure_xdomain() - Configure port for XDomain
1236 xd->link_usb4 = link_is_usb4(port); in usb4_port_configure_xdomain()
1241 * usb4_port_unconfigure_xdomain() - Unconfigure port for XDomain
1251 static int usb4_port_wait_for_bit(struct tb_port *port, u32 offset, u32 bit, in usb4_port_wait_for_bit() argument
1264 if ((val & bit) == value) in usb4_port_wait_for_bit()
1270 return -ETIMEDOUT; in usb4_port_wait_for_bit()
1276 return -EINVAL; in usb4_port_read_data()
1278 return tb_port_read(port, data, TB_CFG_PORT, port->cap_usb4 + PORT_CS_2, in usb4_port_read_data()
1286 return -EINVAL; in usb4_port_write_data()
1288 return tb_port_write(port, data, TB_CFG_PORT, port->cap_usb4 + PORT_CS_2, in usb4_port_write_data()
1293 * usb4_port_sb_read() - Read from sideband register
1311 if (!port->cap_usb4) in usb4_port_sb_read()
1312 return -EINVAL; in usb4_port_sb_read()
1322 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1326 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_read()
1332 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_read()
1337 return -ENODEV; in usb4_port_sb_read()
1339 return -EIO; in usb4_port_sb_read()
1345 * usb4_port_sb_write() - Write to sideband register
1363 if (!port->cap_usb4) in usb4_port_sb_write()
1364 return -EINVAL; in usb4_port_sb_write()
1381 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1385 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_1, in usb4_port_sb_write()
1391 port->cap_usb4 + PORT_CS_1, 1); in usb4_port_sb_write()
1396 return -ENODEV; in usb4_port_sb_write()
1398 return -EIO; in usb4_port_sb_write()
1409 return -EAGAIN; in usb4_port_sb_opcode_err_to_errno()
1411 return -EOPNOTSUPP; in usb4_port_sb_opcode_err_to_errno()
1413 return -EIO; in usb4_port_sb_opcode_err_to_errno()
1445 return -ETIMEDOUT; in usb4_port_sb_op()
1464 * usb4_port_router_offline() - Put the USB4 port to offline mode
1480 * usb4_port_router_online() - Put the USB4 port back to online
1491 * usb4_port_enumerate_retimers() - Send RT broadcast transaction
1508 * usb4_port_clx_supported() - Check if CLx is supported by the link
1511 * PORT_CS_18_CPS bit reflects if the link supports CLx including
1520 port->cap_usb4 + PORT_CS_18, 1); in usb4_port_clx_supported()
1528 * usb4_port_asym_supported() - If the port supports asymmetric link
1538 if (!port->cap_usb4) in usb4_port_asym_supported()
1541 if (tb_port_read(port, &val, TB_CFG_PORT, port->cap_usb4 + PORT_CS_18, 1)) in usb4_port_asym_supported()
1548 * usb4_port_asym_set_link_width() - Set link width to asymmetric or symmetric
1560 if (!port->cap_phy) in usb4_port_asym_set_link_width()
1561 return -EINVAL; in usb4_port_asym_set_link_width()
1564 port->cap_phy + LANE_ADP_CS_1, 1); in usb4_port_asym_set_link_width()
1583 return -EINVAL; in usb4_port_asym_set_link_width()
1587 port->cap_phy + LANE_ADP_CS_1, 1); in usb4_port_asym_set_link_width()
1591 * usb4_port_asym_start() - Start symmetry change and wait for completion
1598 * Returns %0 in case of success, %-ETIMEDOUT if case of timeout or
1607 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_asym_start()
1615 port->cap_usb4 + PORT_CS_19, 1); in usb4_port_asym_start()
1623 ret = usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_19, in usb4_port_asym_start()
1630 return usb4_port_wait_for_bit(port, port->cap_usb4 + PORT_CS_18, in usb4_port_asym_start()
1635 * usb4_port_margining_caps() - Read USB4 port marginig capabilities
1659 * usb4_port_hw_margin() - Run hardware lane margining on port
1678 return -EINVAL; in usb4_port_hw_margin()
1680 val = params->lanes; in usb4_port_hw_margin()
1681 if (params->time) in usb4_port_hw_margin()
1683 if (params->right_high || params->upper_eye) in usb4_port_hw_margin()
1685 if (params->ber_level) in usb4_port_hw_margin()
1686 val |= FIELD_PREP(USB4_MARGIN_HW_BER_MASK, params->ber_level); in usb4_port_hw_margin()
1687 if (params->optional_voltage_offset_range) in usb4_port_hw_margin()
1705 * usb4_port_sw_margin() - Run software lane margining on port
1724 return -EINVAL; in usb4_port_sw_margin()
1726 val = params->lanes; in usb4_port_sw_margin()
1727 if (params->time) in usb4_port_sw_margin()
1729 if (params->optional_voltage_offset_range) in usb4_port_sw_margin()
1731 if (params->right_high) in usb4_port_sw_margin()
1733 if (params->upper_eye) in usb4_port_sw_margin()
1735 val |= FIELD_PREP(USB4_MARGIN_SW_COUNTER_MASK, params->error_counter); in usb4_port_sw_margin()
1736 val |= FIELD_PREP(USB4_MARGIN_SW_VT_MASK, params->voltage_time_offset); in usb4_port_sw_margin()
1754 * usb4_port_sw_margin_errors() - Read the software margining error counters
1786 * usb4_port_retimer_set_inbound_sbtx() - Enable sideband channel transactions
1800 if (ret != -ENODEV) in usb4_port_retimer_set_inbound_sbtx()
1813 * usb4_port_retimer_unset_inbound_sbtx() - Disable sideband channel transactions
1827 * usb4_port_retimer_is_last() - Is the retimer last on-board retimer
1832 * Type-C port) this function returns %1. If it is not returns %0. If
1833 * the retimer is not present returns %-ENODEV. Otherwise returns
1852 * usb4_port_retimer_is_cable() - Is the retimer cable retimer
1857 * %1 and %0 if it is on-board retimer. In case a retimer is not present
1858 * at @index returns %-ENODEV. Otherwise returns negative errno.
1876 * usb4_port_retimer_nvm_sector_size() - Read retimer NVM sector size
1883 * in case of error. Specifically returns %-ENODEV if there is no
1902 * usb4_port_retimer_nvm_set_offset() - Set NVM write offset
1941 struct tb_port *port = info->port; in usb4_port_retimer_nvm_write_next_block()
1942 u8 index = info->index; in usb4_port_retimer_nvm_write_next_block()
1955 * usb4_port_retimer_nvm_write() - Write to retimer NVM
1964 * errno in case of failure. Specifically returns %-ENODEV if there is
1982 * usb4_port_retimer_nvm_authenticate() - Start retimer NVM upgrade
2007 * usb4_port_retimer_nvm_authenticate_status() - Read status of NVM upgrade
2036 case -EAGAIN: in usb4_port_retimer_nvm_authenticate_status()
2055 struct tb_port *port = info->port; in usb4_port_retimer_nvm_read_block()
2056 u8 index = info->index; in usb4_port_retimer_nvm_read_block()
2078 * usb4_port_retimer_nvm_read() - Read contents of retimer NVM
2087 * Specifically returns %-ENODEV if there is no retimer at @index.
2102 if (port->max_bw) in usb4_usb3_port_max_bandwidth()
2103 return min(bw, port->max_bw); in usb4_usb3_port_max_bandwidth()
2108 * usb4_usb3_port_max_link_rate() - Maximum support USB3 link rate
2120 return -EINVAL; in usb4_usb3_port_max_link_rate()
2123 port->cap_adap + ADP_USB3_CS_4, 1); in usb4_usb3_port_max_link_rate()
2139 return -EINVAL; in usb4_usb3_port_cm_request()
2140 if (tb_route(port->sw)) in usb4_usb3_port_cm_request()
2141 return -EINVAL; in usb4_usb3_port_cm_request()
2144 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2154 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_cm_request()
2159 * We can use val here directly as the CMR bit is in the same place in usb4_usb3_port_cm_request()
2163 return usb4_port_wait_for_bit(port, port->cap_adap + ADP_USB3_CS_1, in usb4_usb3_port_cm_request()
2190 /* 1 uframe is 1/8 ms (125 us) -> 1 / 8000 s */ in mbps_to_usb3_bw()
2203 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_read_allocated_bandwidth()
2208 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_allocated_bandwidth()
2224 * usb4_usb3_port_allocated_bandwidth() - Bandwidth allocated for USB3
2257 port->cap_adap + ADP_USB3_CS_1, 1); in usb4_usb3_port_read_consumed_bandwidth()
2262 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_read_consumed_bandwidth()
2294 return -EINVAL; in usb4_usb3_port_write_allocated_bandwidth()
2297 port->cap_adap + ADP_USB3_CS_3, 1); in usb4_usb3_port_write_allocated_bandwidth()
2307 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2316 port->cap_adap + ADP_USB3_CS_2, 1); in usb4_usb3_port_write_allocated_bandwidth()
2320 * usb4_usb3_port_allocate_bandwidth() - Allocate bandwidth for USB3
2368 * usb4_usb3_port_release_bandwidth() - Release allocated USB3 bandwidth
2418 if (!tb_switch_is_usb4(port->sw)) in is_usb4_dpin()
2424 * usb4_dp_port_set_cm_id() - Assign CM ID to the DP IN adapter
2429 * otherwise. Speficially returns %-EOPNOTSUPP if the @port does not
2438 return -EOPNOTSUPP; in usb4_dp_port_set_cm_id()
2441 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2449 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_id()
2453 * usb4_dp_port_bandwidth_mode_supported() - Is the bandwidth allocation mode
2469 port->cap_adap + DP_LOCAL_CAP, 1); in usb4_dp_port_bandwidth_mode_supported()
2477 * usb4_dp_port_bandwidth_mode_enabled() - Is the bandwidth allocation mode
2493 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_bandwidth_mode_enabled()
2501 * usb4_dp_port_set_cm_bandwidth_mode_supported() - Set/clear CM support for
2506 * Can be called to any DP IN adapter. Sets or clears the CM support bit
2508 * otherwise. Specifically returns %-OPNOTSUPP if the passed in adapter
2518 return -EOPNOTSUPP; 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()
2531 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_cm_bandwidth_mode_supported()
2535 * usb4_dp_port_group_id() - Return Group ID assigned for the adapter
2540 * %-EOPNOTSUPP is returned.
2548 return -EOPNOTSUPP; in usb4_dp_port_group_id()
2551 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_group_id()
2559 * usb4_dp_port_set_group_id() - Set adapter Group ID
2565 * Specifically returns %-EOPNOTSUPP if the adapter does not support
2574 return -EOPNOTSUPP; in usb4_dp_port_set_group_id()
2577 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2585 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_group_id()
2589 * usb4_dp_port_nrd() - Read non-reduced rate and lanes
2591 * @rate: Non-reduced rate in Mb/s is placed here
2592 * @lanes: Non-reduced lanes are placed here
2594 * Reads the non-reduced rate and lanes from the DP IN adapter. Returns
2596 * %-EOPNOTSUPP if the adapter does not support this.
2604 return -EOPNOTSUPP; in usb4_dp_port_nrd()
2607 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_nrd()
2644 * usb4_dp_port_set_nrd() - Set non-reduced rate and lanes
2646 * @rate: Non-reduced rate in Mb/s
2647 * @lanes: Non-reduced lanes
2650 * the non-reduced values for the DP IN adapter. Returns %0 in success
2652 * %-EOPNOTSUPP is returned.
2660 return -EOPNOTSUPP; in usb4_dp_port_set_nrd()
2663 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2685 return -EINVAL; in usb4_dp_port_set_nrd()
2700 return -EINVAL; in usb4_dp_port_set_nrd()
2704 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_nrd()
2708 * usb4_dp_port_granularity() - Return granularity for the bandwidth values
2712 * not support bandwidth allocation mode returns %-EOPNOTSUPP and negative
2721 return -EOPNOTSUPP; in usb4_dp_port_granularity()
2724 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_granularity()
2740 return -EINVAL; in usb4_dp_port_granularity()
2744 * usb4_dp_port_set_granularity() - Set granularity for the bandwidth values
2750 * adapter does not support this %-EOPNOTSUPP is returned.
2758 return -EOPNOTSUPP; in usb4_dp_port_set_granularity()
2761 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2778 return -EINVAL; in usb4_dp_port_set_granularity()
2782 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_granularity()
2786 * usb4_dp_port_set_estimated_bandwidth() - Set estimated bandwidth
2793 * and negative errno otherwise. Specifically returns %-EOPNOTSUPP if
2802 return -EOPNOTSUPP; in usb4_dp_port_set_estimated_bandwidth()
2810 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2818 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_set_estimated_bandwidth()
2822 * usb4_dp_port_allocated_bandwidth() - Return allocated bandwidth
2835 return -EOPNOTSUPP; in usb4_dp_port_allocated_bandwidth()
2843 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocated_bandwidth()
2859 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2869 port->cap_adap + ADP_DP_CS_2, 1); in __usb4_dp_port_set_cm_ack()
2891 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2903 return -ETIMEDOUT; in usb4_dp_port_wait_and_clear_cm_ack()
2907 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2913 port->cap_adap + ADP_DP_CS_2, 1); in usb4_dp_port_wait_and_clear_cm_ack()
2917 * usb4_dp_port_allocate_bandwidth() - Set allocated bandwidth
2931 return -EOPNOTSUPP; in usb4_dp_port_allocate_bandwidth()
2939 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2947 port->cap_adap + DP_STATUS, 1); in usb4_dp_port_allocate_bandwidth()
2959 * usb4_dp_port_requested_bandwidth() - Read requested bandwidth
2964 * error returns negative errno. Specifically returns %-EOPNOTSUPP if
2974 return -EOPNOTSUPP; in usb4_dp_port_requested_bandwidth()
2982 port->cap_adap + ADP_DP_CS_8, 1); in usb4_dp_port_requested_bandwidth()
2987 return -ENODATA; in usb4_dp_port_requested_bandwidth()
2993 * usb4_pci_port_set_ext_encapsulation() - Enable/disable extended encapsulation
2995 * @enable: Enable/disable extended encapsulation
3001 int usb4_pci_port_set_ext_encapsulation(struct tb_port *port, bool enable) in usb4_pci_port_set_ext_encapsulation() argument
3007 return -EINVAL; in usb4_pci_port_set_ext_encapsulation()
3010 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()
3014 if (enable) in usb4_pci_port_set_ext_encapsulation()
3020 port->cap_adap + ADP_PCIE_CS_1, 1); in usb4_pci_port_set_ext_encapsulation()