| 1 |
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
| 2 |
/* |
| 3 |
* Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <rdma/uverbs_std_types.h> |
| 7 |
#include <linux/pci-tph.h> |
| 8 |
#include "dmah.h" |
| 9 |
|
| 10 |
#define UVERBS_MODULE_NAME mlx5_ib |
| 11 |
#include <rdma/uverbs_named_ioctl.h> |
| 12 |
|
| 13 |
static int mlx5_ib_alloc_dmah(struct ib_dmah *ibdmah, |
| 14 |
struct uverbs_attr_bundle *attrs) |
| 15 |
{ |
| 16 |
struct mlx5_core_dev *mdev = to_mdev(ibdmah->device)->mdev; |
| 17 |
struct mlx5_ib_dmah *dmah = to_mdmah(ibdmah); |
| 18 |
u16 st_bits = BIT(IB_DMAH_CPU_ID_EXISTS) | |
| 19 |
BIT(IB_DMAH_MEM_TYPE_EXISTS); |
| 20 |
int err; |
| 21 |
|
| 22 |
/* PH is a must for TPH following PCIe spec 6.2-1.0 */ |
| 23 |
if (!(ibdmah->valid_fields & BIT(IB_DMAH_PH_EXISTS))) |
| 24 |
return -EINVAL; |
| 25 |
|
| 26 |
/* ST is optional; however, partial data for it is not allowed */ |
| 27 |
if (ibdmah->valid_fields & st_bits) { |
| 28 |
if ((ibdmah->valid_fields & st_bits) != st_bits) |
| 29 |
return -EINVAL; |
| 30 |
err = mlx5_st_alloc_index(mdev, ibdmah->mem_type, |
| 31 |
ibdmah->cpu_id, &dmah->st_index); |
| 32 |
if (err) |
| 33 |
return err; |
| 34 |
} |
| 35 |
|
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
static int mlx5_ib_dealloc_dmah(struct ib_dmah *ibdmah, |
| 40 |
struct uverbs_attr_bundle *attrs) |
| 41 |
{ |
| 42 |
struct mlx5_ib_dmah *dmah = to_mdmah(ibdmah); |
| 43 |
struct mlx5_core_dev *mdev = to_mdev(ibdmah->device)->mdev; |
| 44 |
|
| 45 |
if (ibdmah->valid_fields & BIT(IB_DMAH_CPU_ID_EXISTS)) |
| 46 |
return mlx5_st_dealloc_index(mdev, dmah->st_index); |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
const struct ib_device_ops mlx5_ib_dev_dmah_ops = { |
| 52 |
.alloc_dmah = mlx5_ib_alloc_dmah, |
| 53 |
.dealloc_dmah = mlx5_ib_dealloc_dmah, |
| 54 |
}; |