Lines Matching refs:xd

164 int tb_xdomain_response(struct tb_xdomain *xd, const void *response,  in tb_xdomain_response()  argument
167 return __tb_xdomain_response(xd->tb->ctl, response, size, type); in tb_xdomain_response()
216 int tb_xdomain_request(struct tb_xdomain *xd, const void *request, in tb_xdomain_request() argument
221 return __tb_xdomain_request(xd->tb->ctl, request, request_size, in tb_xdomain_request()
415 struct tb_xdomain *xd, u8 sequence, const struct tb_xdp_properties *req) in tb_xdp_properties_response() argument
427 if (!uuid_equal(xd->local_uuid, &req->dst_uuid)) { in tb_xdp_properties_response()
428 tb_xdp_error_response(ctl, xd->route, sequence, in tb_xdp_properties_response()
433 mutex_lock(&xd->lock); in tb_xdp_properties_response()
435 if (req->offset >= xd->local_property_block_len) { in tb_xdp_properties_response()
436 mutex_unlock(&xd->lock); in tb_xdp_properties_response()
440 len = xd->local_property_block_len - req->offset; in tb_xdp_properties_response()
446 mutex_unlock(&xd->lock); in tb_xdp_properties_response()
450 tb_xdp_fill_header(&res->hdr, xd->route, sequence, PROPERTIES_RESPONSE, in tb_xdp_properties_response()
452 res->generation = xd->local_property_block_gen; in tb_xdp_properties_response()
453 res->data_length = xd->local_property_block_len; in tb_xdp_properties_response()
455 uuid_copy(&res->src_uuid, xd->local_uuid); in tb_xdp_properties_response()
457 memcpy(res->data, &xd->local_property_block[req->offset], len * 4); in tb_xdp_properties_response()
459 mutex_unlock(&xd->lock); in tb_xdp_properties_response()
538 struct tb_xdomain *xd, u8 sequence) in tb_xdp_link_state_status_response() argument
540 struct tb_switch *sw = tb_to_switch(xd->dev.parent); in tb_xdp_link_state_status_response()
542 struct tb_port *port = tb_port_at(xd->route, sw); in tb_xdp_link_state_status_response()
547 tb_xdp_fill_header(&res.hdr, xd->route, sequence, in tb_xdp_link_state_status_response()
647 static void update_property_block(struct tb_xdomain *xd) in update_property_block() argument
650 mutex_lock(&xd->lock); in update_property_block()
655 if (!xd->local_property_block || in update_property_block()
656 xd->local_property_block_gen < xdomain_property_block_gen) { in update_property_block()
663 dev_warn(&xd->dev, "failed to copy properties\n"); in update_property_block()
669 tb_property_add_immediate(dir, "maxhopid", xd->local_max_hopid); in update_property_block()
673 dev_warn(&xd->dev, "local property block creation failed\n"); in update_property_block()
687 dev_warn(&xd->dev, "property block generation failed\n"); in update_property_block()
695 kfree(xd->local_property_block); in update_property_block()
697 xd->local_property_block = block; in update_property_block()
698 xd->local_property_block_len = block_len; in update_property_block()
699 xd->local_property_block_gen = xdomain_property_block_gen; in update_property_block()
703 mutex_unlock(&xd->lock); in update_property_block()
714 struct tb_xdomain *xd; in tb_xdp_handle_request() local
736 xd = tb_xdomain_find_by_route_locked(tb, route); in tb_xdp_handle_request()
737 if (xd) in tb_xdp_handle_request()
738 update_property_block(xd); in tb_xdp_handle_request()
743 if (xd) { in tb_xdp_handle_request()
744 ret = tb_xdp_properties_response(tb, ctl, xd, sequence, in tb_xdp_handle_request()
760 if (xd && device_is_registered(&xd->dev)) in tb_xdp_handle_request()
761 queue_delayed_work(tb->wq, &xd->state_work, in tb_xdp_handle_request()
775 if (xd) { in tb_xdp_handle_request()
776 ret = tb_xdp_link_state_status_response(tb, ctl, xd, in tb_xdp_handle_request()
788 if (xd && xd->state == XDOMAIN_STATE_BONDING_UUID_HIGH) { in tb_xdp_handle_request()
794 xd->target_link_width = lsc->tlw; in tb_xdp_handle_request()
795 queue_delayed_work(tb->wq, &xd->state_work, in tb_xdp_handle_request()
810 tb_xdomain_put(xd); in tb_xdp_handle_request()
968 struct tb_xdomain *xd = tb_service_parent(svc); in tb_service_release() local
971 ida_simple_remove(&xd->service_ids, svc->id); in tb_service_release()
986 struct tb_xdomain *xd = data; in remove_missing_service() local
993 if (!tb_property_find(xd->remote_properties, svc->key, in remove_missing_service()
1039 static void enumerate_services(struct tb_xdomain *xd) in enumerate_services() argument
1050 device_for_each_child_reverse(&xd->dev, xd, remove_missing_service); in enumerate_services()
1053 tb_property_for_each(xd->remote_properties, p) { in enumerate_services()
1058 dev = device_find_child(&xd->dev, p, find_service); in enumerate_services()
1073 id = ida_simple_get(&xd->service_ids, 0, 0, GFP_KERNEL); in enumerate_services()
1082 svc->dev.parent = &xd->dev; in enumerate_services()
1083 dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev), svc->id); in enumerate_services()
1094 static int populate_properties(struct tb_xdomain *xd, in populate_properties() argument
1103 xd->device = p->value.immediate; in populate_properties()
1108 xd->vendor = p->value.immediate; in populate_properties()
1116 xd->remote_max_hopid = p ? p->value.immediate : XDOMAIN_DEFAULT_MAX_HOPID; in populate_properties()
1118 kfree(xd->device_name); in populate_properties()
1119 xd->device_name = NULL; in populate_properties()
1120 kfree(xd->vendor_name); in populate_properties()
1121 xd->vendor_name = NULL; in populate_properties()
1126 xd->device_name = kstrdup(p->value.text, GFP_KERNEL); in populate_properties()
1129 xd->vendor_name = kstrdup(p->value.text, GFP_KERNEL); in populate_properties()
1134 static int tb_xdomain_update_link_attributes(struct tb_xdomain *xd) in tb_xdomain_update_link_attributes() argument
1140 port = tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_update_link_attributes()
1146 if (xd->link_speed != ret) in tb_xdomain_update_link_attributes()
1149 xd->link_speed = ret; in tb_xdomain_update_link_attributes()
1155 if (xd->link_width != ret) in tb_xdomain_update_link_attributes()
1158 xd->link_width = ret; in tb_xdomain_update_link_attributes()
1161 kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE); in tb_xdomain_update_link_attributes()
1166 static int tb_xdomain_get_uuid(struct tb_xdomain *xd) in tb_xdomain_get_uuid() argument
1168 struct tb *tb = xd->tb; in tb_xdomain_get_uuid()
1173 dev_dbg(&xd->dev, "requesting remote UUID\n"); in tb_xdomain_get_uuid()
1175 ret = tb_xdp_uuid_request(tb->ctl, xd->route, xd->state_retries, &uuid, in tb_xdomain_get_uuid()
1178 if (xd->state_retries-- > 0) { in tb_xdomain_get_uuid()
1179 dev_dbg(&xd->dev, "failed to request UUID, retrying\n"); in tb_xdomain_get_uuid()
1182 dev_dbg(&xd->dev, "failed to read remote UUID\n"); in tb_xdomain_get_uuid()
1187 dev_dbg(&xd->dev, "got remote UUID %pUb\n", &uuid); in tb_xdomain_get_uuid()
1189 if (uuid_equal(&uuid, xd->local_uuid)) { in tb_xdomain_get_uuid()
1190 if (route == xd->route) in tb_xdomain_get_uuid()
1191 dev_dbg(&xd->dev, "loop back detected\n"); in tb_xdomain_get_uuid()
1193 dev_dbg(&xd->dev, "intra-domain loop detected\n"); in tb_xdomain_get_uuid()
1196 xd->bonding_possible = false; in tb_xdomain_get_uuid()
1204 if (xd->remote_uuid && !uuid_equal(&uuid, xd->remote_uuid)) { in tb_xdomain_get_uuid()
1205 dev_dbg(&xd->dev, "remote UUID is different, unplugging\n"); in tb_xdomain_get_uuid()
1206 xd->is_unplugged = true; in tb_xdomain_get_uuid()
1211 if (!xd->remote_uuid) { in tb_xdomain_get_uuid()
1212 xd->remote_uuid = kmemdup(&uuid, sizeof(uuid_t), GFP_KERNEL); in tb_xdomain_get_uuid()
1213 if (!xd->remote_uuid) in tb_xdomain_get_uuid()
1220 static int tb_xdomain_get_link_status(struct tb_xdomain *xd) in tb_xdomain_get_link_status() argument
1222 struct tb *tb = xd->tb; in tb_xdomain_get_link_status()
1226 dev_dbg(&xd->dev, "sending link state status request to %pUb\n", in tb_xdomain_get_link_status()
1227 xd->remote_uuid); in tb_xdomain_get_link_status()
1229 ret = tb_xdp_link_state_status_request(tb->ctl, xd->route, in tb_xdomain_get_link_status()
1230 xd->state_retries, &slw, &tlw, &sls, in tb_xdomain_get_link_status()
1233 if (ret != -EOPNOTSUPP && xd->state_retries-- > 0) { in tb_xdomain_get_link_status()
1234 dev_dbg(&xd->dev, in tb_xdomain_get_link_status()
1238 dev_dbg(&xd->dev, "failed to receive remote link status\n"); in tb_xdomain_get_link_status()
1242 dev_dbg(&xd->dev, "remote link supports width %#x speed %#x\n", slw, sls); in tb_xdomain_get_link_status()
1245 dev_dbg(&xd->dev, "remote adapter is single lane only\n"); in tb_xdomain_get_link_status()
1252 static int tb_xdomain_link_state_change(struct tb_xdomain *xd, in tb_xdomain_link_state_change() argument
1255 struct tb_switch *sw = tb_to_switch(xd->dev.parent); in tb_xdomain_link_state_change()
1256 struct tb_port *port = tb_port_at(xd->route, sw); in tb_xdomain_link_state_change()
1257 struct tb *tb = xd->tb; in tb_xdomain_link_state_change()
1275 dev_dbg(&xd->dev, "sending link state change request with width %#x speed %#x\n", in tb_xdomain_link_state_change()
1278 ret = tb_xdp_link_state_change_request(tb->ctl, xd->route, in tb_xdomain_link_state_change()
1279 xd->state_retries, tlw, tls); in tb_xdomain_link_state_change()
1281 if (ret != -EOPNOTSUPP && xd->state_retries-- > 0) { in tb_xdomain_link_state_change()
1282 dev_dbg(&xd->dev, in tb_xdomain_link_state_change()
1286 dev_err(&xd->dev, "failed request link state change, aborting\n"); in tb_xdomain_link_state_change()
1290 dev_dbg(&xd->dev, "received link state change response\n"); in tb_xdomain_link_state_change()
1294 static int tb_xdomain_bond_lanes_uuid_high(struct tb_xdomain *xd) in tb_xdomain_bond_lanes_uuid_high() argument
1299 if (xd->target_link_width == LANE_ADP_CS_1_TARGET_WIDTH_SINGLE) { in tb_xdomain_bond_lanes_uuid_high()
1301 } else if (xd->target_link_width == LANE_ADP_CS_1_TARGET_WIDTH_DUAL) { in tb_xdomain_bond_lanes_uuid_high()
1304 if (xd->state_retries-- > 0) { in tb_xdomain_bond_lanes_uuid_high()
1305 dev_dbg(&xd->dev, in tb_xdomain_bond_lanes_uuid_high()
1309 dev_dbg(&xd->dev, "timeout waiting for link change request\n"); in tb_xdomain_bond_lanes_uuid_high()
1313 port = tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_bond_lanes_uuid_high()
1336 dev_warn(&xd->dev, "error waiting for link width to become %d\n", in tb_xdomain_bond_lanes_uuid_high()
1345 tb_xdomain_update_link_attributes(xd); in tb_xdomain_bond_lanes_uuid_high()
1347 dev_dbg(&xd->dev, "lane bonding %sabled\n", width == 2 ? "en" : "dis"); in tb_xdomain_bond_lanes_uuid_high()
1351 static int tb_xdomain_get_properties(struct tb_xdomain *xd) in tb_xdomain_get_properties() argument
1354 struct tb *tb = xd->tb; in tb_xdomain_get_properties()
1360 dev_dbg(&xd->dev, "requesting remote properties\n"); in tb_xdomain_get_properties()
1362 ret = tb_xdp_properties_request(tb->ctl, xd->route, xd->local_uuid, in tb_xdomain_get_properties()
1363 xd->remote_uuid, xd->state_retries, in tb_xdomain_get_properties()
1366 if (xd->state_retries-- > 0) { in tb_xdomain_get_properties()
1367 dev_dbg(&xd->dev, in tb_xdomain_get_properties()
1372 dev_err(&xd->dev, in tb_xdomain_get_properties()
1374 xd->remote_uuid); in tb_xdomain_get_properties()
1380 mutex_lock(&xd->lock); in tb_xdomain_get_properties()
1383 if (xd->remote_properties && gen <= xd->remote_property_block_gen) { in tb_xdomain_get_properties()
1390 dev_err(&xd->dev, "failed to parse XDomain properties\n"); in tb_xdomain_get_properties()
1395 ret = populate_properties(xd, dir); in tb_xdomain_get_properties()
1397 dev_err(&xd->dev, "missing XDomain properties in response\n"); in tb_xdomain_get_properties()
1402 if (xd->remote_properties) { in tb_xdomain_get_properties()
1403 tb_property_free_dir(xd->remote_properties); in tb_xdomain_get_properties()
1407 xd->remote_properties = dir; in tb_xdomain_get_properties()
1408 xd->remote_property_block_gen = gen; in tb_xdomain_get_properties()
1410 tb_xdomain_update_link_attributes(xd); in tb_xdomain_get_properties()
1412 mutex_unlock(&xd->lock); in tb_xdomain_get_properties()
1428 if (xd->bonding_possible) { in tb_xdomain_get_properties()
1431 port = tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_get_properties()
1436 if (device_add(&xd->dev)) { in tb_xdomain_get_properties()
1437 dev_err(&xd->dev, "failed to add XDomain device\n"); in tb_xdomain_get_properties()
1440 dev_info(&xd->dev, "new host found, vendor=%#x device=%#x\n", in tb_xdomain_get_properties()
1441 xd->vendor, xd->device); in tb_xdomain_get_properties()
1442 if (xd->vendor_name && xd->device_name) in tb_xdomain_get_properties()
1443 dev_info(&xd->dev, "%s %s\n", xd->vendor_name, in tb_xdomain_get_properties()
1444 xd->device_name); in tb_xdomain_get_properties()
1446 tb_xdomain_debugfs_init(xd); in tb_xdomain_get_properties()
1448 kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE); in tb_xdomain_get_properties()
1451 enumerate_services(xd); in tb_xdomain_get_properties()
1458 mutex_unlock(&xd->lock); in tb_xdomain_get_properties()
1463 static void tb_xdomain_queue_uuid(struct tb_xdomain *xd) in tb_xdomain_queue_uuid() argument
1465 xd->state = XDOMAIN_STATE_UUID; in tb_xdomain_queue_uuid()
1466 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_uuid()
1467 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_uuid()
1471 static void tb_xdomain_queue_link_status(struct tb_xdomain *xd) in tb_xdomain_queue_link_status() argument
1473 xd->state = XDOMAIN_STATE_LINK_STATUS; in tb_xdomain_queue_link_status()
1474 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_link_status()
1475 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_link_status()
1479 static void tb_xdomain_queue_link_status2(struct tb_xdomain *xd) in tb_xdomain_queue_link_status2() argument
1481 xd->state = XDOMAIN_STATE_LINK_STATUS2; in tb_xdomain_queue_link_status2()
1482 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_link_status2()
1483 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_link_status2()
1487 static void tb_xdomain_queue_bonding(struct tb_xdomain *xd) in tb_xdomain_queue_bonding() argument
1489 if (memcmp(xd->local_uuid, xd->remote_uuid, UUID_SIZE) > 0) { in tb_xdomain_queue_bonding()
1490 dev_dbg(&xd->dev, "we have higher UUID, other side bonds the lanes\n"); in tb_xdomain_queue_bonding()
1491 xd->state = XDOMAIN_STATE_BONDING_UUID_HIGH; in tb_xdomain_queue_bonding()
1493 dev_dbg(&xd->dev, "we have lower UUID, bonding lanes\n"); in tb_xdomain_queue_bonding()
1494 xd->state = XDOMAIN_STATE_LINK_STATE_CHANGE; in tb_xdomain_queue_bonding()
1497 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_bonding()
1498 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_bonding()
1502 static void tb_xdomain_queue_bonding_uuid_low(struct tb_xdomain *xd) in tb_xdomain_queue_bonding_uuid_low() argument
1504 xd->state = XDOMAIN_STATE_BONDING_UUID_LOW; in tb_xdomain_queue_bonding_uuid_low()
1505 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_bonding_uuid_low()
1506 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_bonding_uuid_low()
1510 static void tb_xdomain_queue_properties(struct tb_xdomain *xd) in tb_xdomain_queue_properties() argument
1512 xd->state = XDOMAIN_STATE_PROPERTIES; in tb_xdomain_queue_properties()
1513 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_properties()
1514 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_properties()
1518 static void tb_xdomain_queue_properties_changed(struct tb_xdomain *xd) in tb_xdomain_queue_properties_changed() argument
1520 xd->properties_changed_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_properties_changed()
1521 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work, in tb_xdomain_queue_properties_changed()
1527 struct tb_xdomain *xd = container_of(work, typeof(*xd), state_work.work); in tb_xdomain_state_work() local
1528 int ret, state = xd->state; in tb_xdomain_state_work()
1534 dev_dbg(&xd->dev, "running state %s\n", state_names[state]); in tb_xdomain_state_work()
1538 if (xd->needs_uuid) { in tb_xdomain_state_work()
1539 tb_xdomain_queue_uuid(xd); in tb_xdomain_state_work()
1541 tb_xdomain_queue_properties_changed(xd); in tb_xdomain_state_work()
1542 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1547 ret = tb_xdomain_get_uuid(xd); in tb_xdomain_state_work()
1551 xd->state = XDOMAIN_STATE_ERROR; in tb_xdomain_state_work()
1553 tb_xdomain_queue_properties_changed(xd); in tb_xdomain_state_work()
1554 if (xd->bonding_possible) in tb_xdomain_state_work()
1555 tb_xdomain_queue_link_status(xd); in tb_xdomain_state_work()
1557 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1562 ret = tb_xdomain_get_link_status(xd); in tb_xdomain_state_work()
1572 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1574 tb_xdomain_queue_bonding(xd); in tb_xdomain_state_work()
1579 ret = tb_xdomain_link_state_change(xd, 2); in tb_xdomain_state_work()
1583 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1585 tb_xdomain_queue_link_status2(xd); in tb_xdomain_state_work()
1590 ret = tb_xdomain_get_link_status(xd); in tb_xdomain_state_work()
1594 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1596 tb_xdomain_queue_bonding_uuid_low(xd); in tb_xdomain_state_work()
1601 tb_xdomain_lane_bonding_enable(xd); in tb_xdomain_state_work()
1602 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1606 if (tb_xdomain_bond_lanes_uuid_high(xd) == -EAGAIN) in tb_xdomain_state_work()
1608 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1612 ret = tb_xdomain_get_properties(xd); in tb_xdomain_state_work()
1616 xd->state = XDOMAIN_STATE_ERROR; in tb_xdomain_state_work()
1618 xd->state = XDOMAIN_STATE_ENUMERATED; in tb_xdomain_state_work()
1623 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1630 dev_warn(&xd->dev, "unexpected state %d\n", state); in tb_xdomain_state_work()
1637 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_state_work()
1643 struct tb_xdomain *xd = container_of(work, typeof(*xd), in tb_xdomain_properties_changed() local
1647 dev_dbg(&xd->dev, "sending properties changed notification\n"); in tb_xdomain_properties_changed()
1649 ret = tb_xdp_properties_changed_request(xd->tb->ctl, xd->route, in tb_xdomain_properties_changed()
1650 xd->properties_changed_retries, xd->local_uuid); in tb_xdomain_properties_changed()
1652 if (xd->properties_changed_retries-- > 0) { in tb_xdomain_properties_changed()
1653 dev_dbg(&xd->dev, in tb_xdomain_properties_changed()
1655 queue_delayed_work(xd->tb->wq, in tb_xdomain_properties_changed()
1656 &xd->properties_changed_work, in tb_xdomain_properties_changed()
1659 dev_err(&xd->dev, "failed to send properties changed notification\n"); in tb_xdomain_properties_changed()
1663 xd->properties_changed_retries = XDOMAIN_RETRIES; in tb_xdomain_properties_changed()
1669 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in device_show() local
1671 return sysfs_emit(buf, "%#x\n", xd->device); in device_show()
1678 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in device_name_show() local
1681 if (mutex_lock_interruptible(&xd->lock)) in device_name_show()
1683 ret = sysfs_emit(buf, "%s\n", xd->device_name ?: ""); in device_name_show()
1684 mutex_unlock(&xd->lock); in device_name_show()
1693 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in maxhopid_show() local
1695 return sysfs_emit(buf, "%d\n", xd->remote_max_hopid); in maxhopid_show()
1702 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in vendor_show() local
1704 return sysfs_emit(buf, "%#x\n", xd->vendor); in vendor_show()
1711 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in vendor_name_show() local
1714 if (mutex_lock_interruptible(&xd->lock)) in vendor_name_show()
1716 ret = sysfs_emit(buf, "%s\n", xd->vendor_name ?: ""); in vendor_name_show()
1717 mutex_unlock(&xd->lock); in vendor_name_show()
1726 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in unique_id_show() local
1728 return sysfs_emit(buf, "%pUb\n", xd->remote_uuid); in unique_id_show()
1735 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in speed_show() local
1737 return sysfs_emit(buf, "%u.0 Gb/s\n", xd->link_speed); in speed_show()
1746 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in lanes_show() local
1748 return sysfs_emit(buf, "%u\n", xd->link_width); in lanes_show()
1779 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in tb_xdomain_release() local
1781 put_device(xd->dev.parent); in tb_xdomain_release()
1783 kfree(xd->local_property_block); in tb_xdomain_release()
1784 tb_property_free_dir(xd->remote_properties); in tb_xdomain_release()
1785 ida_destroy(&xd->out_hopids); in tb_xdomain_release()
1786 ida_destroy(&xd->in_hopids); in tb_xdomain_release()
1787 ida_destroy(&xd->service_ids); in tb_xdomain_release()
1789 kfree(xd->local_uuid); in tb_xdomain_release()
1790 kfree(xd->remote_uuid); in tb_xdomain_release()
1791 kfree(xd->device_name); in tb_xdomain_release()
1792 kfree(xd->vendor_name); in tb_xdomain_release()
1793 kfree(xd); in tb_xdomain_release()
1796 static void start_handshake(struct tb_xdomain *xd) in start_handshake() argument
1798 xd->state = XDOMAIN_STATE_INIT; in start_handshake()
1799 queue_delayed_work(xd->tb->wq, &xd->state_work, in start_handshake()
1803 static void stop_handshake(struct tb_xdomain *xd) in stop_handshake() argument
1805 cancel_delayed_work_sync(&xd->properties_changed_work); in stop_handshake()
1806 cancel_delayed_work_sync(&xd->state_work); in stop_handshake()
1807 xd->properties_changed_retries = 0; in stop_handshake()
1808 xd->state_retries = 0; in stop_handshake()
1851 struct tb_xdomain *xd; in tb_xdomain_alloc() local
1858 xd = kzalloc(sizeof(*xd), GFP_KERNEL); in tb_xdomain_alloc()
1859 if (!xd) in tb_xdomain_alloc()
1862 xd->tb = tb; in tb_xdomain_alloc()
1863 xd->route = route; in tb_xdomain_alloc()
1864 xd->local_max_hopid = down->config.max_in_hop_id; in tb_xdomain_alloc()
1865 ida_init(&xd->service_ids); in tb_xdomain_alloc()
1866 ida_init(&xd->in_hopids); in tb_xdomain_alloc()
1867 ida_init(&xd->out_hopids); in tb_xdomain_alloc()
1868 mutex_init(&xd->lock); in tb_xdomain_alloc()
1869 INIT_DELAYED_WORK(&xd->state_work, tb_xdomain_state_work); in tb_xdomain_alloc()
1870 INIT_DELAYED_WORK(&xd->properties_changed_work, in tb_xdomain_alloc()
1873 xd->local_uuid = kmemdup(local_uuid, sizeof(uuid_t), GFP_KERNEL); in tb_xdomain_alloc()
1874 if (!xd->local_uuid) in tb_xdomain_alloc()
1878 xd->remote_uuid = kmemdup(remote_uuid, sizeof(uuid_t), in tb_xdomain_alloc()
1880 if (!xd->remote_uuid) in tb_xdomain_alloc()
1883 xd->needs_uuid = true; in tb_xdomain_alloc()
1884 xd->bonding_possible = !!down->dual_link_port; in tb_xdomain_alloc()
1887 device_initialize(&xd->dev); in tb_xdomain_alloc()
1888 xd->dev.parent = get_device(parent); in tb_xdomain_alloc()
1889 xd->dev.bus = &tb_bus_type; in tb_xdomain_alloc()
1890 xd->dev.type = &tb_xdomain_type; in tb_xdomain_alloc()
1891 xd->dev.groups = xdomain_attr_groups; in tb_xdomain_alloc()
1892 dev_set_name(&xd->dev, "%u-%llx", tb->index, route); in tb_xdomain_alloc()
1894 dev_dbg(&xd->dev, "local UUID %pUb\n", local_uuid); in tb_xdomain_alloc()
1896 dev_dbg(&xd->dev, "remote UUID %pUb\n", remote_uuid); in tb_xdomain_alloc()
1902 pm_runtime_set_active(&xd->dev); in tb_xdomain_alloc()
1903 pm_runtime_get_noresume(&xd->dev); in tb_xdomain_alloc()
1904 pm_runtime_enable(&xd->dev); in tb_xdomain_alloc()
1906 return xd; in tb_xdomain_alloc()
1909 kfree(xd->local_uuid); in tb_xdomain_alloc()
1911 kfree(xd); in tb_xdomain_alloc()
1925 void tb_xdomain_add(struct tb_xdomain *xd) in tb_xdomain_add() argument
1928 start_handshake(xd); in tb_xdomain_add()
1945 void tb_xdomain_remove(struct tb_xdomain *xd) in tb_xdomain_remove() argument
1947 tb_xdomain_debugfs_remove(xd); in tb_xdomain_remove()
1949 stop_handshake(xd); in tb_xdomain_remove()
1951 device_for_each_child_reverse(&xd->dev, xd, unregister_service); in tb_xdomain_remove()
1958 pm_runtime_disable(&xd->dev); in tb_xdomain_remove()
1959 pm_runtime_put_noidle(&xd->dev); in tb_xdomain_remove()
1960 pm_runtime_set_suspended(&xd->dev); in tb_xdomain_remove()
1962 if (!device_is_registered(&xd->dev)) { in tb_xdomain_remove()
1963 put_device(&xd->dev); in tb_xdomain_remove()
1965 dev_info(&xd->dev, "host disconnected\n"); in tb_xdomain_remove()
1966 device_unregister(&xd->dev); in tb_xdomain_remove()
1980 int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd) in tb_xdomain_lane_bonding_enable() argument
1985 port = tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_lane_bonding_enable()
2012 tb_xdomain_update_link_attributes(xd); in tb_xdomain_lane_bonding_enable()
2014 dev_dbg(&xd->dev, "lane bonding enabled\n"); in tb_xdomain_lane_bonding_enable()
2026 void tb_xdomain_lane_bonding_disable(struct tb_xdomain *xd) in tb_xdomain_lane_bonding_disable() argument
2030 port = tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_lane_bonding_disable()
2037 tb_xdomain_update_link_attributes(xd); in tb_xdomain_lane_bonding_disable()
2039 dev_dbg(&xd->dev, "lane bonding disabled\n"); in tb_xdomain_lane_bonding_disable()
2054 int tb_xdomain_alloc_in_hopid(struct tb_xdomain *xd, int hopid) in tb_xdomain_alloc_in_hopid() argument
2058 if (hopid < TB_PATH_MIN_HOPID || hopid > xd->local_max_hopid) in tb_xdomain_alloc_in_hopid()
2061 return ida_alloc_range(&xd->in_hopids, hopid, xd->local_max_hopid, in tb_xdomain_alloc_in_hopid()
2076 int tb_xdomain_alloc_out_hopid(struct tb_xdomain *xd, int hopid) in tb_xdomain_alloc_out_hopid() argument
2080 if (hopid < TB_PATH_MIN_HOPID || hopid > xd->remote_max_hopid) in tb_xdomain_alloc_out_hopid()
2083 return ida_alloc_range(&xd->out_hopids, hopid, xd->remote_max_hopid, in tb_xdomain_alloc_out_hopid()
2093 void tb_xdomain_release_in_hopid(struct tb_xdomain *xd, int hopid) in tb_xdomain_release_in_hopid() argument
2095 ida_free(&xd->in_hopids, hopid); in tb_xdomain_release_in_hopid()
2104 void tb_xdomain_release_out_hopid(struct tb_xdomain *xd, int hopid) in tb_xdomain_release_out_hopid() argument
2106 ida_free(&xd->out_hopids, hopid); in tb_xdomain_release_out_hopid()
2125 int tb_xdomain_enable_paths(struct tb_xdomain *xd, int transmit_path, in tb_xdomain_enable_paths() argument
2129 return tb_domain_approve_xdomain_paths(xd->tb, xd, transmit_path, in tb_xdomain_enable_paths()
2150 int tb_xdomain_disable_paths(struct tb_xdomain *xd, int transmit_path, in tb_xdomain_disable_paths() argument
2154 return tb_domain_disconnect_xdomain_paths(xd->tb, xd, transmit_path, in tb_xdomain_disable_paths()
2173 struct tb_xdomain *xd; in switch_find_xdomain() local
2176 xd = port->xdomain; in switch_find_xdomain()
2179 if (xd->remote_uuid && in switch_find_xdomain()
2180 uuid_equal(xd->remote_uuid, lookup->uuid)) in switch_find_xdomain()
2181 return xd; in switch_find_xdomain()
2183 lookup->link == xd->link && in switch_find_xdomain()
2184 lookup->depth == xd->depth) { in switch_find_xdomain()
2185 return xd; in switch_find_xdomain()
2187 lookup->route == xd->route) { in switch_find_xdomain()
2188 return xd; in switch_find_xdomain()
2191 xd = switch_find_xdomain(port->remote->sw, lookup); in switch_find_xdomain()
2192 if (xd) in switch_find_xdomain()
2193 return xd; in switch_find_xdomain()
2218 struct tb_xdomain *xd; in tb_xdomain_find_by_uuid() local
2223 xd = switch_find_xdomain(tb->root_switch, &lookup); in tb_xdomain_find_by_uuid()
2224 return tb_xdomain_get(xd); in tb_xdomain_find_by_uuid()
2248 struct tb_xdomain *xd; in tb_xdomain_find_by_link_depth() local
2254 xd = switch_find_xdomain(tb->root_switch, &lookup); in tb_xdomain_find_by_link_depth()
2255 return tb_xdomain_get(xd); in tb_xdomain_find_by_link_depth()
2276 struct tb_xdomain *xd; in tb_xdomain_find_by_route() local
2281 xd = switch_find_xdomain(tb->root_switch, &lookup); in tb_xdomain_find_by_route()
2282 return tb_xdomain_get(xd); in tb_xdomain_find_by_route()
2331 struct tb_xdomain *xd; in update_xdomain() local
2333 xd = tb_to_xdomain(dev); in update_xdomain()
2334 if (xd) { in update_xdomain()
2335 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work, in update_xdomain()