File: cmd_dmah.c

package info (click to toggle)
rdma-core 61.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: ansic: 176,798; python: 15,496; sh: 2,742; perl: 1,465; makefile: 73
file content (48 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
/*
 * Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved
 */

#include <infiniband/cmd_write.h>

int ibv_cmd_alloc_dmah(struct ibv_context *ctx,
		       struct verbs_dmah *dmah,
		       struct ibv_dmah_init_attr *attr)
{
	DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_DMAH, UVERBS_METHOD_DMAH_ALLOC, 4);
	struct ib_uverbs_attr *handle;
	int ret;

	handle = fill_attr_out_obj(cmdb, UVERBS_ATTR_ALLOC_DMAH_HANDLE);
	if (attr->comp_mask & IBV_DMAH_INIT_ATTR_MASK_CPU_ID)
		fill_attr_in_uint32(cmdb, UVERBS_ATTR_ALLOC_DMAH_CPU_ID,
				    attr->cpu_id);
	if (attr->comp_mask & IBV_DMAH_INIT_ATTR_MASK_TPH_MEM_TYPE)
		fill_attr_in_enum(cmdb, UVERBS_ATTR_ALLOC_DMAH_TPH_MEM_TYPE,
				  attr->tph_mem_type, NULL, 0);
	if (attr->comp_mask & IBV_DMAH_INIT_ATTR_MASK_PH)
		fill_attr_in(cmdb, UVERBS_ATTR_ALLOC_DMAH_PH,
			     &attr->ph, sizeof(attr->ph));
	ret = execute_ioctl(ctx, cmdb);
	if (ret)
		return errno;

	dmah->handle = read_attr_obj(UVERBS_ATTR_ALLOC_DMAH_HANDLE, handle);
	dmah->dmah.context = ctx;

	return 0;
}

int ibv_cmd_free_dmah(struct verbs_dmah *dmah)
{
	DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_DMAH, UVERBS_METHOD_DMAH_FREE, 1);
	int ret;

	fill_attr_in_obj(cmdb, UVERBS_ATTR_FREE_DMA_HANDLE, dmah->handle);

	ret = execute_ioctl(dmah->dmah.context, cmdb);
	if (verbs_is_destroy_err(&ret))
		return ret;

	return 0;
}