File: hv.c

package info (click to toggle)
linux 6.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,532,052 kB
  • sloc: ansic: 23,400,063; asm: 266,720; sh: 108,896; makefile: 49,712; python: 36,925; perl: 36,810; cpp: 6,044; yacc: 4,904; lex: 2,722; awk: 1,440; ruby: 25; sed: 5
file content (64 lines) | stat: -rw-r--r-- 1,634 bytes parent folder | download | duplicates (20)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
// Copyright (c) 2018 Mellanox Technologies

#include <linux/hyperv.h>
#include "mlx5_core.h"
#include "lib/hv.h"

static int mlx5_hv_config_common(struct mlx5_core_dev *dev, void *buf, int len,
				 int offset, bool read)
{
	int rc = -EOPNOTSUPP;
	int bytes_returned;
	int block_id;

	if (offset % HV_CONFIG_BLOCK_SIZE_MAX || len != HV_CONFIG_BLOCK_SIZE_MAX)
		return -EINVAL;

	block_id = offset / HV_CONFIG_BLOCK_SIZE_MAX;

	rc = read ?
	     hyperv_read_cfg_blk(dev->pdev, buf,
				 HV_CONFIG_BLOCK_SIZE_MAX, block_id,
				 &bytes_returned) :
	     hyperv_write_cfg_blk(dev->pdev, buf,
				  HV_CONFIG_BLOCK_SIZE_MAX, block_id);

	/* Make sure len bytes were read successfully  */
	if (read && !rc && len != bytes_returned)
		rc = -EIO;

	if (rc) {
		mlx5_core_err(dev, "Failed to %s hv config, err = %d, len = %d, offset = %d\n",
			      read ? "read" : "write", rc, len,
			      offset);
		return rc;
	}

	return 0;
}

int mlx5_hv_read_config(struct mlx5_core_dev *dev, void *buf, int len,
			int offset)
{
	return mlx5_hv_config_common(dev, buf, len, offset, true);
}

int mlx5_hv_write_config(struct mlx5_core_dev *dev, void *buf, int len,
			 int offset)
{
	return mlx5_hv_config_common(dev, buf, len, offset, false);
}

int mlx5_hv_register_invalidate(struct mlx5_core_dev *dev, void *context,
				void (*block_invalidate)(void *context,
							 u64 block_mask))
{
	return hyperv_reg_block_invalidate(dev->pdev, context,
					   block_invalidate);
}

void mlx5_hv_unregister_invalidate(struct mlx5_core_dev *dev)
{
	hyperv_reg_block_invalidate(dev->pdev, NULL, NULL);
}