Lines Matching +full:0 +full:xd
80 UUID_INIT(0xb638d70e, 0x42ff, 0x40bb,
81 0x97, 0xc2, 0x90, 0xe2, 0xc0, 0xb2, 0xff, 0x07);
125 req->result.err = 0; in tb_xdomain_copy()
154 * @xd: XDomain to send the message
162 * Return: %0 in case of success and negative errno in case of failure
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()
201 * @xd: XDomain to send the request
214 * Return: %0 in case of success and negative errno in case of failure
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()
245 return 0; in tb_xdp_handle_error()
259 return 0; in tb_xdp_handle_error()
269 memset(&req, 0, sizeof(req)); in tb_xdp_uuid_request()
273 memset(&res, 0, sizeof(res)); in tb_xdp_uuid_request()
288 return 0; in tb_xdp_uuid_request()
296 memset(&res, 0, sizeof(res)); in tb_xdp_uuid_response()
313 memset(&res, 0, sizeof(res)); in tb_xdp_error_response()
338 memset(&req, 0, sizeof(req)); in tb_xdp_properties_request()
344 len = 0; in tb_xdp_properties_request()
345 data_len = 0; in tb_xdp_properties_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()
430 return 0; 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()
475 memset(&req, 0, sizeof(req)); in tb_xdp_properties_changed_request()
480 memset(&res, 0, sizeof(res)); in tb_xdp_properties_changed_request()
496 memset(&res, 0, sizeof(res)); in tb_xdp_properties_changed_response()
511 memset(&req, 0, sizeof(req)); in tb_xdp_link_state_status_request()
515 memset(&res, 0, sizeof(res)); in tb_xdp_link_state_status_request()
526 if (res.status != 0) in tb_xdp_link_state_status_request()
534 return 0; in tb_xdp_link_state_status_request()
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()
546 memset(&res, 0, sizeof(res)); in tb_xdp_link_state_status_response()
547 tb_xdp_fill_header(&res.hdr, xd->route, sequence, in tb_xdp_link_state_status_response()
555 res.slw = (val[0] & LANE_ADP_CS_0_SUPPORTED_WIDTH_MASK) >> in tb_xdp_link_state_status_response()
557 res.sls = (val[0] & LANE_ADP_CS_0_SUPPORTED_SPEED_MASK) >> in tb_xdp_link_state_status_response()
574 memset(&req, 0, sizeof(req)); in tb_xdp_link_state_change_request()
580 memset(&res, 0, sizeof(res)); in tb_xdp_link_state_change_request()
591 return res.status != 0 ? -EREMOTEIO : 0; in tb_xdp_link_state_change_request()
599 memset(&res, 0, sizeof(res)); in tb_xdp_link_state_change_response()
629 return 0; in tb_register_protocol_handler()
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()
671 ret = tb_property_format_dir(dir, NULL, 0); in update_property_block()
672 if (ret < 0) { 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
716 int ret = 0; in tb_xdp_handle_request()
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()
793 sequence, 0); 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()
933 return sysfs_emit(buf, "0x%08x\n", svc->prtcstns); in prtcstns_show()
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
991 return 0; in remove_missing_service()
993 if (!tb_property_find(xd->remote_properties, svc->key, in remove_missing_service()
997 return 0; in remove_missing_service()
1007 return 0; in find_service()
1036 return 0; in populate_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()
1074 if (id < 0) { 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()
1131 return 0; 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()
1143 if (ret < 0) 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()
1152 if (ret < 0) 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()
1163 return 0; 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()
1177 if (ret < 0) { 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()
1217 return 0; 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()
1249 return 0; 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()
1291 return 0; 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()
1348 return 0; 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()
1357 u32 gen = 0; 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()
1365 if (ret < 0) { 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()
1384 ret = 0; 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()
1425 port = tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_get_properties()
1429 if (device_add(&xd->dev)) { in tb_xdomain_get_properties()
1430 dev_err(&xd->dev, "failed to add XDomain device\n"); in tb_xdomain_get_properties()
1433 dev_info(&xd->dev, "new host found, vendor=%#x device=%#x\n", in tb_xdomain_get_properties()
1434 xd->vendor, xd->device); in tb_xdomain_get_properties()
1435 if (xd->vendor_name && xd->device_name) in tb_xdomain_get_properties()
1436 dev_info(&xd->dev, "%s %s\n", xd->vendor_name, in tb_xdomain_get_properties()
1437 xd->device_name); in tb_xdomain_get_properties()
1439 tb_xdomain_debugfs_init(xd); in tb_xdomain_get_properties()
1441 kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE); in tb_xdomain_get_properties()
1444 enumerate_services(xd); in tb_xdomain_get_properties()
1445 return 0; in tb_xdomain_get_properties()
1451 mutex_unlock(&xd->lock); in tb_xdomain_get_properties()
1456 static void tb_xdomain_queue_uuid(struct tb_xdomain *xd) in tb_xdomain_queue_uuid() argument
1458 xd->state = XDOMAIN_STATE_UUID; in tb_xdomain_queue_uuid()
1459 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_uuid()
1460 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_uuid()
1464 static void tb_xdomain_queue_link_status(struct tb_xdomain *xd) in tb_xdomain_queue_link_status() argument
1466 xd->state = XDOMAIN_STATE_LINK_STATUS; in tb_xdomain_queue_link_status()
1467 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_link_status()
1468 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_link_status()
1472 static void tb_xdomain_queue_link_status2(struct tb_xdomain *xd) in tb_xdomain_queue_link_status2() argument
1474 xd->state = XDOMAIN_STATE_LINK_STATUS2; in tb_xdomain_queue_link_status2()
1475 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_link_status2()
1476 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_link_status2()
1480 static void tb_xdomain_queue_bonding(struct tb_xdomain *xd) in tb_xdomain_queue_bonding() argument
1482 if (memcmp(xd->local_uuid, xd->remote_uuid, UUID_SIZE) > 0) { in tb_xdomain_queue_bonding()
1483 dev_dbg(&xd->dev, "we have higher UUID, other side bonds the lanes\n"); in tb_xdomain_queue_bonding()
1484 xd->state = XDOMAIN_STATE_BONDING_UUID_HIGH; in tb_xdomain_queue_bonding()
1486 dev_dbg(&xd->dev, "we have lower UUID, bonding lanes\n"); in tb_xdomain_queue_bonding()
1487 xd->state = XDOMAIN_STATE_LINK_STATE_CHANGE; in tb_xdomain_queue_bonding()
1490 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_bonding()
1491 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_bonding()
1495 static void tb_xdomain_queue_bonding_uuid_low(struct tb_xdomain *xd) in tb_xdomain_queue_bonding_uuid_low() argument
1497 xd->state = XDOMAIN_STATE_BONDING_UUID_LOW; in tb_xdomain_queue_bonding_uuid_low()
1498 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_bonding_uuid_low()
1499 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_bonding_uuid_low()
1503 static void tb_xdomain_queue_properties(struct tb_xdomain *xd) in tb_xdomain_queue_properties() argument
1505 xd->state = XDOMAIN_STATE_PROPERTIES; in tb_xdomain_queue_properties()
1506 xd->state_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_properties()
1507 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_queue_properties()
1511 static void tb_xdomain_queue_properties_changed(struct tb_xdomain *xd) in tb_xdomain_queue_properties_changed() argument
1513 xd->properties_changed_retries = XDOMAIN_RETRIES; in tb_xdomain_queue_properties_changed()
1514 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work, in tb_xdomain_queue_properties_changed()
1520 struct tb_xdomain *xd = container_of(work, typeof(*xd), state_work.work); in tb_xdomain_state_work() local
1521 int ret, state = xd->state; in tb_xdomain_state_work()
1527 dev_dbg(&xd->dev, "running state %s\n", state_names[state]); in tb_xdomain_state_work()
1531 if (xd->needs_uuid) { in tb_xdomain_state_work()
1532 tb_xdomain_queue_uuid(xd); in tb_xdomain_state_work()
1534 tb_xdomain_queue_properties_changed(xd); in tb_xdomain_state_work()
1535 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1540 ret = tb_xdomain_get_uuid(xd); in tb_xdomain_state_work()
1544 xd->state = XDOMAIN_STATE_ERROR; in tb_xdomain_state_work()
1546 tb_xdomain_queue_properties_changed(xd); in tb_xdomain_state_work()
1547 if (xd->bonding_possible) in tb_xdomain_state_work()
1548 tb_xdomain_queue_link_status(xd); in tb_xdomain_state_work()
1550 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1555 ret = tb_xdomain_get_link_status(xd); in tb_xdomain_state_work()
1565 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1567 tb_xdomain_queue_bonding(xd); in tb_xdomain_state_work()
1572 ret = tb_xdomain_link_state_change(xd, 2); in tb_xdomain_state_work()
1576 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1578 tb_xdomain_queue_link_status2(xd); in tb_xdomain_state_work()
1583 ret = tb_xdomain_get_link_status(xd); in tb_xdomain_state_work()
1587 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1589 tb_xdomain_queue_bonding_uuid_low(xd); in tb_xdomain_state_work()
1594 tb_xdomain_lane_bonding_enable(xd); in tb_xdomain_state_work()
1595 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1599 if (tb_xdomain_bond_lanes_uuid_high(xd) == -EAGAIN) in tb_xdomain_state_work()
1601 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1605 ret = tb_xdomain_get_properties(xd); in tb_xdomain_state_work()
1609 xd->state = XDOMAIN_STATE_ERROR; in tb_xdomain_state_work()
1611 xd->state = XDOMAIN_STATE_ENUMERATED; in tb_xdomain_state_work()
1616 tb_xdomain_queue_properties(xd); in tb_xdomain_state_work()
1623 dev_warn(&xd->dev, "unexpected state %d\n", state); in tb_xdomain_state_work()
1630 queue_delayed_work(xd->tb->wq, &xd->state_work, in tb_xdomain_state_work()
1636 struct tb_xdomain *xd = container_of(work, typeof(*xd), in tb_xdomain_properties_changed() local
1640 dev_dbg(&xd->dev, "sending properties changed notification\n"); in tb_xdomain_properties_changed()
1642 ret = tb_xdp_properties_changed_request(xd->tb->ctl, xd->route, in tb_xdomain_properties_changed()
1643 xd->properties_changed_retries, xd->local_uuid); in tb_xdomain_properties_changed()
1645 if (xd->properties_changed_retries-- > 0) { in tb_xdomain_properties_changed()
1646 dev_dbg(&xd->dev, in tb_xdomain_properties_changed()
1648 queue_delayed_work(xd->tb->wq, in tb_xdomain_properties_changed()
1649 &xd->properties_changed_work, in tb_xdomain_properties_changed()
1652 dev_err(&xd->dev, "failed to send properties changed notification\n"); in tb_xdomain_properties_changed()
1656 xd->properties_changed_retries = XDOMAIN_RETRIES; in tb_xdomain_properties_changed()
1662 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in device_show() local
1664 return sysfs_emit(buf, "%#x\n", xd->device); in device_show()
1671 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in device_name_show() local
1674 if (mutex_lock_interruptible(&xd->lock)) in device_name_show()
1676 ret = sysfs_emit(buf, "%s\n", xd->device_name ?: ""); in device_name_show()
1677 mutex_unlock(&xd->lock); in device_name_show()
1686 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in maxhopid_show() local
1688 return sysfs_emit(buf, "%d\n", xd->remote_max_hopid); in maxhopid_show()
1695 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in vendor_show() local
1697 return sysfs_emit(buf, "%#x\n", xd->vendor); in vendor_show()
1704 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in vendor_name_show() local
1707 if (mutex_lock_interruptible(&xd->lock)) in vendor_name_show()
1709 ret = sysfs_emit(buf, "%s\n", xd->vendor_name ?: ""); in vendor_name_show()
1710 mutex_unlock(&xd->lock); in vendor_name_show()
1719 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in unique_id_show() local
1721 return sysfs_emit(buf, "%pUb\n", xd->remote_uuid); in unique_id_show()
1728 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in speed_show() local
1730 return sysfs_emit(buf, "%u.0 Gb/s\n", xd->link_speed); in speed_show()
1739 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in lanes_show() local
1741 return sysfs_emit(buf, "%u\n", xd->link_width); in lanes_show()
1772 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev); in tb_xdomain_release() local
1774 put_device(xd->dev.parent); in tb_xdomain_release()
1776 kfree(xd->local_property_block); in tb_xdomain_release()
1777 tb_property_free_dir(xd->remote_properties); in tb_xdomain_release()
1778 ida_destroy(&xd->out_hopids); in tb_xdomain_release()
1779 ida_destroy(&xd->in_hopids); in tb_xdomain_release()
1780 ida_destroy(&xd->service_ids); in tb_xdomain_release()
1782 kfree(xd->local_uuid); in tb_xdomain_release()
1783 kfree(xd->remote_uuid); in tb_xdomain_release()
1784 kfree(xd->device_name); in tb_xdomain_release()
1785 kfree(xd->vendor_name); in tb_xdomain_release()
1786 kfree(xd); in tb_xdomain_release()
1789 static void start_handshake(struct tb_xdomain *xd) in start_handshake() argument
1791 xd->state = XDOMAIN_STATE_INIT; in start_handshake()
1792 queue_delayed_work(xd->tb->wq, &xd->state_work, in start_handshake()
1796 static void stop_handshake(struct tb_xdomain *xd) in stop_handshake() argument
1798 cancel_delayed_work_sync(&xd->properties_changed_work); in stop_handshake()
1799 cancel_delayed_work_sync(&xd->state_work); in stop_handshake()
1800 xd->properties_changed_retries = 0; in stop_handshake()
1801 xd->state_retries = 0; in stop_handshake()
1807 return 0; in tb_xdomain_suspend()
1813 return 0; in tb_xdomain_resume()
1844 struct tb_xdomain *xd; in tb_xdomain_alloc() local
1851 xd = kzalloc(sizeof(*xd), GFP_KERNEL); in tb_xdomain_alloc()
1852 if (!xd) in tb_xdomain_alloc()
1855 xd->tb = tb; in tb_xdomain_alloc()
1856 xd->route = route; in tb_xdomain_alloc()
1857 xd->local_max_hopid = down->config.max_in_hop_id; in tb_xdomain_alloc()
1858 ida_init(&xd->service_ids); in tb_xdomain_alloc()
1859 ida_init(&xd->in_hopids); in tb_xdomain_alloc()
1860 ida_init(&xd->out_hopids); in tb_xdomain_alloc()
1861 mutex_init(&xd->lock); in tb_xdomain_alloc()
1862 INIT_DELAYED_WORK(&xd->state_work, tb_xdomain_state_work); in tb_xdomain_alloc()
1863 INIT_DELAYED_WORK(&xd->properties_changed_work, in tb_xdomain_alloc()
1866 xd->local_uuid = kmemdup(local_uuid, sizeof(uuid_t), GFP_KERNEL); in tb_xdomain_alloc()
1867 if (!xd->local_uuid) in tb_xdomain_alloc()
1871 xd->remote_uuid = kmemdup(remote_uuid, sizeof(uuid_t), in tb_xdomain_alloc()
1873 if (!xd->remote_uuid) in tb_xdomain_alloc()
1876 xd->needs_uuid = true; in tb_xdomain_alloc()
1877 xd->bonding_possible = !!down->dual_link_port; in tb_xdomain_alloc()
1880 device_initialize(&xd->dev); in tb_xdomain_alloc()
1881 xd->dev.parent = get_device(parent); in tb_xdomain_alloc()
1882 xd->dev.bus = &tb_bus_type; in tb_xdomain_alloc()
1883 xd->dev.type = &tb_xdomain_type; in tb_xdomain_alloc()
1884 xd->dev.groups = xdomain_attr_groups; in tb_xdomain_alloc()
1885 dev_set_name(&xd->dev, "%u-%llx", tb->index, route); in tb_xdomain_alloc()
1887 dev_dbg(&xd->dev, "local UUID %pUb\n", local_uuid); in tb_xdomain_alloc()
1889 dev_dbg(&xd->dev, "remote UUID %pUb\n", remote_uuid); in tb_xdomain_alloc()
1895 pm_runtime_set_active(&xd->dev); in tb_xdomain_alloc()
1896 pm_runtime_get_noresume(&xd->dev); in tb_xdomain_alloc()
1897 pm_runtime_enable(&xd->dev); in tb_xdomain_alloc()
1899 return xd; in tb_xdomain_alloc()
1902 kfree(xd->local_uuid); in tb_xdomain_alloc()
1904 kfree(xd); in tb_xdomain_alloc()
1911 * @xd: XDomain to add
1918 void tb_xdomain_add(struct tb_xdomain *xd) in tb_xdomain_add() argument
1921 start_handshake(xd); in tb_xdomain_add()
1927 return 0; in unregister_service()
1932 * @xd: XDomain to remove
1935 * along with any services from the bus. When the last reference to @xd
1938 void tb_xdomain_remove(struct tb_xdomain *xd) in tb_xdomain_remove() argument
1940 tb_xdomain_debugfs_remove(xd); in tb_xdomain_remove()
1942 stop_handshake(xd); in tb_xdomain_remove()
1944 device_for_each_child_reverse(&xd->dev, xd, unregister_service); in tb_xdomain_remove()
1951 pm_runtime_disable(&xd->dev); in tb_xdomain_remove()
1952 pm_runtime_put_noidle(&xd->dev); in tb_xdomain_remove()
1953 pm_runtime_set_suspended(&xd->dev); in tb_xdomain_remove()
1955 if (!device_is_registered(&xd->dev)) { in tb_xdomain_remove()
1956 put_device(&xd->dev); in tb_xdomain_remove()
1958 dev_info(&xd->dev, "host disconnected\n"); in tb_xdomain_remove()
1959 device_unregister(&xd->dev); in tb_xdomain_remove()
1965 * @xd: XDomain connection
1971 * Return: %0 in case of success and negative errno in case of error.
1973 int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd) in tb_xdomain_lane_bonding_enable() argument
1978 port = tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_lane_bonding_enable()
1987 if (ret < 0) in tb_xdomain_lane_bonding_enable()
2005 tb_xdomain_update_link_attributes(xd); in tb_xdomain_lane_bonding_enable()
2007 dev_dbg(&xd->dev, "lane bonding enabled\n"); in tb_xdomain_lane_bonding_enable()
2008 return 0; in tb_xdomain_lane_bonding_enable()
2014 * @xd: XDomain connection
2019 void tb_xdomain_lane_bonding_disable(struct tb_xdomain *xd) in tb_xdomain_lane_bonding_disable() argument
2023 port = tb_port_at(xd->route, tb_xdomain_parent(xd)); in tb_xdomain_lane_bonding_disable()
2030 tb_xdomain_update_link_attributes(xd); in tb_xdomain_lane_bonding_disable()
2032 dev_dbg(&xd->dev, "lane bonding disabled\n"); in tb_xdomain_lane_bonding_disable()
2039 * @xd: XDomain connection
2047 int tb_xdomain_alloc_in_hopid(struct tb_xdomain *xd, int hopid) in tb_xdomain_alloc_in_hopid() argument
2049 if (hopid < 0) in tb_xdomain_alloc_in_hopid()
2051 if (hopid < TB_PATH_MIN_HOPID || hopid > xd->local_max_hopid) in tb_xdomain_alloc_in_hopid()
2054 return ida_alloc_range(&xd->in_hopids, hopid, xd->local_max_hopid, in tb_xdomain_alloc_in_hopid()
2061 * @xd: XDomain connection
2069 int tb_xdomain_alloc_out_hopid(struct tb_xdomain *xd, int hopid) in tb_xdomain_alloc_out_hopid() argument
2071 if (hopid < 0) in tb_xdomain_alloc_out_hopid()
2073 if (hopid < TB_PATH_MIN_HOPID || hopid > xd->remote_max_hopid) in tb_xdomain_alloc_out_hopid()
2076 return ida_alloc_range(&xd->out_hopids, hopid, xd->remote_max_hopid, in tb_xdomain_alloc_out_hopid()
2083 * @xd: XDomain connection
2086 void tb_xdomain_release_in_hopid(struct tb_xdomain *xd, int hopid) in tb_xdomain_release_in_hopid() argument
2088 ida_free(&xd->in_hopids, hopid); in tb_xdomain_release_in_hopid()
2094 * @xd: XDomain connection
2097 void tb_xdomain_release_out_hopid(struct tb_xdomain *xd, int hopid) in tb_xdomain_release_out_hopid() argument
2099 ida_free(&xd->out_hopids, hopid); in tb_xdomain_release_out_hopid()
2105 * @xd: XDomain connection
2116 * Return: %0 in case of success and negative errno in case of error
2118 int tb_xdomain_enable_paths(struct tb_xdomain *xd, int transmit_path, in tb_xdomain_enable_paths() argument
2122 return tb_domain_approve_xdomain_paths(xd->tb, xd, transmit_path, in tb_xdomain_enable_paths()
2130 * @xd: XDomain connection
2141 * Return: %0 in case of success and negative errno in case of error
2143 int tb_xdomain_disable_paths(struct tb_xdomain *xd, int transmit_path, in tb_xdomain_disable_paths() argument
2147 return tb_domain_disconnect_xdomain_paths(xd->tb, xd, transmit_path, in tb_xdomain_disable_paths()
2166 struct tb_xdomain *xd; in switch_find_xdomain() local
2169 xd = port->xdomain; in switch_find_xdomain()
2172 if (xd->remote_uuid && in switch_find_xdomain()
2173 uuid_equal(xd->remote_uuid, lookup->uuid)) in switch_find_xdomain()
2174 return xd; in switch_find_xdomain()
2176 lookup->link == xd->link && in switch_find_xdomain()
2177 lookup->depth == xd->depth) { in switch_find_xdomain()
2178 return xd; in switch_find_xdomain()
2180 lookup->route == xd->route) { in switch_find_xdomain()
2181 return xd; in switch_find_xdomain()
2184 xd = switch_find_xdomain(port->remote->sw, lookup); in switch_find_xdomain()
2185 if (xd) in switch_find_xdomain()
2186 return xd; in switch_find_xdomain()
2211 struct tb_xdomain *xd; in tb_xdomain_find_by_uuid() local
2213 memset(&lookup, 0, sizeof(lookup)); in tb_xdomain_find_by_uuid()
2216 xd = switch_find_xdomain(tb->root_switch, &lookup); in tb_xdomain_find_by_uuid()
2217 return tb_xdomain_get(xd); in tb_xdomain_find_by_uuid()
2241 struct tb_xdomain *xd; in tb_xdomain_find_by_link_depth() local
2243 memset(&lookup, 0, sizeof(lookup)); in tb_xdomain_find_by_link_depth()
2247 xd = switch_find_xdomain(tb->root_switch, &lookup); in tb_xdomain_find_by_link_depth()
2248 return tb_xdomain_get(xd); in tb_xdomain_find_by_link_depth()
2269 struct tb_xdomain *xd; in tb_xdomain_find_by_route() local
2271 memset(&lookup, 0, sizeof(lookup)); in tb_xdomain_find_by_route()
2274 xd = switch_find_xdomain(tb->root_switch, &lookup); in tb_xdomain_find_by_route()
2275 return tb_xdomain_get(xd); in tb_xdomain_find_by_route()
2285 int ret = 0; in tb_xdomain_handle_request()
2319 return ret > 0; in tb_xdomain_handle_request()
2324 struct tb_xdomain *xd; in update_xdomain() local
2326 xd = tb_to_xdomain(dev); in update_xdomain()
2327 if (xd) { in update_xdomain()
2328 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work, in update_xdomain()
2332 return 0; in update_xdomain()
2363 * Return: %0 on success and negative errno on failure
2390 return 0; in tb_register_property_dir()
2408 int ret = 0; in tb_unregister_property_dir()
2437 tb_property_add_immediate(xdomain_property_dir, "deviceid", 0x1); in tb_xdomain_init()
2438 tb_property_add_immediate(xdomain_property_dir, "devicerv", 0x80000100); in tb_xdomain_init()
2441 return 0; in tb_xdomain_init()