drivers/net/thunderbolt/main.c
Source file repositories/reference/linux-study-clean/drivers/net/thunderbolt/main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/thunderbolt/main.c- Extension
.c- Size
- 39898 bytes
- Lines
- 1524
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/atomic.hlinux/ethtool.hlinux/highmem.hlinux/if_vlan.hlinux/jhash.hlinux/module.hlinux/etherdevice.hlinux/rtnetlink.hlinux/sizes.hlinux/thunderbolt.hlinux/uuid.hlinux/workqueue.hnet/ip6_checksum.htrace.h
Detected Declarations
struct thunderbolt_ip_frame_headerstruct thunderbolt_ip_headerstruct thunderbolt_ip_loginstruct thunderbolt_ip_login_responsestruct thunderbolt_ip_logoutstruct thunderbolt_ip_statusstruct tbnet_statsstruct tbnet_framestruct tbnet_ringstruct tbnetenum thunderbolt_ip_frame_pdfenum thunderbolt_ip_typefunction tbnet_fill_headerfunction tbnet_login_responsefunction tbnet_login_requestfunction tbnet_logout_responsefunction tbnet_logout_requestfunction start_loginfunction stop_loginfunction tbnet_frame_sizefunction tbnet_free_buffersfunction tbnet_tear_downfunction tbnet_handle_packetfunction tbnet_available_buffersfunction tbnet_alloc_rx_buffersfunction tbnet_tx_callbackfunction tbnet_alloc_tx_buffersfunction tbnet_connected_workfunction tbnet_login_workfunction tbnet_disconnect_workfunction tbnet_check_framefunction tbnet_pollfunction tbnet_start_pollfunction tbnet_openfunction tbnet_stopfunction tbnet_xmit_csum_and_mapfunction tbnet_start_xmitfunction tbnet_get_stats64function tbnet_get_link_ksettingsfunction tbnet_generate_macfunction tbnet_probefunction tbnet_removefunction tbnet_shutdownfunction tbnet_suspendfunction tbnet_resumefunction tbnet_initfunction tbnet_exitmodule init tbnet_init
Annotated Snippet
static const struct net_device_ops tbnet_netdev_ops = {
.ndo_open = tbnet_open,
.ndo_stop = tbnet_stop,
.ndo_start_xmit = tbnet_start_xmit,
.ndo_set_mac_address = eth_mac_addr,
.ndo_get_stats64 = tbnet_get_stats64,
};
static int tbnet_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *cmd)
{
const struct tbnet *net = netdev_priv(dev);
const struct tb_xdomain *xd = net->xd;
int speed;
ethtool_link_ksettings_zero_link_mode(cmd, supported);
ethtool_link_ksettings_zero_link_mode(cmd, advertising);
/* Figure out the current link speed and width */
switch (xd->link_speed) {
case 40:
speed = SPEED_80000;
break;
case 20:
if (xd->link_width == 2)
speed = SPEED_40000;
else
speed = SPEED_20000;
break;
case 10:
if (xd->link_width == 2) {
speed = SPEED_20000;
break;
}
fallthrough;
default:
speed = SPEED_10000;
break;
}
cmd->base.speed = speed;
cmd->base.duplex = DUPLEX_FULL;
cmd->base.autoneg = AUTONEG_DISABLE;
cmd->base.port = PORT_OTHER;
return 0;
}
static const struct ethtool_ops tbnet_ethtool_ops = {
.get_link_ksettings = tbnet_get_link_ksettings,
};
static void tbnet_generate_mac(struct net_device *dev)
{
const struct tbnet *net = netdev_priv(dev);
const struct tb_xdomain *xd = net->xd;
u8 addr[ETH_ALEN];
u8 phy_port;
u32 hash;
phy_port = tb_phy_port_from_link(TBNET_L0_PORT_NUM(xd->route));
/* Unicast and locally administered MAC */
addr[0] = phy_port << 4 | 0x02;
hash = jhash2((u32 *)xd->local_uuid, 4, 0);
memcpy(addr + 1, &hash, sizeof(hash));
hash = jhash2((u32 *)xd->local_uuid, 4, hash);
addr[5] = hash & 0xff;
eth_hw_addr_set(dev, addr);
/* Allow changing it if needed */
dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
}
static int tbnet_probe(struct tb_service *svc, const struct tb_service_id *id)
{
struct tb_xdomain *xd = tb_service_parent(svc);
struct net_device *dev;
struct tbnet *net;
int ret;
dev = alloc_etherdev(sizeof(*net));
if (!dev)
return -ENOMEM;
SET_NETDEV_DEV(dev, &svc->dev);
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/ethtool.h`, `linux/highmem.h`, `linux/if_vlan.h`, `linux/jhash.h`, `linux/module.h`, `linux/etherdevice.h`, `linux/rtnetlink.h`.
- Detected declarations: `struct thunderbolt_ip_frame_header`, `struct thunderbolt_ip_header`, `struct thunderbolt_ip_login`, `struct thunderbolt_ip_login_response`, `struct thunderbolt_ip_logout`, `struct thunderbolt_ip_status`, `struct tbnet_stats`, `struct tbnet_frame`, `struct tbnet_ring`, `struct tbnet`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.