Skip to content

Commit

Permalink
RDMA/mana_ib: Modify QP state
Browse files Browse the repository at this point in the history
Implement modify QP state for RC QPs.

Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
Link: https://lore.kernel.org/r/1716366242-558-4-git-send-email-kotaranov@linux.microsoft.com
Reviewed-by: Long Li <longli@microsoft.com>
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
  • Loading branch information
Konstantin Taranov authored and rleon committed May 30, 2024
1 parent fdefb91 commit e095405
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
37 changes: 37 additions & 0 deletions drivers/infiniband/hw/mana/mana_ib.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ enum mana_ib_command_code {
MANA_IB_DESTROY_CQ = 0x30009,
MANA_IB_CREATE_RC_QP = 0x3000a,
MANA_IB_DESTROY_RC_QP = 0x3000b,
MANA_IB_SET_QP_STATE = 0x3000d,
};

struct mana_ib_query_adapter_caps_req {
Expand Down Expand Up @@ -286,6 +287,42 @@ struct mana_rnic_destroy_rc_qp_resp {
struct gdma_resp_hdr hdr;
}; /* HW Data */

struct mana_ib_ah_attr {
u8 src_addr[16];
u8 dest_addr[16];
u8 src_mac[ETH_ALEN];
u8 dest_mac[ETH_ALEN];
u8 src_addr_type;
u8 dest_addr_type;
u8 hop_limit;
u8 traffic_class;
u16 src_port;
u16 dest_port;
u32 reserved;
};

struct mana_rnic_set_qp_state_req {
struct gdma_req_hdr hdr;
mana_handle_t adapter;
mana_handle_t qp_handle;
u64 attr_mask;
u32 qp_state;
u32 path_mtu;
u32 rq_psn;
u32 sq_psn;
u32 dest_qpn;
u32 max_dest_rd_atomic;
u32 retry_cnt;
u32 rnr_retry;
u32 min_rnr_timer;
u32 reserved;
struct mana_ib_ah_attr ah_attr;
}; /* HW Data */

struct mana_rnic_set_qp_state_resp {
struct gdma_resp_hdr hdr;
}; /* HW Data */

static inline struct gdma_context *mdev_to_gc(struct mana_ib_dev *mdev)
{
return mdev->gdma_dev->gdma_context;
Expand Down
72 changes: 70 additions & 2 deletions drivers/infiniband/hw/mana/qp.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,79 @@ int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
return -EINVAL;
}

static int mana_ib_gd_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
int attr_mask, struct ib_udata *udata)
{
struct mana_ib_dev *mdev = container_of(ibqp->device, struct mana_ib_dev, ib_dev);
struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp);
struct mana_rnic_set_qp_state_resp resp = {};
struct mana_rnic_set_qp_state_req req = {};
struct gdma_context *gc = mdev_to_gc(mdev);
struct mana_port_context *mpc;
struct net_device *ndev;
int err;

mana_gd_init_req_hdr(&req.hdr, MANA_IB_SET_QP_STATE, sizeof(req), sizeof(resp));
req.hdr.dev_id = gc->mana_ib.dev_id;
req.adapter = mdev->adapter_handle;
req.qp_handle = qp->qp_handle;
req.qp_state = attr->qp_state;
req.attr_mask = attr_mask;
req.path_mtu = attr->path_mtu;
req.rq_psn = attr->rq_psn;
req.sq_psn = attr->sq_psn;
req.dest_qpn = attr->dest_qp_num;
req.max_dest_rd_atomic = attr->max_dest_rd_atomic;
req.retry_cnt = attr->retry_cnt;
req.rnr_retry = attr->rnr_retry;
req.min_rnr_timer = attr->min_rnr_timer;
if (attr_mask & IB_QP_AV) {
ndev = mana_ib_get_netdev(&mdev->ib_dev, ibqp->port);
if (!ndev) {
ibdev_dbg(&mdev->ib_dev, "Invalid port %u in QP %u\n",
ibqp->port, ibqp->qp_num);
return -EINVAL;
}
mpc = netdev_priv(ndev);
copy_in_reverse(req.ah_attr.src_mac, mpc->mac_addr, ETH_ALEN);
copy_in_reverse(req.ah_attr.dest_mac, attr->ah_attr.roce.dmac, ETH_ALEN);
copy_in_reverse(req.ah_attr.src_addr, attr->ah_attr.grh.sgid_attr->gid.raw,
sizeof(union ib_gid));
copy_in_reverse(req.ah_attr.dest_addr, attr->ah_attr.grh.dgid.raw,
sizeof(union ib_gid));
if (rdma_gid_attr_network_type(attr->ah_attr.grh.sgid_attr) == RDMA_NETWORK_IPV4) {
req.ah_attr.src_addr_type = SGID_TYPE_IPV4;
req.ah_attr.dest_addr_type = SGID_TYPE_IPV4;
} else {
req.ah_attr.src_addr_type = SGID_TYPE_IPV6;
req.ah_attr.dest_addr_type = SGID_TYPE_IPV6;
}
req.ah_attr.dest_port = ROCE_V2_UDP_DPORT;
req.ah_attr.src_port = rdma_get_udp_sport(attr->ah_attr.grh.flow_label,
ibqp->qp_num, attr->dest_qp_num);
req.ah_attr.traffic_class = attr->ah_attr.grh.traffic_class;
req.ah_attr.hop_limit = attr->ah_attr.grh.hop_limit;
}

err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp);
if (err) {
ibdev_err(&mdev->ib_dev, "Failed modify qp err %d", err);
return err;
}

return 0;
}

int mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
int attr_mask, struct ib_udata *udata)
{
/* modify_qp is not supported by this version of the driver */
return -EOPNOTSUPP;
switch (ibqp->qp_type) {
case IB_QPT_RC:
return mana_ib_gd_modify_qp(ibqp, attr, attr_mask, udata);
default:
ibdev_dbg(ibqp->device, "Modify QP type %u not supported", ibqp->qp_type);
return -EOPNOTSUPP;
}
}

static int mana_ib_destroy_qp_rss(struct mana_ib_qp *qp,
Expand Down

0 comments on commit e095405

Please sign in to comment.