/* * Serializes access to the properties and protocol handlers below. If * you need to take both this lock and the struct tb_xdomain lock, take * this one first.
*/ static DEFINE_MUTEX(xdomain_lock);
/* Properties exposed to the remote domains */ staticstruct tb_property_dir *xdomain_property_dir; static u32 xdomain_property_block_gen;
/** * tb_xdomain_response() - Send a XDomain response message * @xd: XDomain to send the message * @response: Response to send * @size: Size of the response * @type: PDF type of the response * * This can be used to send a XDomain response message to the other * domain. No response for the message is expected. * * Return: %0 in case of success and negative errno in case of failure
*/ int tb_xdomain_response(struct tb_xdomain *xd, constvoid *response,
size_t size, enum tb_cfg_pkg_type type)
{ return __tb_xdomain_response(xd->tb->ctl, response, size, type);
}
EXPORT_SYMBOL_GPL(tb_xdomain_response);
res = tb_cfg_request_sync(ctl, req, timeout_msec);
tb_cfg_request_put(req);
return res.err == 1 ? -EIO : res.err;
}
/** * tb_xdomain_request() - Send a XDomain request * @xd: XDomain to send the request * @request: Request to send * @request_size: Size of the request in bytes * @request_type: PDF type of the request * @response: Response is copied here * @response_size: Expected size of the response in bytes * @response_type: Expected PDF type of the response * @timeout_msec: Timeout in milliseconds to wait for the response * * This function can be used to send XDomain control channel messages to * the other domain. The function waits until the response is received * or when timeout triggers. Whichever comes first. * * Return: %0 in case of success and negative errno in case of failure
*/ int tb_xdomain_request(struct tb_xdomain *xd, constvoid *request,
size_t request_size, enum tb_cfg_pkg_type request_type, void *response, size_t response_size, enum tb_cfg_pkg_type response_type, unsignedint timeout_msec)
{ return __tb_xdomain_request(xd->tb->ctl, request, request_size,
request_type, response, response_size,
response_type, timeout_msec);
}
EXPORT_SYMBOL_GPL(tb_xdomain_request);
switch (res->error) { case ERROR_UNKNOWN_PACKET: case ERROR_UNKNOWN_DOMAIN: return -EIO; case ERROR_NOT_SUPPORTED: return -EOPNOTSUPP; case ERROR_NOT_READY: return -EAGAIN; default: break;
}
do {
ret = __tb_xdomain_request(ctl, &req, sizeof(req),
TB_CFG_PKG_XDOMAIN_REQ, res,
total_size, TB_CFG_PKG_XDOMAIN_RESP,
XDOMAIN_DEFAULT_TIMEOUT); if (ret) goto err;
ret = tb_xdp_handle_error(&res->err); if (ret) goto err;
/* * Package length includes the whole payload without the * XDomain header. Validate first that the package is at * least size of the response structure.
*/
len = res->hdr.xd_hdr.length_sn & TB_XDOMAIN_LENGTH_MASK; if (len < sizeof(*res) / 4) {
ret = -EINVAL; goto err;
}
len += sizeof(res->hdr.xd_hdr) / 4;
len -= sizeof(*res) / 4;
if (res->offset != req.offset) {
ret = -EINVAL; goto err;
}
/* * First time allocate block that has enough space for * the whole properties block.
*/ if (!data) {
data_len = res->data_length; if (data_len > TB_XDP_PROPERTIES_MAX_LENGTH) {
ret = -E2BIG; goto err;
}
data = kcalloc(data_len, sizeof(u32), GFP_KERNEL); if (!data) {
ret = -ENOMEM; goto err;
}
}
memcpy(data + req.offset, res->data, len * 4);
req.offset += len;
} while (!data_len || req.offset < data_len);
/* * Currently we expect all requests to be directed to us. The * protocol supports forwarding, though which we might add * support later on.
*/ if (!uuid_equal(xd->local_uuid, &req->dst_uuid)) {
tb_xdp_error_response(ctl, xd->route, sequence,
ERROR_UNKNOWN_DOMAIN); return 0;
}
mutex_lock(&xd->lock);
if (req->offset >= xd->local_property_block_len) {
mutex_unlock(&xd->lock); return -EINVAL;
}
len = xd->local_property_block_len - req->offset;
len = min_t(u16, len, TB_XDP_PROPERTIES_MAX_DATA_LENGTH);
total_size = sizeof(*res) + len * 4;
res = kzalloc(total_size, GFP_KERNEL); if (!res) {
mutex_unlock(&xd->lock); return -ENOMEM;
}
/** * tb_register_protocol_handler() - Register protocol handler * @handler: Handler to register * * This allows XDomain service drivers to hook into incoming XDomain * messages. After this function is called the service driver needs to * be able to handle calls to callback whenever a package with the * registered protocol is received.
*/ int tb_register_protocol_handler(struct tb_protocol_handler *handler)
{ if (!handler->uuid || !handler->callback) return -EINVAL; if (uuid_equal(handler->uuid, &tb_xdp_uuid)) return -EINVAL;
staticvoid update_property_block(struct tb_xdomain *xd)
{
mutex_lock(&xdomain_lock);
mutex_lock(&xd->lock); /* * If the local property block is not up-to-date, rebuild it now * based on the global property template.
*/ if (!xd->local_property_block ||
xd->local_property_block_gen < xdomain_property_block_gen) { struct tb_property_dir *dir; int ret, block_len;
u32 *block;
dir = tb_property_copy_dir(xdomain_property_dir); if (!dir) {
dev_warn(&xd->dev, "failed to copy properties\n"); goto out_unlock;
}
/* Fill in non-static properties now */
tb_property_add_text(dir, "deviceid", utsname()->nodename);
tb_property_add_immediate(dir, "maxhopid", xd->local_max_hopid);
ret = tb_property_format_dir(dir, NULL, 0); if (ret < 0) {
dev_warn(&xd->dev, "local property block creation failed\n");
tb_property_free_dir(dir); goto out_unlock;
}
/* Can be called from state_work */ staticvoid __stop_handshake(struct tb_xdomain *xd)
{
cancel_delayed_work_sync(&xd->properties_changed_work);
xd->properties_changed_retries = 0;
xd->state_retries = 0;
}
if (!uuid) {
tb_xdp_error_response(ctl, route, sequence, ERROR_NOT_READY); goto out;
}
xd = tb_xdomain_find_by_route_locked(tb, route); if (xd)
update_property_block(xd);
switch (pkg->type) { case PROPERTIES_REQUEST:
tb_dbg(tb, "%llx: received XDomain properties request\n", route); if (xd) {
ret = tb_xdp_properties_response(tb, ctl, xd, sequence,
(conststruct tb_xdp_properties *)pkg);
} break;
case PROPERTIES_CHANGED_REQUEST:
tb_dbg(tb, "%llx: received XDomain properties changed request\n",
route);
ret = tb_xdp_properties_changed_response(ctl, route, sequence);
/* * Since the properties have been changed, let's update * the xdomain related to this connection as well in * case there is a change in services it offers.
*/ if (xd && device_is_registered(&xd->dev))
queue_delayed_work(tb->wq, &xd->state_work,
msecs_to_jiffies(XDOMAIN_SHORT_TIMEOUT)); break;
case UUID_REQUEST_OLD: case UUID_REQUEST:
tb_dbg(tb, "%llx: received XDomain UUID request\n", route);
ret = tb_xdp_uuid_response(ctl, route, sequence, uuid); /* * If we've stopped the discovery with an error such as * timing out, we will restart the handshake now that we * received UUID request from the remote host.
*/ if (!ret && xd && xd->state == XDOMAIN_STATE_ERROR) {
dev_dbg(&xd->dev, "restarting handshake\n");
start_handshake(xd);
} break;
case LINK_STATE_STATUS_REQUEST:
tb_dbg(tb, "%llx: received XDomain link state status request\n",
route);
if (xd) {
ret = tb_xdp_link_state_status_response(tb, ctl, xd,
sequence);
} else {
tb_xdp_error_response(ctl, route, sequence,
ERROR_NOT_READY);
} break;
case LINK_STATE_CHANGE_REQUEST:
tb_dbg(tb, "%llx: received XDomain link state change request\n",
route);
/** * tb_register_service_driver() - Register XDomain service driver * @drv: Driver to register * * Registers new service driver from @drv to the bus.
*/ int tb_register_service_driver(struct tb_service_driver *drv)
{
drv->driver.bus = &tb_bus_type; return driver_register(&drv->driver);
}
EXPORT_SYMBOL_GPL(tb_register_service_driver);
/** * tb_unregister_service_driver() - Unregister XDomain service driver * @drv: Driver to unregister * * Unregisters XDomain service driver from the bus.
*/ void tb_unregister_service_driver(struct tb_service_driver *drv)
{
driver_unregister(&drv->driver);
}
EXPORT_SYMBOL_GPL(tb_unregister_service_driver);
/* * It should be null terminated but anything else is pretty much * allowed.
*/ return sysfs_emit(buf, "%*pE\n", (int)strlen(svc->key), svc->key);
} static DEVICE_ATTR_RO(key);
/* Fill in standard properties */
p = tb_property_find(dir, "prtcid", TB_PROPERTY_TYPE_VALUE); if (p)
svc->prtcid = p->value.immediate;
p = tb_property_find(dir, "prtcvers", TB_PROPERTY_TYPE_VALUE); if (p)
svc->prtcvers = p->value.immediate;
p = tb_property_find(dir, "prtcrevs", TB_PROPERTY_TYPE_VALUE); if (p)
svc->prtcrevs = p->value.immediate;
p = tb_property_find(dir, "prtcstns", TB_PROPERTY_TYPE_VALUE); if (p)
svc->prtcstns = p->value.immediate;
svc->key = kstrdup(property->key, GFP_KERNEL); if (!svc->key) return -ENOMEM;
/* * First remove all services that are not available anymore in * the updated property block.
*/
device_for_each_child_reverse(&xd->dev, xd, remove_missing_service);
/* Then re-enumerate properties creating new services as we go */
tb_property_for_each(xd->remote_properties, p) { if (p->type != TB_PROPERTY_TYPE_DIRECTORY) continue;
/* If the service exists already we are fine */
dev = device_find_child(&xd->dev, p, find_service); if (dev) {
put_device(dev); continue;
}
svc = kzalloc(sizeof(*svc), GFP_KERNEL); if (!svc) break;
if (populate_service(svc, p)) {
kfree(svc); break;
}
id = ida_alloc(&xd->service_ids, GFP_KERNEL); if (id < 0) {
kfree(svc->key);
kfree(svc); break;
}
svc->id = id;
svc->dev.bus = &tb_bus_type;
svc->dev.type = &tb_service_type;
svc->dev.parent = &xd->dev;
dev_set_name(&svc->dev, "%s.%d", dev_name(&xd->dev), svc->id);
tb_service_debugfs_init(svc);
if (device_register(&svc->dev)) {
put_device(&svc->dev); break;
}
}
}
/* Required properties */
p = tb_property_find(dir, "deviceid", TB_PROPERTY_TYPE_VALUE); if (!p) return -EINVAL;
xd->device = p->value.immediate;
p = tb_property_find(dir, "vendorid", TB_PROPERTY_TYPE_VALUE); if (!p) return -EINVAL;
xd->vendor = p->value.immediate;
p = tb_property_find(dir, "maxhopid", TB_PROPERTY_TYPE_VALUE); /* * USB4 inter-domain spec suggests using 15 as HopID if the * other end does not announce it in a property. This is for * TBT3 compatibility.
*/
xd->remote_max_hopid = p ? p->value.immediate : XDOMAIN_DEFAULT_MAX_HOPID;
if (uuid_equal(&uuid, xd->local_uuid)) { if (route == xd->route)
dev_dbg(&xd->dev, "loop back detected\n"); else
dev_dbg(&xd->dev, "intra-domain loop detected\n");
/* Don't bond lanes automatically for loops */
xd->bonding_possible = false;
}
/* * If the UUID is different, there is another domain connected * so mark this one unplugged and wait for the connection * manager to replace it.
*/ if (xd->remote_uuid && !uuid_equal(&uuid, xd->remote_uuid)) {
dev_dbg(&xd->dev, "remote UUID is different, unplugging\n");
xd->is_unplugged = true; return -ENODEV;
}
/* First time fill in the missing UUID */ if (!xd->remote_uuid) {
xd->remote_uuid = kmemdup(&uuid, sizeof(uuid_t), GFP_KERNEL); if (!xd->remote_uuid) return -ENOMEM;
}
/* Use the current target speed */
ret = tb_port_read(port, &val, TB_CFG_PORT, port->cap_phy + LANE_ADP_CS_1, 1); if (ret) return ret;
tls = val & LANE_ADP_CS_1_TARGET_SPEED_MASK;
dev_dbg(&xd->dev, "sending link state change request with width %#x speed %#x\n",
tlw, tls);
ret = tb_xdp_link_state_change_request(tb->ctl, xd->route,
xd->state_retries, tlw, tls); if (ret) { if (ret != -EOPNOTSUPP && xd->state_retries-- > 0) {
dev_dbg(&xd->dev, "failed to change remote link state, retrying\n"); return -EAGAIN;
}
dev_err(&xd->dev, "failed request link state change, aborting\n"); return ret;
}
dev_dbg(&xd->dev, "received link state change response\n"); return 0;
}
if (xd->target_link_width == LANE_ADP_CS_1_TARGET_WIDTH_SINGLE) {
width = TB_LINK_WIDTH_SINGLE;
width_mask = width;
} elseif (xd->target_link_width == LANE_ADP_CS_1_TARGET_WIDTH_DUAL) {
width = TB_LINK_WIDTH_DUAL;
width_mask = width | TB_LINK_WIDTH_ASYM_TX | TB_LINK_WIDTH_ASYM_RX;
} else { if (xd->state_retries-- > 0) {
dev_dbg(&xd->dev, "link state change request not received yet, retrying\n"); return -EAGAIN;
}
dev_dbg(&xd->dev, "timeout waiting for link change request\n"); return -ETIMEDOUT;
}
port = tb_xdomain_downstream_port(xd);
/* * We can't use tb_xdomain_lane_bonding_enable() here because it * is the other side that initiates lane bonding. So here we * just set the width to both lane adapters and wait for the * link to transition bonded.
*/
ret = tb_port_set_link_width(port->dual_link_port, width); if (ret) {
tb_port_warn(port->dual_link_port, "failed to set link width to %d\n", width); return ret;
}
ret = tb_port_set_link_width(port, width); if (ret) {
tb_port_warn(port, "failed to set link width to %d\n", width); return ret;
}
ret = tb_port_wait_for_link_width(port, width_mask,
XDOMAIN_BONDING_TIMEOUT); if (ret) {
dev_warn(&xd->dev, "error waiting for link width to become %d\n",
width_mask); return ret;
}
/* * Now the device should be ready enough so we can add it to the * bus and let userspace know about it. If the device is already * registered, we notify the userspace that it has changed.
*/ if (!update) { /* * Now disable lane 1 if bonding was not enabled. Do * this only if bonding was possible at the beginning * (that is we are the connection manager and there are * two lanes).
*/ if (xd->bonding_possible) { struct tb_port *port;
port = tb_xdomain_downstream_port(xd); if (!port->bonded)
tb_port_disable(port->dual_link_port);
}
dev_dbg(&xd->dev, "current link speed %u.0 Gb/s\n",
xd->link_speed);
dev_dbg(&xd->dev, "current link width %s\n",
tb_width_name(xd->link_width));
if (device_add(&xd->dev)) {
dev_err(&xd->dev, "failed to add XDomain device\n"); return -ENODEV;
}
dev_info(&xd->dev, "new host found, vendor=%#x device=%#x\n",
xd->vendor, xd->device); if (xd->vendor_name && xd->device_name)
dev_info(&xd->dev, "%s %s\n", xd->vendor_name,
xd->device_name);
staticvoid tb_xdomain_state_work(struct work_struct *work)
{ struct tb_xdomain *xd = container_of(work, typeof(*xd), state_work.work); int ret, state = xd->state;
if (WARN_ON_ONCE(state < XDOMAIN_STATE_INIT ||
state > XDOMAIN_STATE_ERROR)) return;
dev_dbg(&xd->dev, "running state %s\n", state_names[state]);
switch (state) { case XDOMAIN_STATE_INIT: if (xd->needs_uuid) {
tb_xdomain_queue_uuid(xd);
} else {
tb_xdomain_queue_properties_changed(xd);
tb_xdomain_queue_properties(xd);
} break;
case XDOMAIN_STATE_UUID:
ret = tb_xdomain_get_uuid(xd); if (ret) { if (ret == -EAGAIN) goto retry_state;
tb_xdomain_failed(xd);
} else {
tb_xdomain_queue_properties_changed(xd); if (xd->bonding_possible)
tb_xdomain_queue_link_status(xd); else
tb_xdomain_queue_properties(xd);
} break;
case XDOMAIN_STATE_LINK_STATUS:
ret = tb_xdomain_get_link_status(xd); if (ret) { if (ret == -EAGAIN) goto retry_state;
/* * If any of the lane bonding states fail we skip * bonding completely and try to continue from * reading properties.
*/
tb_xdomain_queue_properties(xd);
} else {
tb_xdomain_queue_bonding(xd);
} break;
case XDOMAIN_STATE_LINK_STATE_CHANGE:
ret = tb_xdomain_link_state_change(xd, 2); if (ret) { if (ret == -EAGAIN) goto retry_state;
tb_xdomain_queue_properties(xd);
} else {
tb_xdomain_queue_link_status2(xd);
} break;
case XDOMAIN_STATE_LINK_STATUS2:
ret = tb_xdomain_get_link_status(xd); if (ret) { if (ret == -EAGAIN) goto retry_state;
tb_xdomain_queue_properties(xd);
} else {
tb_xdomain_queue_bonding_uuid_low(xd);
} break;
case XDOMAIN_STATE_BONDING_UUID_LOW:
tb_xdomain_lane_bonding_enable(xd);
tb_xdomain_queue_properties(xd); break;
case XDOMAIN_STATE_BONDING_UUID_HIGH: if (tb_xdomain_bond_lanes_uuid_high(xd) == -EAGAIN) goto retry_state;
tb_xdomain_queue_properties(xd); break;
case XDOMAIN_STATE_PROPERTIES:
ret = tb_xdomain_get_properties(xd); if (ret) { if (ret == -EAGAIN) goto retry_state;
tb_xdomain_failed(xd);
} else {
xd->state = XDOMAIN_STATE_ENUMERATED;
} break;
case XDOMAIN_STATE_ENUMERATED:
tb_xdomain_queue_properties(xd); break;
case XDOMAIN_STATE_ERROR:
dev_dbg(&xd->dev, "discovery failed, stopping handshake\n");
__stop_handshake(xd); break;
default:
dev_warn(&xd->dev, "unexpected state %d\n", state); break;
}
/* * Gen 4 links come up already as bonded so only update the port * structures here.
*/ if (tb_port_get_link_generation(down) >= 4) {
down->bonded = true;
down->dual_link_port->bonded = true;
} else {
xd->bonding_possible = true;
}
}
if (tb_port_get_link_generation(down) >= 4) {
down->bonded = false;
down->dual_link_port->bonded = false;
} elseif (xd->link_width > TB_LINK_WIDTH_SINGLE) { /* * Just return port structures back to way they were and * update credits. No need to update userspace because * the XDomain is removed soon anyway.
*/
tb_port_lane_bonding_disable(down);
tb_port_update_credits(down);
} elseif (down->dual_link_port) { /* * Re-enable the lane 1 adapter we disabled at the end * of tb_xdomain_get_properties().
*/
tb_port_enable(down->dual_link_port);
}
}
/** * tb_xdomain_alloc() - Allocate new XDomain object * @tb: Domain where the XDomain belongs * @parent: Parent device (the switch through the connection to the * other domain is reached). * @route: Route string used to reach the other domain * @local_uuid: Our local domain UUID * @remote_uuid: UUID of the other domain (optional) * * Allocates new XDomain structure and returns pointer to that. The * object must be released by calling tb_xdomain_put().
*/ struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent,
u64 route, const uuid_t *local_uuid, const uuid_t *remote_uuid)
{ struct tb_switch *parent_sw = tb_to_switch(parent); struct tb_xdomain *xd; struct tb_port *down;
/* Make sure the downstream domain is accessible */
down = tb_port_at(route, parent_sw);
tb_port_unlock(down);
xd = kzalloc(sizeof(*xd), GFP_KERNEL); if (!xd) return NULL;
/* * This keeps the DMA powered on as long as we have active * connection to another host.
*/
pm_runtime_set_active(&xd->dev);
pm_runtime_get_noresume(&xd->dev);
pm_runtime_enable(&xd->dev);
/** * tb_xdomain_add() - Add XDomain to the bus * @xd: XDomain to add * * This function starts XDomain discovery protocol handshake and * eventually adds the XDomain to the bus. After calling this function * the caller needs to call tb_xdomain_remove() in order to remove and * release the object regardless whether the handshake succeeded or not.
*/ void tb_xdomain_add(struct tb_xdomain *xd)
{ /* Start exchanging properties with the other host */
start_handshake(xd);
}
/** * tb_xdomain_remove() - Remove XDomain from the bus * @xd: XDomain to remove * * This will stop all ongoing configuration work and remove the XDomain * along with any services from the bus. When the last reference to @xd * is released the object will be released as well.
*/ void tb_xdomain_remove(struct tb_xdomain *xd)
{
tb_xdomain_debugfs_remove(xd);
/* * Undo runtime PM here explicitly because it is possible that * the XDomain was never added to the bus and thus device_del() * is not called for it (device_del() would handle this otherwise).
*/
pm_runtime_disable(&xd->dev);
pm_runtime_put_noidle(&xd->dev);
pm_runtime_set_suspended(&xd->dev);
/** * tb_xdomain_lane_bonding_enable() - Enable lane bonding on XDomain * @xd: XDomain connection * * Lane bonding is disabled by default for XDomains. This function tries * to enable bonding by first enabling the port and waiting for the CL0 * state. * * Return: %0 in case of success and negative errno in case of error.
*/ int tb_xdomain_lane_bonding_enable(struct tb_xdomain *xd)
{ unsignedint width_mask; struct tb_port *port; int ret;
port = tb_xdomain_downstream_port(xd); if (!port->dual_link_port) return -ENODEV;
ret = tb_port_enable(port->dual_link_port); if (ret) return ret;
ret = tb_wait_for_port(port->dual_link_port, true); if (ret < 0) return ret; if (!ret) return -ENOTCONN;
ret = tb_port_lane_bonding_enable(port); if (ret) {
tb_port_warn(port, "failed to enable lane bonding\n"); return ret;
}
/* Any of the widths are all bonded */
width_mask = TB_LINK_WIDTH_DUAL | TB_LINK_WIDTH_ASYM_TX |
TB_LINK_WIDTH_ASYM_RX;
ret = tb_port_wait_for_link_width(port, width_mask,
XDOMAIN_BONDING_TIMEOUT); if (ret) {
tb_port_warn(port, "failed to enable lane bonding\n"); return ret;
}
/** * tb_xdomain_lane_bonding_disable() - Disable lane bonding * @xd: XDomain connection * * Lane bonding is disabled by default for XDomains. If bonding has been * enabled, this function can be used to disable it.
*/ void tb_xdomain_lane_bonding_disable(struct tb_xdomain *xd)
{ struct tb_port *port;
port = tb_xdomain_downstream_port(xd); if (port->dual_link_port) { int ret;
tb_port_lane_bonding_disable(port);
ret = tb_port_wait_for_link_width(port, TB_LINK_WIDTH_SINGLE, 100); if (ret == -ETIMEDOUT)
tb_port_warn(port, "timeout disabling lane bonding\n");
tb_port_disable(port->dual_link_port);
tb_port_update_credits(port);
tb_xdomain_update_link_attributes(xd);
/** * tb_xdomain_alloc_in_hopid() - Allocate input HopID for tunneling * @xd: XDomain connection * @hopid: Preferred HopID or %-1 for next available * * Returns allocated HopID or negative errno. Specifically returns * %-ENOSPC if there are no more available HopIDs. Returned HopID is * guaranteed to be within range supported by the input lane adapter. * Call tb_xdomain_release_in_hopid() to release the allocated HopID.
*/ int tb_xdomain_alloc_in_hopid(struct tb_xdomain *xd, int hopid)
{ if (hopid < 0)
hopid = TB_PATH_MIN_HOPID; if (hopid < TB_PATH_MIN_HOPID || hopid > xd->local_max_hopid) return -EINVAL;
/** * tb_xdomain_alloc_out_hopid() - Allocate output HopID for tunneling * @xd: XDomain connection * @hopid: Preferred HopID or %-1 for next available * * Returns allocated HopID or negative errno. Specifically returns * %-ENOSPC if there are no more available HopIDs. Returned HopID is * guaranteed to be within range supported by the output lane adapter. * Call tb_xdomain_release_in_hopid() to release the allocated HopID.
*/ int tb_xdomain_alloc_out_hopid(struct tb_xdomain *xd, int hopid)
{ if (hopid < 0)
hopid = TB_PATH_MIN_HOPID; if (hopid < TB_PATH_MIN_HOPID || hopid > xd->remote_max_hopid) return -EINVAL;
/** * tb_xdomain_enable_paths() - Enable DMA paths for XDomain connection * @xd: XDomain connection * @transmit_path: HopID we are using to send out packets * @transmit_ring: DMA ring used to send out packets * @receive_path: HopID the other end is using to send packets to us * @receive_ring: DMA ring used to receive packets from @receive_path * * The function enables DMA paths accordingly so that after successful * return the caller can send and receive packets using high-speed DMA * path. If a transmit or receive path is not needed, pass %-1 for those * parameters. * * Return: %0 in case of success and negative errno in case of error
*/ int tb_xdomain_enable_paths(struct tb_xdomain *xd, int transmit_path, int transmit_ring, int receive_path, int receive_ring)
{ return tb_domain_approve_xdomain_paths(xd->tb, xd, transmit_path,
transmit_ring, receive_path,
receive_ring);
}
EXPORT_SYMBOL_GPL(tb_xdomain_enable_paths);
/** * tb_xdomain_disable_paths() - Disable DMA paths for XDomain connection * @xd: XDomain connection * @transmit_path: HopID we are using to send out packets * @transmit_ring: DMA ring used to send out packets * @receive_path: HopID the other end is using to send packets to us * @receive_ring: DMA ring used to receive packets from @receive_path * * This does the opposite of tb_xdomain_enable_paths(). After call to * this the caller is not expected to use the rings anymore. Passing %-1 * as path/ring parameter means don't care. Normally the callers should * pass the same values here as they do when paths are enabled. * * Return: %0 in case of success and negative errno in case of error
*/ int tb_xdomain_disable_paths(struct tb_xdomain *xd, int transmit_path, int transmit_ring, int receive_path, int receive_ring)
{ return tb_domain_disconnect_xdomain_paths(xd->tb, xd, transmit_path,
transmit_ring, receive_path,
receive_ring);
}
EXPORT_SYMBOL_GPL(tb_xdomain_disable_paths);
if (lookup->uuid) { if (xd->remote_uuid &&
uuid_equal(xd->remote_uuid, lookup->uuid)) return xd;
} else { if (lookup->link && lookup->link == xd->link &&
lookup->depth == xd->depth) return xd; if (lookup->route && lookup->route == xd->route) return xd;
}
} elseif (tb_port_has_remote(port)) {
xd = switch_find_xdomain(port->remote->sw, lookup); if (xd) return xd;
}
}
return NULL;
}
/** * tb_xdomain_find_by_uuid() - Find an XDomain by UUID * @tb: Domain where the XDomain belongs to * @uuid: UUID to look for * * Finds XDomain by walking through the Thunderbolt topology below @tb. * The returned XDomain will have its reference count increased so the * caller needs to call tb_xdomain_put() when it is done with the * object. * * This will find all XDomains including the ones that are not yet added * to the bus (handshake is still in progress). * * The caller needs to hold @tb->lock.
*/ struct tb_xdomain *tb_xdomain_find_by_uuid(struct tb *tb, const uuid_t *uuid)
{ struct tb_xdomain_lookup lookup; struct tb_xdomain *xd;
/** * tb_xdomain_find_by_link_depth() - Find an XDomain by link and depth * @tb: Domain where the XDomain belongs to * @link: Root switch link number * @depth: Depth in the link * * Finds XDomain by walking through the Thunderbolt topology below @tb. * The returned XDomain will have its reference count increased so the * caller needs to call tb_xdomain_put() when it is done with the * object. * * This will find all XDomains including the ones that are not yet added * to the bus (handshake is still in progress). * * The caller needs to hold @tb->lock.
*/ struct tb_xdomain *tb_xdomain_find_by_link_depth(struct tb *tb, u8 link,
u8 depth)
{ struct tb_xdomain_lookup lookup; struct tb_xdomain *xd;
/** * tb_xdomain_find_by_route() - Find an XDomain by route string * @tb: Domain where the XDomain belongs to * @route: XDomain route string * * Finds XDomain by walking through the Thunderbolt topology below @tb. * The returned XDomain will have its reference count increased so the * caller needs to call tb_xdomain_put() when it is done with the * object. * * This will find all XDomains including the ones that are not yet added * to the bus (handshake is still in progress). * * The caller needs to hold @tb->lock.
*/ struct tb_xdomain *tb_xdomain_find_by_route(struct tb *tb, u64 route)
{ struct tb_xdomain_lookup lookup; struct tb_xdomain *xd;
/* We expect the packet is at least size of the header */
length = hdr->xd_hdr.length_sn & TB_XDOMAIN_LENGTH_MASK; if (length != size / 4 - sizeof(hdr->xd_hdr) / 4) returntrue; if (length < sizeof(*hdr) / 4 - sizeof(hdr->xd_hdr) / 4) returntrue;
/* * Handle XDomain discovery protocol packets directly here. For * other protocols (based on their UUID) we call registered * handlers in turn.
*/ if (uuid_equal(&hdr->uuid, &tb_xdp_uuid)) { if (type == TB_CFG_PKG_XDOMAIN_REQ) return tb_xdp_schedule_request(tb, hdr, size); returnfalse;
}
mutex_lock(&xdomain_lock);
list_for_each_entry_safe(handler, tmp, &protocol_handlers, list) { if (!uuid_equal(&hdr->uuid, handler->uuid)) continue;
mutex_unlock(&xdomain_lock);
ret = handler->callback(buf, size, handler->data);
mutex_lock(&xdomain_lock);
p = tb_property_find(xdomain_property_dir, key,
TB_PROPERTY_TYPE_DIRECTORY); if (p && p->value.dir == dir) {
tb_property_remove(p); returntrue;
} returnfalse;
}
/** * tb_register_property_dir() - Register property directory to the host * @key: Key (name) of the directory to add * @dir: Directory to add * * Service drivers can use this function to add new property directory * to the host available properties. The other connected hosts are * notified so they can re-read properties of this host if they are * interested. * * Return: %0 on success and negative errno on failure
*/ int tb_register_property_dir(constchar *key, struct tb_property_dir *dir)
{ int ret;
if (WARN_ON(!xdomain_property_dir)) return -EAGAIN;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.