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_free(&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_alloc(&xd->service_ids, 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 dev_dbg(&xd->dev, "current link speed %u.0 Gb/s\n",
1466 xd->link_speed);
1467 dev_dbg(&xd->dev, "current link width %s\n",
1468 tb_width_name(xd->link_width));
1470 if (device_add(&xd->dev)) {
1471 dev_err(&xd->dev, "failed to add XDomain device\n");
1474 dev_info(&xd->dev, "new host found, vendor=%#x device=%#x\n",
1475 xd->vendor, xd->device);
1476 if (xd->vendor_name && xd->device_name)
1477 dev_info(&xd->dev, "%s %s\n", xd->vendor_name,
1478 xd->device_name);
1480 tb_xdomain_debugfs_init(xd);
1482 kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE);
1485 enumerate_services(xd);
1492 mutex_unlock(&xd->lock);
1497 static void tb_xdomain_queue_uuid(struct tb_xdomain *xd)
1499 xd->state = XDOMAIN_STATE_UUID;
1500 xd->state_retries = XDOMAIN_RETRIES;
1501 queue_delayed_work(xd->tb->wq, &xd->state_work,
1505 static void tb_xdomain_queue_link_status(struct tb_xdomain *xd)
1507 xd->state = XDOMAIN_STATE_LINK_STATUS;
1508 xd->state_retries = XDOMAIN_RETRIES;
1509 queue_delayed_work(xd->tb->wq, &xd->state_work,
1513 static void tb_xdomain_queue_link_status2(struct tb_xdomain *xd)
1515 xd->state = XDOMAIN_STATE_LINK_STATUS2;
1516 xd->state_retries = XDOMAIN_RETRIES;
1517 queue_delayed_work(xd->tb->wq, &xd->state_work,
1521 static void tb_xdomain_queue_bonding(struct tb_xdomain *xd)
1523 if (memcmp(xd->local_uuid, xd->remote_uuid, UUID_SIZE) > 0) {
1524 dev_dbg(&xd->dev, "we have higher UUID, other side bonds the lanes\n");
1525 xd->state = XDOMAIN_STATE_BONDING_UUID_HIGH;
1527 dev_dbg(&xd->dev, "we have lower UUID, bonding lanes\n");
1528 xd->state = XDOMAIN_STATE_LINK_STATE_CHANGE;
1531 xd->state_retries = XDOMAIN_RETRIES;
1532 queue_delayed_work(xd->tb->wq, &xd->state_work,
1536 static void tb_xdomain_queue_bonding_uuid_low(struct tb_xdomain *xd)
1538 xd->state = XDOMAIN_STATE_BONDING_UUID_LOW;
1539 xd->state_retries = XDOMAIN_RETRIES;
1540 queue_delayed_work(xd->tb->wq, &xd->state_work,
1544 static void tb_xdomain_queue_properties(struct tb_xdomain *xd)
1546 xd->state = XDOMAIN_STATE_PROPERTIES;
1547 xd->state_retries = XDOMAIN_RETRIES;
1548 queue_delayed_work(xd->tb->wq, &xd->state_work,
1552 static void tb_xdomain_queue_properties_changed(struct tb_xdomain *xd)
1554 xd->properties_changed_retries = XDOMAIN_RETRIES;
1555 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work,
1559 static void tb_xdomain_failed(struct tb_xdomain *xd)
1561 xd->state = XDOMAIN_STATE_ERROR;
1562 queue_delayed_work(xd->tb->wq, &xd->state_work,
1568 struct tb_xdomain *xd = container_of(work, typeof(*xd), state_work.work);
1569 int ret, state = xd->state;
1575 dev_dbg(&xd->dev, "running state %s\n", state_names[state]);
1579 if (xd->needs_uuid) {
1580 tb_xdomain_queue_uuid(xd);
1582 tb_xdomain_queue_properties_changed(xd);
1583 tb_xdomain_queue_properties(xd);
1588 ret = tb_xdomain_get_uuid(xd);
1592 tb_xdomain_failed(xd);
1594 tb_xdomain_queue_properties_changed(xd);
1595 if (xd->bonding_possible)
1596 tb_xdomain_queue_link_status(xd);
1598 tb_xdomain_queue_properties(xd);
1603 ret = tb_xdomain_get_link_status(xd);
1613 tb_xdomain_queue_properties(xd);
1615 tb_xdomain_queue_bonding(xd);
1620 ret = tb_xdomain_link_state_change(xd, 2);
1624 tb_xdomain_queue_properties(xd);
1626 tb_xdomain_queue_link_status2(xd);
1631 ret = tb_xdomain_get_link_status(xd);
1635 tb_xdomain_queue_properties(xd);
1637 tb_xdomain_queue_bonding_uuid_low(xd);
1642 tb_xdomain_lane_bonding_enable(xd);
1643 tb_xdomain_queue_properties(xd);
1647 if (tb_xdomain_bond_lanes_uuid_high(xd) == -EAGAIN)
1649 tb_xdomain_queue_properties(xd);
1653 ret = tb_xdomain_get_properties(xd);
1657 tb_xdomain_failed(xd);
1659 xd->state = XDOMAIN_STATE_ENUMERATED;
1664 tb_xdomain_queue_properties(xd);
1668 dev_dbg(&xd->dev, "discovery failed, stopping handshake\n");
1669 __stop_handshake(xd);
1673 dev_warn(&xd->dev, "unexpected state %d\n", state);
1680 queue_delayed_work(xd->tb->wq, &xd->state_work,
1686 struct tb_xdomain *xd = container_of(work, typeof(*xd),
1690 dev_dbg(&xd->dev, "sending properties changed notification\n");
1692 ret = tb_xdp_properties_changed_request(xd->tb->ctl, xd->route,
1693 xd->properties_changed_retries, xd->local_uuid);
1695 if (xd->properties_changed_retries-- > 0) {
1696 dev_dbg(&xd->dev,
1698 queue_delayed_work(xd->tb->wq,
1699 &xd->properties_changed_work,
1702 dev_err(&xd->dev, "failed to send properties changed notification\n");
1706 xd->properties_changed_retries = XDOMAIN_RETRIES;
1712 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1714 return sysfs_emit(buf, "%#x\n", xd->device);
1721 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1724 if (mutex_lock_interruptible(&xd->lock))
1726 ret = sysfs_emit(buf, "%s\n", xd->device_name ?: "");
1727 mutex_unlock(&xd->lock);
1736 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1738 return sysfs_emit(buf, "%d\n", xd->remote_max_hopid);
1745 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1747 return sysfs_emit(buf, "%#x\n", xd->vendor);
1754 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1757 if (mutex_lock_interruptible(&xd->lock))
1759 ret = sysfs_emit(buf, "%s\n", xd->vendor_name ?: "");
1760 mutex_unlock(&xd->lock);
1769 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1771 return sysfs_emit(buf, "%pUb\n", xd->remote_uuid);
1778 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1780 return sysfs_emit(buf, "%u.0 Gb/s\n", xd->link_speed);
1789 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1792 switch (xd->link_width) {
1815 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1818 switch (xd->link_width) {
1863 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1865 put_device(xd->dev.parent);
1867 kfree(xd->local_property_block);
1868 tb_property_free_dir(xd->remote_properties);
1869 ida_destroy(&xd->out_hopids);
1870 ida_destroy(&xd->in_hopids);
1871 ida_destroy(&xd->service_ids);
1873 kfree(xd->local_uuid);
1874 kfree(xd->remote_uuid);
1875 kfree(xd->device_name);
1876 kfree(xd->vendor_name);
1877 kfree(xd);
1903 static void tb_xdomain_link_init(struct tb_xdomain *xd, struct tb_port *down)
1916 xd->bonding_possible = true;
1920 static void tb_xdomain_link_exit(struct tb_xdomain *xd)
1922 struct tb_port *down = tb_xdomain_downstream_port(xd);
1930 } else if (xd->link_width > TB_LINK_WIDTH_SINGLE) {
1964 struct tb_xdomain *xd;
1971 xd = kzalloc(sizeof(*xd), GFP_KERNEL);
1972 if (!xd)
1975 xd->tb = tb;
1976 xd->route = route;
1977 xd->local_max_hopid = down->config.max_in_hop_id;
1978 ida_init(&xd->service_ids);
1979 ida_init(&xd->in_hopids);
1980 ida_init(&xd->out_hopids);
1981 mutex_init(&xd->lock);
1982 INIT_DELAYED_WORK(&xd->state_work, tb_xdomain_state_work);
1983 INIT_DELAYED_WORK(&xd->properties_changed_work,
1986 xd->local_uuid = kmemdup(local_uuid, sizeof(uuid_t), GFP_KERNEL);
1987 if (!xd->local_uuid)
1991 xd->remote_uuid = kmemdup(remote_uuid, sizeof(uuid_t),
1993 if (!xd->remote_uuid)
1996 xd->needs_uuid = true;
1998 tb_xdomain_link_init(xd, down);
2001 device_initialize(&xd->dev);
2002 xd->dev.parent = get_device(parent);
2003 xd->dev.bus = &tb_bus_type;
2004 xd->dev.type = &tb_xdomain_type;
2005 xd->dev.groups = xdomain_attr_groups;
2006 dev_set_name(&xd->dev, "%u-%llx", tb->index, route);
2008 dev_dbg(&xd->dev, "local UUID %pUb\n", local_uuid);
2010 dev_dbg(&xd->dev, "remote UUID %pUb\n", remote_uuid);
2016 pm_runtime_set_active(&xd->dev);
2017 pm_runtime_get_noresume(&xd->dev);
2018 pm_runtime_enable(&xd->dev);
2020 return xd;
2023 kfree(xd->local_uuid);
2025 kfree(xd);
2032 * @xd: XDomain to add
2039 void tb_xdomain_add(struct tb_xdomain *xd)
2042 start_handshake(xd);
2053 * @xd: XDomain to remove
2056 * along with any services from the bus. When the last reference to @xd
2059 void tb_xdomain_remove(struct tb_xdomain *xd)
2061 tb_xdomain_debugfs_remove(xd);
2063 stop_handshake(xd);
2065 device_for_each_child_reverse(&xd->dev, xd, unregister_service);
2067 tb_xdomain_link_exit(xd);
2074 pm_runtime_disable(&xd->dev);
2075 pm_runtime_put_noidle(&xd->dev);
2076 pm_runtime_set_suspended(&xd->dev);
2078 if (!device_is_registered(&xd->dev)) {
2079 put_device(&xd->dev);
2081 dev_info(&xd->dev, "host disconnected\n");
2082 device_unregister(&xd->dev);
2088 * @xd: XDomain connection
2096 int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd)
2102 port = tb_xdomain_downstream_port(xd);
2134 tb_xdomain_update_link_attributes(xd);
2136 dev_dbg(&xd->dev, "lane bonding enabled\n");
2143 * @xd: XDomain connection
2148 void tb_xdomain_lane_bonding_disable(struct tb_xdomain *xd)
2152 port = tb_xdomain_downstream_port(xd);
2162 tb_xdomain_update_link_attributes(xd);
2164 dev_dbg(&xd->dev, "lane bonding disabled\n");
2171 * @xd: XDomain connection
2179 int tb_xdomain_alloc_in_hopid(struct tb_xdomain *xd, int hopid)
2183 if (hopid < TB_PATH_MIN_HOPID || hopid > xd->local_max_hopid)
2186 return ida_alloc_range(&xd->in_hopids, hopid, xd->local_max_hopid,
2193 * @xd: XDomain connection
2201 int tb_xdomain_alloc_out_hopid(struct tb_xdomain *xd, int hopid)
2205 if (hopid < TB_PATH_MIN_HOPID || hopid > xd->remote_max_hopid)
2208 return ida_alloc_range(&xd->out_hopids, hopid, xd->remote_max_hopid,
2215 * @xd: XDomain connection
2218 void tb_xdomain_release_in_hopid(struct tb_xdomain *xd, int hopid)
2220 ida_free(&xd->in_hopids, hopid);
2226 * @xd: XDomain connection
2229 void tb_xdomain_release_out_hopid(struct tb_xdomain *xd, int hopid)
2231 ida_free(&xd->out_hopids, hopid);
2237 * @xd: XDomain connection
2250 int tb_xdomain_enable_paths(struct tb_xdomain *xd, int transmit_path,
2254 return tb_domain_approve_xdomain_paths(xd->tb, xd, transmit_path,
2262 * @xd: XDomain connection
2275 int tb_xdomain_disable_paths(struct tb_xdomain *xd, int transmit_path,
2279 return tb_domain_disconnect_xdomain_paths(xd->tb, xd, transmit_path,
2298 struct tb_xdomain *xd;
2301 xd = port->xdomain;
2304 if (xd->remote_uuid &&
2305 uuid_equal(xd->remote_uuid, lookup->uuid))
2306 return xd;
2308 if (lookup->link && lookup->link == xd->link &&
2309 lookup->depth == xd->depth)
2310 return xd;
2311 if (lookup->route && lookup->route == xd->route)
2312 return xd;
2315 xd = switch_find_xdomain(port->remote->sw, lookup);
2316 if (xd)
2317 return xd;
2342 struct tb_xdomain *xd;
2347 xd = switch_find_xdomain(tb->root_switch, &lookup);
2348 return tb_xdomain_get(xd);
2372 struct tb_xdomain *xd;
2378 xd = switch_find_xdomain(tb->root_switch, &lookup);
2379 return tb_xdomain_get(xd);
2400 struct tb_xdomain *xd;
2405 xd = switch_find_xdomain(tb->root_switch, &lookup);
2406 return tb_xdomain_get(xd);
2455 struct tb_xdomain *xd;
2457 xd = tb_to_xdomain(dev);
2458 if (xd) {
2459 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work,