tools/testing/selftests/drivers/net/hw/ncdevmem.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/hw/ncdevmem.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/drivers/net/hw/ncdevmem.c- Extension
.c- Size
- 34891 bytes
- Lines
- 1545
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/uio.hstdarg.hstdio.hstdlib.hunistd.hstdbool.hstring.herrno.hfcntl.hlimits.hmalloc.herror.hpoll.harpa/inet.hsys/socket.hsys/mman.hsys/ioctl.hsys/syscall.hsys/time.hlinux/memfd.hlinux/dma-buf.hlinux/errqueue.hlinux/udmabuf.hlinux/types.hlinux/netlink.hlinux/genetlink.hlinux/netdev.hlinux/ethtool_netlink.htime.hnet/if.hnetdev-user.hethtool-user.h
Detected Declarations
struct memory_bufferstruct memory_providerfunction pr_errfunction udmabuf_freefunction udmabuf_memcpy_to_devicefunction udmabuf_memcpy_from_devicefunction print_nonzero_bytesfunction validate_bufferfunction __run_commandfunction run_commandfunction ethtool_add_flowfunction rxq_numfunction reset_flow_steeringfunction restore_ring_configfunction configure_headersplitfunction configure_rssfunction reset_rssfunction check_changing_channelsfunction configure_flow_steeringfunction bind_rx_queuefunction bind_tx_queuefunction enable_reuseaddrfunction parse_addressfunction do_serverfunction run_devmem_testsfunction gettimeofday_msfunction do_pollfunction wait_complfunction do_clientfunction main
Annotated Snippet
struct memory_buffer {
int fd;
size_t size;
int devfd;
int memfd;
char *buf_mem;
};
struct memory_provider {
struct memory_buffer *(*alloc)(size_t size);
void (*free)(struct memory_buffer *ctx);
void (*memcpy_to_device)(struct memory_buffer *dst, size_t off,
void *src, int n);
void (*memcpy_from_device)(void *dst, struct memory_buffer *src,
size_t off, int n);
};
static void pr_err(const char *fmt, ...)
{
va_list args;
fprintf(stderr, "%s: ", TEST_PREFIX);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
if (errno != 0)
fprintf(stderr, ": %s", strerror(errno));
fprintf(stderr, "\n");
}
static struct memory_buffer *udmabuf_alloc(size_t size)
{
struct udmabuf_create create;
struct memory_buffer *ctx;
int ret;
ctx = malloc(sizeof(*ctx));
if (!ctx)
return NULL;
ctx->size = size;
ctx->devfd = open("/dev/udmabuf", O_RDWR);
if (ctx->devfd < 0) {
pr_err("[skip,no-udmabuf: Unable to access DMA buffer device file]");
goto err_free_ctx;
}
ctx->memfd = memfd_create("udmabuf-test", MFD_ALLOW_SEALING);
if (ctx->memfd < 0) {
pr_err("[skip,no-memfd]");
goto err_close_dev;
}
ret = fcntl(ctx->memfd, F_ADD_SEALS, F_SEAL_SHRINK);
if (ret < 0) {
pr_err("[skip,fcntl-add-seals]");
goto err_close_memfd;
}
ret = ftruncate(ctx->memfd, size);
if (ret == -1) {
pr_err("[FAIL,memfd-truncate]");
goto err_close_memfd;
}
memset(&create, 0, sizeof(create));
create.memfd = ctx->memfd;
create.offset = 0;
create.size = size;
ctx->fd = ioctl(ctx->devfd, UDMABUF_CREATE, &create);
if (ctx->fd < 0) {
pr_err("[FAIL, create udmabuf]");
goto err_close_fd;
}
ctx->buf_mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
ctx->fd, 0);
if (ctx->buf_mem == MAP_FAILED) {
pr_err("[FAIL, map udmabuf]");
goto err_close_fd;
}
return ctx;
err_close_fd:
Annotation
- Immediate include surface: `linux/uio.h`, `stdarg.h`, `stdio.h`, `stdlib.h`, `unistd.h`, `stdbool.h`, `string.h`, `errno.h`.
- Detected declarations: `struct memory_buffer`, `struct memory_provider`, `function pr_err`, `function udmabuf_free`, `function udmabuf_memcpy_to_device`, `function udmabuf_memcpy_from_device`, `function print_nonzero_bytes`, `function validate_buffer`, `function __run_command`, `function run_command`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.