Lines Matching refs:xd

114  * @xd: XDomain to send the message
124 int tb_xdomain_response(struct tb_xdomain *xd, const void *response,
127 return __tb_xdomain_response(xd->tb->ctl, response, size, type);
161 * @xd: XDomain to send the request
176 int tb_xdomain_request(struct tb_xdomain *xd, const void *request,
181 return __tb_xdomain_request(xd->tb->ctl, request, request_size,
592 struct tb_xdomain *xd;
601 xd = tb_xdomain_find_by_uuid_locked(tb, &xchg->src_uuid);
602 if (xd) {
603 queue_delayed_work(tb->wq, &xd->get_properties_work,
605 tb_xdomain_put(xd);
778 struct tb_xdomain *xd = tb_service_parent(svc);
780 ida_simple_remove(&xd->service_ids, svc->id);
795 struct tb_xdomain *xd = data;
802 if (!tb_property_find(xd->properties, svc->key,
848 static void enumerate_services(struct tb_xdomain *xd)
859 device_for_each_child_reverse(&xd->dev, xd, remove_missing_service);
862 tb_property_for_each(xd->properties, p) {
867 dev = device_find_child(&xd->dev, p, find_service);
882 id = ida_simple_get(&xd->service_ids, 0, 0, GFP_KERNEL);
891 svc->dev.parent = &xd->dev;
892 dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev), svc->id);
901 static int populate_properties(struct tb_xdomain *xd,
910 xd->device = p->value.immediate;
915 xd->vendor = p->value.immediate;
917 kfree(xd->device_name);
918 xd->device_name = NULL;
919 kfree(xd->vendor_name);
920 xd->vendor_name = NULL;
925 xd->device_name = kstrdup(p->value.text, GFP_KERNEL);
928 xd->vendor_name = kstrdup(p->value.text, GFP_KERNEL);
933 /* Called with @xd->lock held */
934 static void tb_xdomain_restore_paths(struct tb_xdomain *xd)
936 if (!xd->resume)
939 xd->resume = false;
940 if (xd->transmit_path) {
941 dev_dbg(&xd->dev, "re-establishing DMA path\n");
942 tb_domain_approve_xdomain_paths(xd->tb, xd);
948 struct tb_xdomain *xd = container_of(work, typeof(*xd),
950 struct tb *tb = xd->tb;
954 ret = tb_xdp_uuid_request(tb->ctl, xd->route, xd->uuid_retries, &uuid);
956 if (xd->uuid_retries-- > 0) {
957 queue_delayed_work(xd->tb->wq, &xd->get_uuid_work,
960 dev_dbg(&xd->dev, "failed to read remote UUID\n");
965 if (uuid_equal(&uuid, xd->local_uuid)) {
966 dev_dbg(&xd->dev, "intra-domain loop detected\n");
975 if (xd->remote_uuid && !uuid_equal(&uuid, xd->remote_uuid)) {
976 dev_dbg(&xd->dev, "remote UUID is different, unplugging\n");
977 xd->is_unplugged = true;
982 if (!xd->remote_uuid) {
983 xd->remote_uuid = kmemdup(&uuid, sizeof(uuid_t), GFP_KERNEL);
984 if (!xd->remote_uuid)
989 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work,
991 queue_delayed_work(xd->tb->wq, &xd->get_properties_work,
997 struct tb_xdomain *xd = container_of(work, typeof(*xd),
1000 struct tb *tb = xd->tb;
1006 ret = tb_xdp_properties_request(tb->ctl, xd->route, xd->local_uuid,
1007 xd->remote_uuid, xd->properties_retries,
1010 if (xd->properties_retries-- > 0) {
1011 queue_delayed_work(xd->tb->wq, &xd->get_properties_work,
1015 dev_err(&xd->dev,
1017 xd->remote_uuid);
1022 xd->properties_retries = XDOMAIN_PROPERTIES_RETRIES;
1024 mutex_lock(&xd->lock);
1027 if (xd->properties && gen <= xd->property_block_gen) {
1034 tb_xdomain_restore_paths(xd);
1040 dev_err(&xd->dev, "failed to parse XDomain properties\n");
1044 ret = populate_properties(xd, dir);
1046 dev_err(&xd->dev, "missing XDomain properties in response\n");
1051 if (xd->properties) {
1052 tb_property_free_dir(xd->properties);
1056 xd->properties = dir;
1057 xd->property_block_gen = gen;
1059 tb_xdomain_restore_paths(xd);
1061 mutex_unlock(&xd->lock);
1071 if (device_add(&xd->dev)) {
1072 dev_err(&xd->dev, "failed to add XDomain device\n");
1076 kobject_uevent(&xd->dev.kobj, KOBJ_CHANGE);
1079 enumerate_services(xd);
1086 mutex_unlock(&xd->lock);
1091 struct tb_xdomain *xd = container_of(work, typeof(*xd),
1095 ret = tb_xdp_properties_changed_request(xd->tb->ctl, xd->route,
1096 xd->properties_changed_retries, xd->local_uuid);
1098 if (xd->properties_changed_retries-- > 0)
1099 queue_delayed_work(xd->tb->wq,
1100 &xd->properties_changed_work,
1105 xd->properties_changed_retries = XDOMAIN_PROPERTIES_CHANGED_RETRIES;
1111 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1113 return sprintf(buf, "%#x\n", xd->device);
1120 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1123 if (mutex_lock_interruptible(&xd->lock))
1125 ret = sprintf(buf, "%s\n", xd->device_name ? xd->device_name : "");
1126 mutex_unlock(&xd->lock);
1135 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1137 return sprintf(buf, "%#x\n", xd->vendor);
1144 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1147 if (mutex_lock_interruptible(&xd->lock))
1149 ret = sprintf(buf, "%s\n", xd->vendor_name ? xd->vendor_name : "");
1150 mutex_unlock(&xd->lock);
1159 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1161 return sprintf(buf, "%pUb\n", xd->remote_uuid);
1185 struct tb_xdomain *xd = container_of(dev, struct tb_xdomain, dev);
1187 put_device(xd->dev.parent);
1189 tb_property_free_dir(xd->properties);
1190 ida_destroy(&xd->service_ids);
1192 kfree(xd->local_uuid);
1193 kfree(xd->remote_uuid);
1194 kfree(xd->device_name);
1195 kfree(xd->vendor_name);
1196 kfree(xd);
1199 static void start_handshake(struct tb_xdomain *xd)
1201 xd->uuid_retries = XDOMAIN_UUID_RETRIES;
1202 xd->properties_retries = XDOMAIN_PROPERTIES_RETRIES;
1203 xd->properties_changed_retries = XDOMAIN_PROPERTIES_CHANGED_RETRIES;
1205 if (xd->needs_uuid) {
1206 queue_delayed_work(xd->tb->wq, &xd->get_uuid_work,
1210 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work,
1212 queue_delayed_work(xd->tb->wq, &xd->get_properties_work,
1217 static void stop_handshake(struct tb_xdomain *xd)
1219 xd->uuid_retries = 0;
1220 xd->properties_retries = 0;
1221 xd->properties_changed_retries = 0;
1223 cancel_delayed_work_sync(&xd->get_uuid_work);
1224 cancel_delayed_work_sync(&xd->get_properties_work);
1225 cancel_delayed_work_sync(&xd->properties_changed_work);
1236 struct tb_xdomain *xd = tb_to_xdomain(dev);
1242 xd->resume = true;
1243 start_handshake(xd);
1276 struct tb_xdomain *xd;
1283 xd = kzalloc(sizeof(*xd), GFP_KERNEL);
1284 if (!xd)
1287 xd->tb = tb;
1288 xd->route = route;
1289 ida_init(&xd->service_ids);
1290 mutex_init(&xd->lock);
1291 INIT_DELAYED_WORK(&xd->get_uuid_work, tb_xdomain_get_uuid);
1292 INIT_DELAYED_WORK(&xd->get_properties_work, tb_xdomain_get_properties);
1293 INIT_DELAYED_WORK(&xd->properties_changed_work,
1296 xd->local_uuid = kmemdup(local_uuid, sizeof(uuid_t), GFP_KERNEL);
1297 if (!xd->local_uuid)
1301 xd->remote_uuid = kmemdup(remote_uuid, sizeof(uuid_t),
1303 if (!xd->remote_uuid)
1306 xd->needs_uuid = true;
1309 device_initialize(&xd->dev);
1310 xd->dev.parent = get_device(parent);
1311 xd->dev.bus = &tb_bus_type;
1312 xd->dev.type = &tb_xdomain_type;
1313 xd->dev.groups = xdomain_attr_groups;
1314 dev_set_name(&xd->dev, "%u-%llx", tb->index, route);
1320 pm_runtime_set_active(&xd->dev);
1321 pm_runtime_get_noresume(&xd->dev);
1322 pm_runtime_enable(&xd->dev);
1324 return xd;
1327 kfree(xd->local_uuid);
1329 kfree(xd);
1336 * @xd: XDomain to add
1343 void tb_xdomain_add(struct tb_xdomain *xd)
1346 start_handshake(xd);
1357 * @xd: XDomain to remove
1360 * along with any services from the bus. When the last reference to @xd
1363 void tb_xdomain_remove(struct tb_xdomain *xd)
1365 stop_handshake(xd);
1367 device_for_each_child_reverse(&xd->dev, xd, unregister_service);
1374 pm_runtime_disable(&xd->dev);
1375 pm_runtime_put_noidle(&xd->dev);
1376 pm_runtime_set_suspended(&xd->dev);
1378 if (!device_is_registered(&xd->dev))
1379 put_device(&xd->dev);
1381 device_unregister(&xd->dev);
1386 * @xd: XDomain connection
1400 int tb_xdomain_enable_paths(struct tb_xdomain *xd, u16 transmit_path,
1406 mutex_lock(&xd->lock);
1408 if (xd->transmit_path) {
1409 ret = xd->transmit_path == transmit_path ? 0 : -EBUSY;
1413 xd->transmit_path = transmit_path;
1414 xd->transmit_ring = transmit_ring;
1415 xd->receive_path = receive_path;
1416 xd->receive_ring = receive_ring;
1418 ret = tb_domain_approve_xdomain_paths(xd->tb, xd);
1421 mutex_unlock(&xd->lock);
1429 * @xd: XDomain connection
1436 int tb_xdomain_disable_paths(struct tb_xdomain *xd)
1440 mutex_lock(&xd->lock);
1441 if (xd->transmit_path) {
1442 xd->transmit_path = 0;
1443 xd->transmit_ring = 0;
1444 xd->receive_path = 0;
1445 xd->receive_ring = 0;
1447 ret = tb_domain_disconnect_xdomain_paths(xd->tb, xd);
1449 mutex_unlock(&xd->lock);
1468 struct tb_xdomain *xd;
1471 xd = port->xdomain;
1474 if (xd->remote_uuid &&
1475 uuid_equal(xd->remote_uuid, lookup->uuid))
1476 return xd;
1478 lookup->link == xd->link &&
1479 lookup->depth == xd->depth) {
1480 return xd;
1482 lookup->route == xd->route) {
1483 return xd;
1486 xd = switch_find_xdomain(port->remote->sw, lookup);
1487 if (xd)
1488 return xd;
1513 struct tb_xdomain *xd;
1518 xd = switch_find_xdomain(tb->root_switch, &lookup);
1519 return tb_xdomain_get(xd);
1543 struct tb_xdomain *xd;
1549 xd = switch_find_xdomain(tb->root_switch, &lookup);
1550 return tb_xdomain_get(xd);
1571 struct tb_xdomain *xd;
1576 xd = switch_find_xdomain(tb->root_switch, &lookup);
1577 return tb_xdomain_get(xd);
1626 struct tb_xdomain *xd;
1628 xd = tb_to_xdomain(dev);
1629 if (xd) {
1630 queue_delayed_work(xd->tb->wq, &xd->properties_changed_work,