drivers/net/hyperv/netvsc.c
Source file repositories/reference/linux-study-clean/drivers/net/hyperv/netvsc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/hyperv/netvsc.c- Extension
.c- Size
- 54297 bytes
- Lines
- 1881
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/kernel.hlinux/sched.hlinux/wait.hlinux/mm.hlinux/highmem.hlinux/delay.hlinux/io.hlinux/slab.hlinux/netdevice.hlinux/if_ether.hlinux/vmalloc.hlinux/rtnetlink.hlinux/prefetch.hlinux/filter.hasm/sync_bitops.hasm/mshyperv.hhyperv_net.hnetvsc_trace.h
Detected Declarations
struct recv_comp_msgfunction Copyrightfunction netvsc_subchan_workfunction free_netvsc_devicefunction free_netvsc_device_rcufunction netvsc_revoke_recv_buffunction msgfunction netvsc_revoke_send_buffunction msgfunction netvsc_teardown_recv_gpadlfunction netvsc_teardown_send_gpadlfunction netvsc_alloc_recv_comp_ringfunction netvsc_init_buffunction negotiate_nvsp_verfunction netvsc_connect_vspfunction netvsc_device_removefunction netvsc_free_send_slotfunction netvsc_send_tx_completefunction netvsc_send_completionfunction netvsc_get_next_send_sectionfunction for_each_clear_bitfunction netvsc_copy_to_send_buffunction netvsc_dma_unmapfunction vmbus_sendpacket_pagebufferfunction netvsc_build_mpb_arrayfunction netvsc_send_pktfunction move_pkt_msdfunction netvsc_sendfunction send_recv_completionsfunction recv_comp_slot_availfunction enq_receive_completefunction netvsc_receivefunction netvsc_send_tablefunction netvsc_send_vffunction netvsc_receive_inbandfunction netvsc_process_raw_pktfunction netvsc_pollfunction napi_complete_donefunction softirq
Annotated Snippet
struct recv_comp_msg {
struct nvsp_message_header hdr;
u32 status;
} __packed;
struct recv_comp_msg msg = {
.hdr.msg_type = NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE,
};
int ret;
while (mrc->first != mrc->next) {
const struct recv_comp_data *rcd
= mrc->slots + mrc->first;
msg.status = rcd->status;
ret = vmbus_sendpacket(nvchan->channel, &msg, sizeof(msg),
rcd->tid, VM_PKT_COMP, 0);
if (unlikely(ret)) {
struct net_device_context *ndev_ctx = netdev_priv(ndev);
++ndev_ctx->eth_stats.rx_comp_busy;
return ret;
}
if (++mrc->first == nvdev->recv_completion_cnt)
mrc->first = 0;
}
/* receive completion ring has been emptied */
if (unlikely(nvdev->destroy))
wake_up(&nvdev->wait_drain);
return 0;
}
/* Count how many receive completions are outstanding */
static void recv_comp_slot_avail(const struct netvsc_device *nvdev,
const struct multi_recv_comp *mrc,
u32 *filled, u32 *avail)
{
u32 count = nvdev->recv_completion_cnt;
if (mrc->next >= mrc->first)
*filled = mrc->next - mrc->first;
else
*filled = (count - mrc->first) + mrc->next;
*avail = count - *filled - 1;
}
/* Add receive complete to ring to send to host. */
static void enq_receive_complete(struct net_device *ndev,
struct netvsc_device *nvdev, u16 q_idx,
u64 tid, u32 status)
{
struct netvsc_channel *nvchan = &nvdev->chan_table[q_idx];
struct multi_recv_comp *mrc = &nvchan->mrc;
struct recv_comp_data *rcd;
u32 filled, avail;
recv_comp_slot_avail(nvdev, mrc, &filled, &avail);
if (unlikely(filled > NAPI_POLL_WEIGHT)) {
send_recv_completions(ndev, nvdev, nvchan);
recv_comp_slot_avail(nvdev, mrc, &filled, &avail);
}
if (unlikely(!avail)) {
netdev_err(ndev, "Recv_comp full buf q:%hd, tid:%llx\n",
q_idx, tid);
return;
}
rcd = mrc->slots + mrc->next;
rcd->tid = tid;
rcd->status = status;
if (++mrc->next == nvdev->recv_completion_cnt)
mrc->next = 0;
}
static int netvsc_receive(struct net_device *ndev,
struct netvsc_device *net_device,
struct netvsc_channel *nvchan,
const struct vmpacket_descriptor *desc)
{
struct net_device_context *net_device_ctx = netdev_priv(ndev);
struct vmbus_channel *channel = nvchan->channel;
const struct vmtransfer_page_packet_header *vmxferpage_packet
= container_of(desc, const struct vmtransfer_page_packet_header, d);
const struct nvsp_message *nvsp = hv_pkt_data(desc);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/sched.h`, `linux/wait.h`, `linux/mm.h`, `linux/highmem.h`, `linux/delay.h`, `linux/io.h`, `linux/slab.h`.
- Detected declarations: `struct recv_comp_msg`, `function Copyright`, `function netvsc_subchan_work`, `function free_netvsc_device`, `function free_netvsc_device_rcu`, `function netvsc_revoke_recv_buf`, `function msg`, `function netvsc_revoke_send_buf`, `function msg`, `function netvsc_teardown_recv_gpadl`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source 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.