drivers/net/hyperv/netvsc_drv.c
Source file repositories/reference/linux-study-clean/drivers/net/hyperv/netvsc_drv.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/hyperv/netvsc_drv.c- Extension
.c- Size
- 76374 bytes
- Lines
- 2901
- 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.
- 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/init.hlinux/atomic.hlinux/ethtool.hlinux/module.hlinux/highmem.hlinux/device.hlinux/io.hlinux/delay.hlinux/netdevice.hlinux/inetdevice.hlinux/etherdevice.hlinux/pci.hlinux/skbuff.hlinux/if_vlan.hlinux/in.hlinux/slab.hlinux/rtnetlink.hlinux/netpoll.hlinux/bpf.hnet/arp.hnet/netdev_lock.hnet/route.hnet/sock.hnet/pkt_sched.hnet/checksum.hnet/ip6_checksum.hhyperv_net.h
Detected Declarations
function netvsc_change_rx_flagsfunction netvsc_set_rx_modefunction netvsc_tx_enablefunction netvsc_openfunction netvsc_wait_until_emptyfunction netvsc_tx_disablefunction netvsc_closefunction netvsc_get_tx_queuefunction defaultfunction netvsc_select_queuefunction init_page_arrayfunction count_skb_frag_slotsfunction netvsc_get_slotsfunction net_checksum_infofunction netvsc_vf_xmitfunction netvsc_xmitfunction netvsc_start_xmitfunction netvsc_linkstatus_callbackfunction data_buflenfunction netvsc_xdp_xmitfunction netvsc_comp_ipcsumfunction netvsc_recv_callbackfunction netvsc_get_drvinfofunction netvsc_get_channelsfunction netvsc_devinfo_putfunction netvsc_detachfunction netvsc_attachfunction netvsc_set_channelsfunction netvsc_init_settingsfunction netvsc_get_link_ksettingsfunction netvsc_set_link_ksettingsfunction netvsc_change_mtufunction netvsc_get_vf_statsfunction for_each_possible_cpufunction netvsc_get_pcpu_statsfunction netvsc_get_stats64function netvsc_set_mac_addrfunction netvsc_get_sset_countfunction netvsc_get_ethtool_statsfunction netvsc_get_stringsfunction for_each_present_cpufunction netvsc_get_rxfh_fieldsfunction netvsc_get_rx_ring_countfunction netvsc_set_rxfh_fieldsfunction netvsc_get_rxfh_key_sizefunction netvsc_rss_indir_sizefunction netvsc_get_rxfhfunction netvsc_set_rxfh
Annotated Snippet
const struct net_device_ops *vf_ops = vf_netdev->netdev_ops;
if (vf_ops->ndo_select_queue)
txq = vf_ops->ndo_select_queue(vf_netdev, skb, sb_dev);
else
txq = netdev_pick_tx(vf_netdev, skb, NULL);
/* Record the queue selected by VF so that it can be
* used for common case where VF has more queues than
* the synthetic device.
*/
qdisc_skb_cb(skb)->slave_dev_queue_mapping = txq;
} else {
txq = netvsc_pick_tx(ndev, skb);
}
rcu_read_unlock();
while (txq >= ndev->real_num_tx_queues)
txq -= ndev->real_num_tx_queues;
return txq;
}
static u32 init_page_array(void *hdr, u32 len, struct sk_buff *skb,
struct hv_netvsc_packet *packet,
struct hv_page_buffer *pb)
{
int frags = skb_shinfo(skb)->nr_frags;
int i;
/* The packet is laid out thus:
* 1. hdr: RNDIS header and PPI
* 2. skb linear data
* 3. skb fragment data
*/
pb[0].offset = offset_in_hvpage(hdr);
pb[0].len = len;
pb[0].pfn = virt_to_hvpfn(hdr);
packet->rmsg_size = len;
pb[1].offset = offset_in_hvpage(skb->data);
pb[1].len = skb_headlen(skb);
pb[1].pfn = virt_to_hvpfn(skb->data);
for (i = 0; i < frags; i++) {
skb_frag_t *frag = skb_shinfo(skb)->frags + i;
struct hv_page_buffer *cur_pb = &pb[i + 2];
u64 pfn = page_to_hvpfn(skb_frag_page(frag));
u32 offset = skb_frag_off(frag);
cur_pb->offset = offset_in_hvpage(offset);
cur_pb->len = skb_frag_size(frag);
cur_pb->pfn = pfn + (offset >> HV_HYP_PAGE_SHIFT);
}
return frags + 2;
}
static int count_skb_frag_slots(struct sk_buff *skb)
{
int i, frags = skb_shinfo(skb)->nr_frags;
int pages = 0;
for (i = 0; i < frags; i++) {
skb_frag_t *frag = skb_shinfo(skb)->frags + i;
unsigned long size = skb_frag_size(frag);
unsigned long offset = skb_frag_off(frag);
/* Skip unused frames from start of page */
offset &= ~HV_HYP_PAGE_MASK;
pages += HVPFN_UP(offset + size);
}
return pages;
}
static int netvsc_get_slots(struct sk_buff *skb)
{
char *data = skb->data;
unsigned int offset = offset_in_hvpage(data);
unsigned int len = skb_headlen(skb);
int slots;
int frag_slots;
slots = DIV_ROUND_UP(offset + len, HV_HYP_PAGE_SIZE);
frag_slots = count_skb_frag_slots(skb);
return slots + frag_slots;
}
static u32 net_checksum_info(struct sk_buff *skb)
{
Annotation
- Immediate include surface: `linux/init.h`, `linux/atomic.h`, `linux/ethtool.h`, `linux/module.h`, `linux/highmem.h`, `linux/device.h`, `linux/io.h`, `linux/delay.h`.
- Detected declarations: `function netvsc_change_rx_flags`, `function netvsc_set_rx_mode`, `function netvsc_tx_enable`, `function netvsc_open`, `function netvsc_wait_until_empty`, `function netvsc_tx_disable`, `function netvsc_close`, `function netvsc_get_tx_queue`, `function default`, `function netvsc_select_queue`.
- 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.
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.