Skip to content

Commit a60109d

Browse files
yonatancodledford
authored andcommitted
IB/mlx5: Add support for extended atomic operations
Extended atomic operations cmp&swp and fetch&add is a Mellanox feature extending the standard atomic operation to use, varied operand sizes, as apposed to normal atomic operation that use an 8 byte operand only. Extended atomics allows masking the results and arguments. This patch configures QP to support extended atomic operation with the maximum size possible, as exposed by HCA capabilities. Signed-off-by: Yonatan Cohen <yonatanc@mellanox.com> Reviewed-by: Guy Levi <guyle@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent 76d865b commit a60109d

2 files changed

Lines changed: 95 additions & 24 deletions

File tree

‎drivers/infiniband/hw/mlx5/qp.c‎

Lines changed: 84 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,53 @@ static void configure_requester_scat_cqe(struct mlx5_ib_dev *dev,
17331733
MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA32_CQE);
17341734
}
17351735

1736+
static int atomic_size_to_mode(int size_mask)
1737+
{
1738+
/* driver does not support atomic_size > 256B
1739+
* and does not know how to translate bigger sizes
1740+
*/
1741+
int supported_size_mask = size_mask & 0x1ff;
1742+
int log_max_size;
1743+
1744+
if (!supported_size_mask)
1745+
return -EOPNOTSUPP;
1746+
1747+
log_max_size = __fls(supported_size_mask);
1748+
1749+
if (log_max_size > 3)
1750+
return log_max_size;
1751+
1752+
return MLX5_ATOMIC_MODE_8B;
1753+
}
1754+
1755+
static int get_atomic_mode(struct mlx5_ib_dev *dev,
1756+
enum ib_qp_type qp_type)
1757+
{
1758+
u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations);
1759+
u8 atomic = MLX5_CAP_GEN(dev->mdev, atomic);
1760+
int atomic_mode = -EOPNOTSUPP;
1761+
int atomic_size_mask;
1762+
1763+
if (!atomic)
1764+
return -EOPNOTSUPP;
1765+
1766+
if (qp_type == MLX5_IB_QPT_DCT)
1767+
atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc);
1768+
else
1769+
atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp);
1770+
1771+
if ((atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_CMP_SWAP) ||
1772+
(atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_FETCH_ADD))
1773+
atomic_mode = atomic_size_to_mode(atomic_size_mask);
1774+
1775+
if (atomic_mode <= 0 &&
1776+
(atomic_operations & MLX5_ATOMIC_OPS_CMP_SWAP &&
1777+
atomic_operations & MLX5_ATOMIC_OPS_FETCH_ADD))
1778+
atomic_mode = MLX5_ATOMIC_MODE_IB_COMP;
1779+
1780+
return atomic_mode;
1781+
}
1782+
17361783
static inline bool check_flags_mask(uint64_t input, uint64_t supported)
17371784
{
17381785
return (input & ~supported) == 0;
@@ -2562,13 +2609,15 @@ int mlx5_ib_destroy_qp(struct ib_qp *qp)
25622609
return 0;
25632610
}
25642611

