Lines Matching refs:xd

155  * @xd: XDomain to send the message
165 int tb_xdomain_response(struct tb_xdomain *xd, const void *response,
168 return __tb_xdomain_response(xd->tb->ctl, response, size, type);
202 * @xd: XDomain to send the request
217 int tb_xdomain_request(struct tb_xdomain *xd, const void *request,
222 return __tb_xdomain_request(xd->tb->ctl, request, request_size,
415 struct tb_xdomain *xd, u8 sequence, const struct tb_xdp_properties *req)
427 if (!uuid_equal(xd->local_uuid, &req->dst_uuid)) {
428 tb_xdp_error_response(ctl, xd->route, sequence,
433 mutex_lock(&xd->lock);
435 if (req->offset >= xd->local_property_block_len) {
436 mutex_unlock(&xd->lock);
440 len = xd->local_property_block_len - req->offset;
446 mutex_unlock(&xd->lock);
450 tb_xdp_fill_header(&res->hdr, xd->route, sequence, PROPERTIES_RESPONSE,
452 res->generation = xd->local_property_block_gen;
453 res->data_length = xd->local_property_block_len;
455 uuid_copy(&res->src_uuid, xd->local_uuid);
457 memcpy(res->data, &xd->local_property_block[req->offset], len * 4);
459 mutex_unlock(&xd->lock);
538 struct tb_xdomain *xd, u8 sequence)
541 struct tb_port *port = tb_xdomain_downstream_port(xd);
546 tb_xdp_fill_header(&res.hdr, xd->route, sequence,
646 static void update_property_block(struct tb_xdomain *xd)
649 mutex_lock(&xd->lock);
654 if (!xd->local_property_block ||
655 xd->local_property_block_gen < xdomain_property_block_gen) {
662 dev_warn(&xd->dev, "failed to copy properties\n");
668 tb_property_add_immediate(dir, "maxhopid", xd->local_max_hopid);
672 dev_warn(&xd->dev, "local property block creation failed\n");
686 dev_warn(&xd->dev, "property block generation failed\n");
694 kfree(xd->local_property_block);
696 xd->local_property_block = block;
697 xd->local_property_block_len = block_len;
698 xd->local_property_block_gen = xdomain_property_block_gen;
702 mutex_unlock(&xd->lock);
706 static void start_handshake(struct tb_xdomain *xd)
708 xd->state = XDOMAIN_STATE_INIT;
709 queue_delayed_work(xd->tb->wq, &xd->state_work,
714 static void __stop_handshake(struct tb_xdomain *xd)
716 cancel_delayed_work_sync(&xd->properties_changed_work);
717 xd->properties_changed_retries = 0;
718 xd->state_retries = 0;
721 static void stop_handshake(struct tb_xdomain *xd)
723 cancel_delayed_work_sync(&xd->state_work);
724 __stop_handshake(xd);
734 struct tb_xdomain *xd;
756 xd = tb_xdomain_find_by_route_locked(tb, route);
757 if (xd)
758 update_property_block(xd);
763 if (xd) {
764 ret = tb_xdp_properties_response(tb, ctl, xd, sequence,
780 if (xd && device_is_registered(&xd->dev))
781 queue_delayed_work(tb->wq, &xd->state_work,
794 if (!ret && xd && xd->state == XDOMAIN_STATE_ERROR) {
795 dev_dbg(&xd->dev, "restarting handshake\n");
796 start_handshake(xd);
804 if (xd) {
805 ret = tb_xdp_link_state_status_response(tb, ctl, xd,
817 if (xd && xd->state == XDOMAIN_STATE_BONDING_UUID_HIGH) {
823 xd->target_link_width = lsc->tlw;
824 queue_delayed_work(tb->wq, &xd->state_work,
839 tb_xdomain_put(xd);
997 struct tb_xdomain *xd = tb_service_parent(svc);
1000 ida_simple_remove(&xd->service_ids, svc->id);
1015 struct tb_xdomain *xd = data;
1022 if (!tb_property_find(xd->remote_properties, svc->key,
1068 static void enumerate_services(struct tb_xdomain *xd)
1079 device_for_each_child_reverse(&xd->dev, xd, remove_missing_service);
1082 tb_property_for_each(xd->remote_properties, p) {
1087 dev = device_find_child(&xd->dev, p, find_service);
1102 id = ida_simple_get(&xd->service_ids, 0, 0, GFP_KERNEL);
1111 svc->dev.parent = &xd->dev;
1112 dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev), svc->id);
1123 static int populate_properties(struct tb_xdomain *xd,
1132 xd->device = p->value.immediate;
1137 xd->vendor = p->value.immediate;
1145 xd->remote_max_hopid = p ? p->value.immediate : XDOMAIN_DEFAULT_MAX_HOPID;
1147 kfree(xd->device_name);
1148 xd->device_name = NULL;
1149 kfree(xd->vendor_name);
1150 xd->vendor_name = NULL;
1155 xd->device_name = kstrdup(p->value.text, GFP_KERNEL);
1158 xd->vendor_name = kstrdup(p->value.text, GFP_KERNEL);
1163 static int tb_xdomain_update_link_attributes(struct tb_xdomain *xd)
1169 port = tb_xdomain_downstream_port(xd);
1175 if (xd->link_speed != ret)
1178 xd->link_speed = ret;
1184 if (xd->link_width != ret)
1187 xd->link_width = ret;
1190 kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE);
1195 static int tb_xdomain_get_uuid(struct tb_xdomain *xd)
1197 struct tb *tb = xd->tb;
1202 dev_dbg(&xd->dev, "requesting remote UUID\n");
1204 ret = tb_xdp_uuid_request(tb->ctl, xd->route, xd->state_retries, &uuid,
1207 if (xd->state_retries-- > 0) {
1208 dev_dbg(&xd->dev, "failed to request UUID, retrying\n");
1211 dev_dbg(&xd->dev, "failed to read remote UUID\n");
1215 dev_dbg(&xd->dev, "got remote UUID %pUb\n", &uuid);
1217 if (uuid_equal(&uuid, xd->local_uuid)) {
1218 if (route == xd->route)
1219 dev_dbg(&xd->dev, "loop back detected\n");
1221 dev_dbg(&xd->dev, "intra-domain loop detected\n");
1224 xd->bonding_possible = false;
1232 if (xd->remote_uuid && !uuid_equal(&uuid, xd->remote_uuid)) {
1233 dev_dbg(&xd->dev, "remote UUID is different, unplugging\n");
1234 xd->is_unplugged = true;
1239 if (!xd->remote_uuid) {
1240 xd->remote_uuid = kmemdup(&uuid, sizeof(uuid_t), GFP_KERNEL);
1241 if (!xd->remote_uuid)
1248 static int tb_xdomain_get_link_status(struct tb_xdomain *xd)
1250 struct tb *tb = xd->tb;
1254 dev_dbg(&xd->dev, "sending link state status request to %pUb\n",
1255 xd->remote_uuid);
1257 ret = tb_xdp_link_state_status_request(tb->ctl, xd->route,
1258 xd->state_retries, &slw, &tlw, &sls,
1261 if (ret != -EOPNOTSUPP && xd->state_retries-- > 0) {
1262 dev_dbg(&xd->dev,
1266 dev_dbg(&xd->dev, "failed to receive remote link status\n");
1270 dev_dbg(&xd->dev, "remote link supports width %#x speed %#x\n", slw, sls);
1273 dev_dbg(&xd->dev, "remote adapter is single lane only\n");
1280 static int tb_xdomain_link_state_change(struct tb_xdomain *xd,
1283 struct tb_port *port = tb_xdomain_downstream_port(xd);
1284 struct tb *tb = xd->tb;
1302 dev_dbg(&xd->dev, "sending link state change request with width %#x speed %#x\n",
1305 ret = tb_xdp_link_state_change_request(tb->ctl, xd->route,
1306 xd->state_retries, tlw, tls);
1308 if (ret != -EOPNOTSUPP && xd->state_retries-- > 0) {
1309 dev_dbg(&xd->dev,
1313 dev_err(&xd->dev, "failed request link state change, aborting\n");
1317 dev_dbg(&xd->dev, "received link state change response\n");
1321 static int tb_xdomain_bond_lanes_uuid_high(struct tb_xdomain *xd)
1327 if (xd->target_link_width == LANE_ADP_CS_1_TARGET_WIDTH_SINGLE) {
1330 } else if (xd->target_link_width == LANE_ADP_CS_1_TARGET_WIDTH_DUAL) {
1334 if (xd->state_retries-- > 0) {
1335 dev_dbg(&xd->dev,
1339 dev_dbg(&xd->dev, "timeout waiting for link change request\n");
1343 port = tb_xdomain_downstream_port(xd);
1367 dev_warn(&xd->dev, "error waiting for link width to become %d\n",
1376 tb_xdomain_update_link_attributes(xd);
1378 dev_dbg(&xd->dev, "lane bonding %s\n", str_enabled_disabled(width == 2));
1382 static int tb_xdomain_get_properties(struct tb_xdomain *xd)
1385 struct tb *tb = xd->tb;
1391 dev_dbg(&xd->dev, "requesting remote properties\n");
1393 ret = tb_xdp_properties_request(tb->ctl, xd->route, xd->local_uuid,
1394 xd->remote_uuid, xd->state_retries,
1397 if (xd->state_retries-- > 0) {
1398 dev_dbg(&xd->dev,
1403 dev_err(&xd->dev, "failed read XDomain properties from %pUb\n",
1404 xd->remote_uuid);
1409 mutex_lock(&xd->lock);
1412 if (xd->remote_properties && gen <= xd->remote_property_block_gen) {
1419 dev_err(&xd->dev, "failed to parse XDomain properties\n");
1424 ret = populate_properties(xd, dir);
1426 dev_err(&xd->dev, "missing XDomain properties in response\n");
1431 if (xd->remote_properties) {
1432 tb_property_free_dir(xd->remote_properties);
1436 xd->remote_properties = dir;
1437 xd->remote_property_block_gen = gen;
1439 tb_xdomain_update_link_attributes(xd);
1441 mutex_unlock(&xd->lock);
1457 if (xd->bonding_possible) {
1460 port = tb_xdomain_downstream_port(xd);
1465 if (device_add(&xd->dev)) {
1466 dev_err(&xd->dev, "failed to add XDomain device\n");
1469 dev_info(&xd->dev, "new host found, vendor=%#x device=%#x\n",
1470 xd->vendor, xd->device);
1471 if (xd->vendor_name && xd->device_name)
1472 dev_info(&xd->dev, "%s %s\n", xd->vendor_name,
1473 xd->device_name);
1475 tb_xdomain_debugfs_init(xd);
1477 kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE);
1480 enumerate_services(xd);
1487 mutex_unlock(&xd->lock);
1492 static void tb_xdomain_queue_uuid(struct tb_xdomain *xd)
1494 xd->state = XDOMAIN_STATE_UUID;
1495 xd->state_retries = XDOMAIN_RETRIES;
1496 queue_delayed_work(xd->tb->wq, &xd->state_work,
1500 static void tb_xdomain_queue_link_status(struct tb_xdomain *xd)
1502 xd->state = XDOMAIN_STATE_LINK_STATUS;
1503 xd->state_retries = XDOMAIN_RETRIES;
1504 queue_delayed_work(xd->tb->wq, &xd->state_work,
1508 static void tb_xdomain_queue_link_status2(struct tb_xdomain *xd)
1510 xd->state = XDOMAIN_STATE_LINK_STATUS2;
1511 xd->state_retries = XDOMAIN_RETRIES;
1512 queue_delayed_work(xd->tb->wq, &xd->state_work,
1516 static void tb_xdomain_queue_bonding(struct tb_xdomain *xd)
1518 if (memcmp(xd->local_uuid, xd->remote_uuid, UUID_SIZE) > 0) {
1519 dev_dbg(&xd->dev, "we have higher UUID, other side bonds the lanes\n");
1520 xd->state = XDOMAIN_STATE_BONDING_UUID_HIGH;
1522 dev_dbg(&xd->dev, "we have lower UUID, bonding lanes\n");
1523 xd->state = XDOMAIN_STATE_LINK_STATE_CHANGE;
1526 xd->state_retries = XDOMAIN_RETRIES;
1527 queue_delayed_work(xd->tb->wq, &xd->state_work,
1531 static void tb_xdomain_queue_bonding_uuid_low(struct tb_xdomain *xd)
1533 xd->state = XDOMAIN_STATE_BONDING_UUID_LOW;
1534 xd->state_retries = XDOMAIN_RETRIES;
1535 queue_delayed_work(xd->tb->wq, &xd->state_work,
1539 static void tb_xdomain_queue_properties(struct tb_xdomain *xd)
1541 xd->state = XDOMAIN_STATE_PROPERTIES;
1542 xd->state_retries = XDOMAIN_RETRIES;
1543 queue_delayed_work(xd->tb->wq, &xd->state_work,
1547 static void tb_xdomain_queue_properties_changed(struct tb_xdomain *xd)
1549 xd->properties_changed_retries = XDOMAIN_RETRIES;
1550 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work,
1554 static void tb_xdomain_failed(struct tb_xdomain *xd)
1556 xd->state = XDOMAIN_STATE_ERROR;
1557 queue_delayed_work(xd->tb->wq, &xd->state_work,
1563 struct tb_xdomain *xd = container_of(work, typeof(*xd), state_work.work);
1564 int ret, state = xd->state;
1570 dev_dbg(&xd->dev, "running state %s\n", state_names[state]);
1574 if (xd->needs_uuid) {
1575 tb_xdomain_queue_uuid(xd);
1577 tb_xdomain_queue_properties_changed(xd);
1578 tb_xdomain_queue_properties(xd);
1583 ret = tb_xdomain_get_uuid(xd);
1587 tb_xdomain_failed(xd);
1589 tb_xdomain_queue_properties_changed(xd);
1590 if (xd->bonding_possible)
1591 tb_xdomain_queue_link_status(xd);
1593 tb_xdomain_queue_properties(xd);
1598 ret = tb_xdomain_get_link_status(xd);
1608 tb_xdomain_queue_properties(xd);
1610 tb_xdomain_queue_bonding(xd);
1615 ret = tb_xdomain_link_state_change(xd, 2);
1619 tb_xdomain_queue_properties(xd);
1621 tb_xdomain_queue_link_status2(xd);
1626 ret = tb_xdomain_get_link_status(xd);
1630 tb_xdomain_queue_properties(xd);
1632 tb_xdomain_queue_bonding_uuid_low(xd);
1637 tb_xdomain_lane_bonding_enable(xd);
1638 tb_xdomain_queue_properties(xd);
1642 if (tb_xdomain_bond_lanes_uuid_high(xd) == -EAGAIN)
1644 tb_xdomain_queue_properties(xd);
1648 ret = tb_xdomain_get_properties(xd);
1652 tb_xdomain_failed(xd);
1654 xd->state = XDOMAIN_STATE_ENUMERATED;
1659 tb_xdomain_queue_properties(xd);
1663 dev_dbg(&xd->dev, "discovery failed, stopping handshake\n");
1664 __stop_handshake(xd);
1668 dev_warn(&xd->dev, "unexpected state %d\n", state);
1675 queue_delayed_work(xd->tb->wq, &xd->state_work,
1681 struct tb_xdomain *xd = container_of(work, typeof(*xd),
1685 dev_dbg(&xd->dev, "sending properties changed notification\n");
1687 ret = tb_xdp_properties_changed_request(xd->tb->ctl, xd->route,
1688 xd->properties_changed_retries, xd->local_uuid);
1690 if (xd->properties_changed_retries-- > 0) {
1691 dev_dbg(&xd->dev,
1693 queue_delayed_work(xd->tb->wq,
1694 &xd->properties_changed_work,
1697 dev_err(&xd->dev, "failed to send properties changed notification\n");
1701 xd->properties_changed_retries = XDOMAIN_RETRIES;
1707 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1709 return sysfs_emit(buf, "%#x\n", xd->device);
1716 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1719 if (mutex_lock_interruptible(&xd->lock))
1721 ret = sysfs_emit(buf, "%s\n", xd->device_name ?: "");
1722 mutex_unlock(&xd->lock);
1731 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1733 return sysfs_emit(buf, "%d\n", xd->remote_max_hopid);
1740 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1742 return sysfs_emit(buf, "%#x\n", xd->vendor);
1749 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1752 if (mutex_lock_interruptible(&xd->lock))
1754 ret = sysfs_emit(buf, "%s\n", xd->vendor_name ?: "");
1755 mutex_unlock(&xd->lock);
1764 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1766 return sysfs_emit(buf, "%pUb\n", xd->remote_uuid);
1773 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1775 return sysfs_emit(buf, "%u.0 Gb/s\n", xd->link_speed);
1784 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1787 switch (xd->link_width) {
1810 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1813 switch (xd->link_width) {
1858 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1860 put_device(xd->dev.parent);
1862 kfree(xd->local_property_block);
1863 tb_property_free_dir(xd->remote_properties);
1864 ida_destroy(&xd->out_hopids);
1865 ida_destroy(&xd->in_hopids);
1866 ida_destroy(&xd->service_ids);
1868 kfree(xd->local_uuid);
1869 kfree(xd->remote_uuid);
1870 kfree(xd->device_name);
1871 kfree(xd->vendor_name);
1872 kfree(xd);
1915 struct tb_xdomain *xd;
1922 xd = kzalloc(sizeof(*xd), GFP_KERNEL);
1923 if (!xd)
1926 xd->tb = tb;
1927 xd->route = route;
1928 xd->local_max_hopid = down->config.max_in_hop_id;
1929 ida_init(&xd->service_ids);
1930 ida_init(&xd->in_hopids);
1931 ida_init(&xd->out_hopids);
1932 mutex_init(&xd->lock);
1933 INIT_DELAYED_WORK(&xd->state_work, tb_xdomain_state_work);
1934 INIT_DELAYED_WORK(&xd->properties_changed_work,
1937 xd->local_uuid = kmemdup(local_uuid, sizeof(uuid_t), GFP_KERNEL);
1938 if (!xd->local_uuid)
1942 xd->remote_uuid = kmemdup(remote_uuid, sizeof(uuid_t),
1944 if (!xd->remote_uuid)
1947 xd->needs_uuid = true;
1948 xd->bonding_possible = !!down->dual_link_port;
1951 device_initialize(&xd->dev);
1952 xd->dev.parent = get_device(parent);
1953 xd->dev.bus = &tb_bus_type;
1954 xd->dev.type = &tb_xdomain_type;
1955 xd->dev.groups = xdomain_attr_groups;
1956 dev_set_name(&xd->dev, "%u-%llx", tb->index, route);
1958 dev_dbg(&xd->dev, "local UUID %pUb\n", local_uuid);
1960 dev_dbg(&xd->dev, "remote UUID %pUb\n", remote_uuid);
1966 pm_runtime_set_active(&xd->dev);
1967 pm_runtime_get_noresume(&xd->dev);
1968 pm_runtime_enable(&xd->dev);
1970 return xd;
1973 kfree(xd->local_uuid);
1975 kfree(xd);
1982 * @xd: XDomain to add
1989 void tb_xdomain_add(struct tb_xdomain *xd)
1992 start_handshake(xd);
2003 * @xd: XDomain to remove
2006 * along with any services from the bus. When the last reference to @xd
2009 void tb_xdomain_remove(struct tb_xdomain *xd)
2011 tb_xdomain_debugfs_remove(xd);
2013 stop_handshake(xd);
2015 device_for_each_child_reverse(&xd->dev, xd, unregister_service);
2022 pm_runtime_disable(&xd->dev);
2023 pm_runtime_put_noidle(&xd->dev);
2024 pm_runtime_set_suspended(&xd->dev);
2026 if (!device_is_registered(&xd->dev)) {
2027 put_device(&xd->dev);
2029 dev_info(&xd->dev, "host disconnected\n");
2030 device_unregister(&xd->dev);
2036 * @xd: XDomain connection
2044 int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd)
2050 port = tb_xdomain_downstream_port(xd);
2082 tb_xdomain_update_link_attributes(xd);
2084 dev_dbg(&xd->dev, "lane bonding enabled\n");
2091 * @xd: XDomain connection
2096 void tb_xdomain_lane_bonding_disable(struct tb_xdomain *xd)
2100 port = tb_xdomain_downstream_port(xd);
2110 tb_xdomain_update_link_attributes(xd);
2112 dev_dbg(&xd->dev, "lane bonding disabled\n");
2119 * @xd: XDomain connection
2127 int tb_xdomain_alloc_in_hopid(struct tb_xdomain *xd, int hopid)
2131 if (hopid < TB_PATH_MIN_HOPID || hopid > xd->local_max_hopid)
2134 return ida_alloc_range(&xd->in_hopids, hopid, xd->local_max_hopid,
2141 * @xd: XDomain connection
2149 int tb_xdomain_alloc_out_hopid(struct tb_xdomain *xd, int hopid)
2153 if (hopid < TB_PATH_MIN_HOPID || hopid > xd->remote_max_hopid)
2156 return ida_alloc_range(&xd->out_hopids, hopid, xd->remote_max_hopid,
2163 * @xd: XDomain connection
2166 void tb_xdomain_release_in_hopid(struct tb_xdomain *xd, int hopid)
2168 ida_free(&xd->in_hopids, hopid);
2174 * @xd: XDomain connection
2177 void tb_xdomain_release_out_hopid(struct tb_xdomain *xd, int hopid)
2179 ida_free(&xd->out_hopids, hopid);
2185 * @xd: XDomain connection
2198 int tb_xdomain_enable_paths(struct tb_xdomain *xd, int transmit_path,
2202 return tb_domain_approve_xdomain_paths(xd->tb, xd, transmit_path,
2210 * @xd: XDomain connection
2223 int tb_xdomain_disable_paths(struct tb_xdomain *xd, int transmit_path,
2227 return tb_domain_disconnect_xdomain_paths(xd->tb, xd, transmit_path,
2246 struct tb_xdomain *xd;
2249 xd = port->xdomain;
2252 if (xd->remote_uuid &&
2253 uuid_equal(xd->remote_uuid, lookup->uuid))
2254 return xd;
2256 if (lookup->link && lookup->link == xd->link &&
2257 lookup->depth == xd->depth)
2258 return xd;
2259 if (lookup->route && lookup->route == xd->route)
2260 return xd;
2263 xd = switch_find_xdomain(port->remote->sw, lookup);
2264 if (xd)
2265 return xd;
2290 struct tb_xdomain *xd;
2295 xd = switch_find_xdomain(tb->root_switch, &lookup);
2296 return tb_xdomain_get(xd);
2320 struct tb_xdomain *xd;
2326 xd = switch_find_xdomain(tb->root_switch, &lookup);
2327 return tb_xdomain_get(xd);
2348 struct tb_xdomain *xd;
2353 xd = switch_find_xdomain(tb->root_switch, &lookup);
2354 return tb_xdomain_get(xd);
2403 struct tb_xdomain *xd;
2405 xd = tb_to_xdomain(dev);
2406 if (xd) {
2407 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work,