drivers/greybus/connection.c
Source file repositories/reference/linux-study-clean/drivers/greybus/connection.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/greybus/connection.c- Extension
.c- Size
- 23120 bytes
- Lines
- 940
- Domain
- Driver Families
- Bucket
- drivers/greybus
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/workqueue.hlinux/greybus.hgreybus_trace.h
Detected Declarations
function gb_connection_cport_in_usefunction list_for_each_entryfunction gb_connection_getfunction gb_connection_putfunction gb_connection_hd_findfunction greybus_data_rcvdfunction gb_connection_kref_releasefunction gb_connection_init_namefunction _gb_connection_createfunction gb_connection_create_staticfunction gb_connection_create_controlfunction gb_connection_createfunction gb_connection_create_flagsfunction gb_connection_create_offloadedfunction gb_connection_hd_cport_enablefunction gb_connection_hd_cport_disablefunction gb_connection_hd_cport_connectedfunction gb_connection_hd_cport_flushfunction gb_connection_hd_cport_quiescefunction gb_connection_hd_cport_clearfunction gb_connection_svc_connection_createfunction gb_connection_svc_connection_destroyfunction gb_connection_control_connectedfunction gb_connection_control_disconnectingfunction gb_connection_control_disconnectedfunction gb_connection_shutdown_operationfunction gb_connection_cport_shutdownfunction gb_connection_cport_shutdown_phase_1function gb_connection_cport_shutdown_phase_2function gb_connection_cancel_operationsfunction gb_connection_flush_incoming_operationsfunction list_for_each_entryfunction _gb_connection_enablefunction gb_connection_enablefunction gb_connection_enable_txfunction gb_connection_disable_rxfunction gb_connection_mode_switch_preparefunction gb_connection_mode_switch_completefunction gb_connection_disablefunction gb_connection_disable_forcedfunction gb_connection_destroyfunction gb_connection_latency_tag_enablefunction gb_connection_latency_tag_disableexport greybus_data_rcvdexport gb_connection_createexport gb_connection_create_flagsexport gb_connection_create_offloadedexport gb_connection_enable
Annotated Snippet
if (connection->hd_cport_id == cport_id) {
gb_connection_get(connection);
goto found;
}
connection = NULL;
found:
spin_unlock_irqrestore(&gb_connections_lock, flags);
return connection;
}
/*
* Callback from the host driver to let us know that data has been
* received on the bundle.
*/
void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
u8 *data, size_t length)
{
struct gb_connection *connection;
trace_gb_hd_in(hd);
connection = gb_connection_hd_find(hd, cport_id);
if (!connection) {
dev_err(&hd->dev,
"nonexistent connection (%zu bytes dropped)\n", length);
return;
}
gb_connection_recv(connection, data, length);
gb_connection_put(connection);
}
EXPORT_SYMBOL_GPL(greybus_data_rcvd);
static void gb_connection_kref_release(struct kref *kref)
{
struct gb_connection *connection;
connection = container_of(kref, struct gb_connection, kref);
trace_gb_connection_release(connection);
kfree(connection);
}
static void gb_connection_init_name(struct gb_connection *connection)
{
u16 hd_cport_id = connection->hd_cport_id;
u16 cport_id = 0;
u8 intf_id = 0;
if (connection->intf) {
intf_id = connection->intf->interface_id;
cport_id = connection->intf_cport_id;
}
snprintf(connection->name, sizeof(connection->name),
"%u/%u:%u", hd_cport_id, intf_id, cport_id);
}
/*
* _gb_connection_create() - create a Greybus connection
* @hd: host device of the connection
* @hd_cport_id: host-device cport id, or -1 for dynamic allocation
* @intf: remote interface, or NULL for static connections
* @bundle: remote-interface bundle (may be NULL)
* @cport_id: remote-interface cport id, or 0 for static connections
* @handler: request handler (may be NULL)
* @flags: connection flags
*
* Create a Greybus connection, representing the bidirectional link
* between a CPort on a (local) Greybus host device and a CPort on
* another Greybus interface.
*
* A connection also maintains the state of operations sent over the
* connection.
*
* Serialised against concurrent create and destroy using the
* gb_connection_mutex.
*
* Return: A pointer to the new connection if successful, or an ERR_PTR
* otherwise.
*/
static struct gb_connection *
_gb_connection_create(struct gb_host_device *hd, int hd_cport_id,
struct gb_interface *intf,
struct gb_bundle *bundle, int cport_id,
gb_request_handler_t handler,
unsigned long flags)
{
struct gb_connection *connection;
Annotation
- Immediate include surface: `linux/workqueue.h`, `linux/greybus.h`, `greybus_trace.h`.
- Detected declarations: `function gb_connection_cport_in_use`, `function list_for_each_entry`, `function gb_connection_get`, `function gb_connection_put`, `function gb_connection_hd_find`, `function greybus_data_rcvd`, `function gb_connection_kref_release`, `function gb_connection_init_name`, `function _gb_connection_create`, `function gb_connection_create_static`.
- Atlas domain: Driver Families / drivers/greybus.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.