2565-
static __be32 to_mlx5_access_flags(struct mlx5_ib_qp *qp, const struct ib_qp_attr *attr,
2566-
int attr_mask)
2612+
static int to_mlx5_access_flags(struct mlx5_ib_qp *qp,
2613+
const struct ib_qp_attr *attr,
2614+
int attr_mask, __be32 *hw_access_flags)
25672615
{
2568-
u32 hw_access_flags = 0;
25692616
u8 dest_rd_atomic;
25702617
u32 access_flags;
25712618

2619+
struct mlx5_ib_dev *dev = to_mdev(qp->ibqp.device);
2620+
25722621
if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
25732622
dest_rd_atomic = attr->max_dest_rd_atomic;
25742623
else
@@ -2583,13 +2632,25 @@ static __be32 to_mlx5_access_flags(struct mlx5_ib_qp *qp, const struct ib_qp_att
25832632
access_flags &= IB_ACCESS_REMOTE_WRITE;
25842633

25852634
if (access_flags & IB_ACCESS_REMOTE_READ)
2586-
hw_access_flags |= MLX5_QP_BIT_RRE;
2587-
if (access_flags & IB_ACCESS_REMOTE_ATOMIC)
2588-
hw_access_flags |= (MLX5_QP_BIT_RAE | MLX5_ATOMIC_MODE_CX);
2635+
*hw_access_flags |= MLX5_QP_BIT_RRE;
2636+
if ((access_flags & IB_ACCESS_REMOTE_ATOMIC) &&
2637+
qp->ibqp.qp_type == IB_QPT_RC) {
2638+
int atomic_mode;
2639+
2640+
atomic_mode = get_atomic_mode(dev, qp->ibqp.qp_type);
2641+
if (atomic_mode < 0)
2642+
return -EOPNOTSUPP;
2643+
2644+
*hw_access_flags |= MLX5_QP_BIT_RAE;
2645+
*hw_access_flags |= atomic_mode << MLX5_ATOMIC_MODE_OFFSET;
2646+
}
2647+
25892648
if (access_flags & IB_ACCESS_REMOTE_WRITE)
2590-
hw_access_flags |= MLX5_QP_BIT_RWE;
2649+
*hw_access_flags |= MLX5_QP_BIT_RWE;
2650+
2651+
*hw_access_flags = cpu_to_be32(*hw_access_flags);
25912652

2592-
return cpu_to_be32(hw_access_flags);
2653+
return 0;
25932654
}
25942655

25952656
enum {
@@ -3287,8 +3348,15 @@ static int __mlx5_ib_modify_qp(struct ib_qp *ibqp,
32873348
cpu_to_be32(fls(attr->max_dest_rd_atomic - 1) << 21);
32883349
}
32893350

3290-
if (attr_mask & (IB_QP_ACCESS_FLAGS | IB_QP_MAX_DEST_RD_ATOMIC))
3291-
context->params2 |= to_mlx5_access_flags(qp, attr, attr_mask);
3351+
if (attr_mask & (IB_QP_ACCESS_FLAGS | IB_QP_MAX_DEST_RD_ATOMIC)) {
3352+
__be32 access_flags = 0;
3353+
3354+
err = to_mlx5_access_flags(qp, attr, attr_mask, &access_flags);
3355+
if (err)
3356+
goto out;
3357+
3358+
context->params2 |= access_flags;
3359+
}
32923360

32933361
if (attr_mask & IB_QP_MIN_RNR_TIMER)
32943362
context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24);
@@ -3504,10 +3572,14 @@ static int mlx5_ib_modify_dct(struct ib_qp *ibqp, struct ib_qp_attr *attr,
35043572
if (attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE)
35053573
MLX5_SET(dctc, dctc, rwe, 1);
35063574
if (attr->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC) {
3507-
if (!mlx5_ib_dc_atomic_is_supported(dev))
3575+
int atomic_mode;
3576+
3577+
atomic_mode = get_atomic_mode(dev, MLX5_IB_QPT_DCT);
3578+
if (atomic_mode < 0)
35083579
return -EOPNOTSUPP;
3580+
3581+
MLX5_SET(dctc, dctc, atomic_mode, atomic_mode);
35093582
MLX5_SET(dctc, dctc, rae, 1);
3510-
MLX5_SET(dctc, dctc, atomic_mode, MLX5_ATOMIC_MODE_DCT_CX);
35113583
}
35123584
MLX5_SET(dctc, dctc, pkey_index, attr->pkey_index);
35133585
MLX5_SET(dctc, dctc, port, attr->port_num);

‎include/linux/mlx5/driver.h‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ enum {
9797
};
9898

9999
enum {
100-
MLX5_ATOMIC_MODE_IB_COMP = 1 << 16,
101-
MLX5_ATOMIC_MODE_CX = 2 << 16,
102-
MLX5_ATOMIC_MODE_8B = 3 << 16,
103-
MLX5_ATOMIC_MODE_16B = 4 << 16,
104-
MLX5_ATOMIC_MODE_32B = 5 << 16,
105-
MLX5_ATOMIC_MODE_64B = 6 << 16,
106-
MLX5_ATOMIC_MODE_128B = 7 << 16,
107-
MLX5_ATOMIC_MODE_256B = 8 << 16,
100+
MLX5_ATOMIC_MODE_OFFSET = 16,
101+
MLX5_ATOMIC_MODE_IB_COMP = 1,
102+
MLX5_ATOMIC_MODE_CX = 2,
103+
MLX5_ATOMIC_MODE_8B = 3,
104+
MLX5_ATOMIC_MODE_16B = 4,
105+
MLX5_ATOMIC_MODE_32B = 5,
106+
MLX5_ATOMIC_MODE_64B = 6,
107+
MLX5_ATOMIC_MODE_128B = 7,
108+
MLX5_ATOMIC_MODE_256B = 8,
108109
};
109110

110111
enum {
@@ -162,13 +163,11 @@ enum mlx5_dcbx_oper_mode {
162163
MLX5E_DCBX_PARAM_VER_OPER_AUTO = 0x3,
163164
};
164165

165-
enum mlx5_dct_atomic_mode {
166-
MLX5_ATOMIC_MODE_DCT_CX = 2,
167-
};
168-
169166
enum {
170167
MLX5_ATOMIC_OPS_CMP_SWAP = 1 << 0,
171168
MLX5_ATOMIC_OPS_FETCH_ADD = 1 << 1,
169+
MLX5_ATOMIC_OPS_EXTENDED_CMP_SWAP = 1 << 2,
170+
MLX5_ATOMIC_OPS_EXTENDED_FETCH_ADD = 1 << 3,
172171
};
173172

174173
enum mlx5_page_fault_resume_flags {

0 commit comments

Comments
 (0)