Merge 'mlx5-next' into mlx5-devx
The enhanced devx support series needs commit:
9d43faac02
("net/mlx5: Update mlx5_ifc with DEVX UCTX capabilities bits")
Signed-off-by: Doug Ledford <dledford@redhat.com>
Šī revīzija ir iekļauta:
@@ -1,6 +1,8 @@
|
||||
obj-$(CONFIG_MLX5_INFINIBAND) += mlx5_ib.o
|
||||
|
||||
mlx5_ib-y := main.o cq.o doorbell.o qp.o mem.o srq.o mr.o ah.o mad.o gsi.o ib_virt.o cmd.o cong.o
|
||||
mlx5_ib-y := main.o cq.o doorbell.o qp.o mem.o srq_cmd.o \
|
||||
srq.o mr.o ah.o mad.o gsi.o ib_virt.o cmd.o \
|
||||
cong.o
|
||||
mlx5_ib-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += odp.o
|
||||
mlx5_ib-$(CONFIG_MLX5_ESWITCH) += ib_rep.o
|
||||
mlx5_ib-$(CONFIG_INFINIBAND_USER_ACCESS) += devx.o
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include <rdma/ib_user_verbs.h>
|
||||
#include <rdma/ib_cache.h>
|
||||
#include "mlx5_ib.h"
|
||||
#include "srq.h"
|
||||
|
||||
static void mlx5_ib_cq_comp(struct mlx5_core_cq *cq)
|
||||
{
|
||||
@@ -177,8 +178,7 @@ static void handle_responder(struct ib_wc *wc, struct mlx5_cqe64 *cqe,
|
||||
struct mlx5_core_srq *msrq = NULL;
|
||||
|
||||
if (qp->ibqp.xrcd) {
|
||||
msrq = mlx5_core_get_srq(dev->mdev,
|
||||
be32_to_cpu(cqe->srqn));
|
||||
msrq = mlx5_cmd_get_srq(dev, be32_to_cpu(cqe->srqn));
|
||||
srq = to_mibsrq(msrq);
|
||||
} else {
|
||||
srq = to_msrq(qp->ibqp.srq);
|
||||
|
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "ib_rep.h"
|
||||
#include "srq.h"
|
||||
|
||||
static const struct mlx5_ib_profile rep_profile = {
|
||||
STAGE_CREATE(MLX5_IB_STAGE_INIT,
|
||||
@@ -21,6 +22,9 @@ static const struct mlx5_ib_profile rep_profile = {
|
||||
STAGE_CREATE(MLX5_IB_STAGE_ROCE,
|
||||
mlx5_ib_stage_rep_roce_init,
|
||||
mlx5_ib_stage_rep_roce_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_SRQ,
|
||||
mlx5_init_srq_table,
|
||||
mlx5_cleanup_srq_table),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES,
|
||||
mlx5_ib_stage_dev_res_init,
|
||||
mlx5_ib_stage_dev_res_cleanup),
|
||||
|
@@ -60,6 +60,7 @@
|
||||
#include "mlx5_ib.h"
|
||||
#include "ib_rep.h"
|
||||
#include "cmd.h"
|
||||
#include "srq.h"
|
||||
#include <linux/mlx5/fs_helpers.h>
|
||||
#include <linux/mlx5/accel.h>
|
||||
#include <rdma/uverbs_std_types.h>
|
||||
@@ -82,10 +83,13 @@ static char mlx5_version[] =
|
||||
|
||||
struct mlx5_ib_event_work {
|
||||
struct work_struct work;
|
||||
struct mlx5_core_dev *dev;
|
||||
void *context;
|
||||
enum mlx5_dev_event event;
|
||||
unsigned long param;
|
||||
union {
|
||||
struct mlx5_ib_dev *dev;
|
||||
struct mlx5_ib_multiport_info *mpi;
|
||||
};
|
||||
bool is_slave;
|
||||
unsigned int event;
|
||||
void *param;
|
||||
};
|
||||
|
||||
enum {
|
||||
@@ -4244,6 +4248,63 @@ static void delay_drop_handler(struct work_struct *work)
|
||||
mutex_unlock(&delay_drop->lock);
|
||||
}
|
||||
|
||||
static void handle_general_event(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe,
|
||||
struct ib_event *ibev)
|
||||
{
|
||||
switch (eqe->sub_type) {
|
||||
case MLX5_GENERAL_SUBTYPE_DELAY_DROP_TIMEOUT:
|
||||
schedule_work(&ibdev->delay_drop.delay_drop_work);
|
||||
break;
|
||||
default: /* do nothing */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int handle_port_change(struct mlx5_ib_dev *ibdev, struct mlx5_eqe *eqe,
|
||||
struct ib_event *ibev)
|
||||
{
|
||||
u8 port = (eqe->data.port.port >> 4) & 0xf;
|
||||
|
||||
ibev->element.port_num = port;
|
||||
|
||||
switch (eqe->sub_type) {
|
||||
case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
|
||||
case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
|
||||
case MLX5_PORT_CHANGE_SUBTYPE_INITIALIZED:
|
||||
/* In RoCE, port up/down events are handled in
|
||||
* mlx5_netdev_event().
|
||||
*/
|
||||
if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) ==
|
||||
IB_LINK_LAYER_ETHERNET)
|
||||
return -EINVAL;
|
||||
|
||||
ibev->event = (eqe->sub_type == MLX5_PORT_CHANGE_SUBTYPE_ACTIVE) ?
|
||||
IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
|
||||
break;
|
||||
|
||||
case MLX5_PORT_CHANGE_SUBTYPE_LID:
|
||||
ibev->event = IB_EVENT_LID_CHANGE;
|
||||
break;
|
||||
|
||||
case MLX5_PORT_CHANGE_SUBTYPE_PKEY:
|
||||
ibev->event = IB_EVENT_PKEY_CHANGE;
|
||||
schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work);
|
||||
break;
|
||||
|
||||
case MLX5_PORT_CHANGE_SUBTYPE_GUID:
|
||||
ibev->event = IB_EVENT_GID_CHANGE;
|
||||
break;
|
||||
|
||||
case MLX5_PORT_CHANGE_SUBTYPE_CLIENT_REREG:
|
||||
ibev->event = IB_EVENT_CLIENT_REREGISTER;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mlx5_ib_handle_event(struct work_struct *_work)
|
||||
{
|
||||
struct mlx5_ib_event_work *work =
|
||||
@@ -4251,65 +4312,37 @@ static void mlx5_ib_handle_event(struct work_struct *_work)
|
||||
struct mlx5_ib_dev *ibdev;
|
||||
struct ib_event ibev;
|
||||
bool fatal = false;
|
||||
u8 port = (u8)work->param;
|
||||
|
||||
if (mlx5_core_is_mp_slave(work->dev)) {
|
||||
ibdev = mlx5_ib_get_ibdev_from_mpi(work->context);
|
||||
if (work->is_slave) {
|
||||
ibdev = mlx5_ib_get_ibdev_from_mpi(work->mpi);
|
||||
if (!ibdev)
|
||||
goto out;
|
||||
} else {
|
||||
ibdev = work->context;
|
||||
ibdev = work->dev;
|
||||
}
|
||||
|
||||
switch (work->event) {
|
||||
case MLX5_DEV_EVENT_SYS_ERROR:
|
||||
ibev.event = IB_EVENT_DEVICE_FATAL;
|
||||
mlx5_ib_handle_internal_error(ibdev);
|
||||
ibev.element.port_num = (u8)(unsigned long)work->param;
|
||||
fatal = true;
|
||||
break;
|
||||
|
||||
case MLX5_DEV_EVENT_PORT_UP:
|
||||
case MLX5_DEV_EVENT_PORT_DOWN:
|
||||
case MLX5_DEV_EVENT_PORT_INITIALIZED:
|
||||
/* In RoCE, port up/down events are handled in
|
||||
* mlx5_netdev_event().
|
||||
*/
|
||||
if (mlx5_ib_port_link_layer(&ibdev->ib_dev, port) ==
|
||||
IB_LINK_LAYER_ETHERNET)
|
||||
case MLX5_EVENT_TYPE_PORT_CHANGE:
|
||||
if (handle_port_change(ibdev, work->param, &ibev))
|
||||
goto out;
|
||||
|
||||
ibev.event = (work->event == MLX5_DEV_EVENT_PORT_UP) ?
|
||||
IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
|
||||
break;
|
||||
|
||||
case MLX5_DEV_EVENT_LID_CHANGE:
|
||||
ibev.event = IB_EVENT_LID_CHANGE;
|
||||
break;
|
||||
|
||||
case MLX5_DEV_EVENT_PKEY_CHANGE:
|
||||
ibev.event = IB_EVENT_PKEY_CHANGE;
|
||||
schedule_work(&ibdev->devr.ports[port - 1].pkey_change_work);
|
||||
break;
|
||||
|
||||
case MLX5_DEV_EVENT_GUID_CHANGE:
|
||||
ibev.event = IB_EVENT_GID_CHANGE;
|
||||
break;
|
||||
|
||||
case MLX5_DEV_EVENT_CLIENT_REREG:
|
||||
ibev.event = IB_EVENT_CLIENT_REREGISTER;
|
||||
break;
|
||||
case MLX5_DEV_EVENT_DELAY_DROP_TIMEOUT:
|
||||
schedule_work(&ibdev->delay_drop.delay_drop_work);
|
||||
goto out;
|
||||
case MLX5_EVENT_TYPE_GENERAL_EVENT:
|
||||
handle_general_event(ibdev, work->param, &ibev);
|
||||
/* fall through */
|
||||
default:
|
||||
goto out;
|
||||
}
|
||||
|
||||
ibev.device = &ibdev->ib_dev;
|
||||
ibev.element.port_num = port;
|
||||
ibev.device = &ibdev->ib_dev;
|
||||
|
||||
if (!rdma_is_port_valid(&ibdev->ib_dev, port)) {
|
||||
mlx5_ib_warn(ibdev, "warning: event on port %d\n", port);
|
||||
if (!rdma_is_port_valid(&ibdev->ib_dev, ibev.element.port_num)) {
|
||||
mlx5_ib_warn(ibdev, "warning: event on port %d\n", ibev.element.port_num);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -4322,22 +4355,43 @@ out:
|
||||
kfree(work);
|
||||
}
|
||||
|
||||
static void mlx5_ib_event(struct mlx5_core_dev *dev, void *context,
|
||||
enum mlx5_dev_event event, unsigned long param)
|
||||
static int mlx5_ib_event(struct notifier_block *nb,
|
||||
unsigned long event, void *param)
|
||||
{
|
||||
struct mlx5_ib_event_work *work;
|
||||
|
||||
work = kmalloc(sizeof(*work), GFP_ATOMIC);
|
||||
if (!work)
|
||||
return;
|
||||
return NOTIFY_DONE;
|
||||
|
||||
INIT_WORK(&work->work, mlx5_ib_handle_event);
|
||||
work->dev = dev;
|
||||
work->dev = container_of(nb, struct mlx5_ib_dev, mdev_events);
|
||||
work->is_slave = false;
|
||||
work->param = param;
|
||||
work->context = context;
|
||||
work->event = event;
|
||||
|
||||
queue_work(mlx5_ib_event_wq, &work->work);
|
||||
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static int mlx5_ib_event_slave_port(struct notifier_block *nb,
|
||||
unsigned long event, void *param)
|
||||
{
|
||||
struct mlx5_ib_event_work *work;
|
||||
|
||||
work = kmalloc(sizeof(*work), GFP_ATOMIC);
|
||||
if (!work)
|
||||
return NOTIFY_DONE;
|
||||
|
||||
INIT_WORK(&work->work, mlx5_ib_handle_event);
|
||||
work->mpi = container_of(nb, struct mlx5_ib_multiport_info, mdev_events);
|
||||
work->is_slave = true;
|
||||
work->param = param;
|
||||
work->event = event;
|
||||
queue_work(mlx5_ib_event_wq, &work->work);
|
||||
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static int set_has_smi_cap(struct mlx5_ib_dev *dev)
|
||||
@@ -5360,6 +5414,11 @@ static void mlx5_ib_unbind_slave_port(struct mlx5_ib_dev *ibdev,
|
||||
spin_unlock(&port->mp.mpi_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mpi->mdev_events.notifier_call)
|
||||
mlx5_notifier_unregister(mpi->mdev, &mpi->mdev_events);
|
||||
mpi->mdev_events.notifier_call = NULL;
|
||||
|
||||
mpi->ibdev = NULL;
|
||||
|
||||
spin_unlock(&port->mp.mpi_lock);
|
||||
@@ -5415,6 +5474,7 @@ static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev,
|
||||
|
||||
ibdev->port[port_num].mp.mpi = mpi;
|
||||
mpi->ibdev = ibdev;
|
||||
mpi->mdev_events.notifier_call = NULL;
|
||||
spin_unlock(&ibdev->port[port_num].mp.mpi_lock);
|
||||
|
||||
err = mlx5_nic_vport_affiliate_multiport(ibdev->mdev, mpi->mdev);
|
||||
@@ -5432,6 +5492,9 @@ static bool mlx5_ib_bind_slave_port(struct mlx5_ib_dev *ibdev,
|
||||
goto unbind;
|
||||
}
|
||||
|
||||
mpi->mdev_events.notifier_call = mlx5_ib_event_slave_port;
|
||||
mlx5_notifier_register(mpi->mdev, &mpi->mdev_events);
|
||||
|
||||
err = mlx5_ib_init_cong_debugfs(ibdev, port_num);
|
||||
if (err)
|
||||
goto unbind;
|
||||
@@ -6155,6 +6218,34 @@ static void mlx5_ib_stage_rep_reg_cleanup(struct mlx5_ib_dev *dev)
|
||||
mlx5_ib_unregister_vport_reps(dev);
|
||||
}
|
||||
|
||||
static int mlx5_ib_stage_dev_notifier_init(struct mlx5_ib_dev *dev)
|
||||
{
|
||||
dev->mdev_events.notifier_call = mlx5_ib_event;
|
||||
mlx5_notifier_register(dev->mdev, &dev->mdev_events);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mlx5_ib_stage_dev_notifier_cleanup(struct mlx5_ib_dev *dev)
|
||||
{
|
||||
mlx5_notifier_unregister(dev->mdev, &dev->mdev_events);
|
||||
}
|
||||
|
||||
static int mlx5_ib_stage_devx_init(struct mlx5_ib_dev *dev)
|
||||
{
|
||||
int uid;
|
||||
|
||||
uid = mlx5_ib_devx_create(dev);
|
||||
if (uid > 0)
|
||||
dev->devx_whitelist_uid = uid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
static void mlx5_ib_stage_devx_cleanup(struct mlx5_ib_dev *dev)
|
||||
{
|
||||
if (dev->devx_whitelist_uid)
|
||||
mlx5_ib_devx_destroy(dev, dev->devx_whitelist_uid);
|
||||
}
|
||||
|
||||
void __mlx5_ib_remove(struct mlx5_ib_dev *dev,
|
||||
const struct mlx5_ib_profile *profile,
|
||||
int stage)
|
||||
@@ -6166,8 +6257,6 @@ void __mlx5_ib_remove(struct mlx5_ib_dev *dev,
|
||||
profile->stage[stage].cleanup(dev);
|
||||
}
|
||||
|
||||
if (dev->devx_whitelist_uid)
|
||||
mlx5_ib_devx_destroy(dev, dev->devx_whitelist_uid);
|
||||
ib_dealloc_device((struct ib_device *)dev);
|
||||
}
|
||||
|
||||
@@ -6176,7 +6265,6 @@ void *__mlx5_ib_add(struct mlx5_ib_dev *dev,
|
||||
{
|
||||
int err;
|
||||
int i;
|
||||
int uid;
|
||||
|
||||
for (i = 0; i < MLX5_IB_STAGE_MAX; i++) {
|
||||
if (profile->stage[i].init) {
|
||||
@@ -6186,10 +6274,6 @@ void *__mlx5_ib_add(struct mlx5_ib_dev *dev,
|
||||
}
|
||||
}
|
||||
|
||||
uid = mlx5_ib_devx_create(dev);
|
||||
if (uid > 0)
|
||||
dev->devx_whitelist_uid = uid;
|
||||
|
||||
dev->profile = profile;
|
||||
dev->ib_active = true;
|
||||
|
||||
@@ -6217,9 +6301,15 @@ static const struct mlx5_ib_profile pf_profile = {
|
||||
STAGE_CREATE(MLX5_IB_STAGE_ROCE,
|
||||
mlx5_ib_stage_roce_init,
|
||||
mlx5_ib_stage_roce_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_SRQ,
|
||||
mlx5_init_srq_table,
|
||||
mlx5_cleanup_srq_table),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES,
|
||||
mlx5_ib_stage_dev_res_init,
|
||||
mlx5_ib_stage_dev_res_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER,
|
||||
mlx5_ib_stage_dev_notifier_init,
|
||||
mlx5_ib_stage_dev_notifier_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_ODP,
|
||||
mlx5_ib_stage_odp_init,
|
||||
mlx5_ib_stage_odp_cleanup),
|
||||
@@ -6238,6 +6328,9 @@ static const struct mlx5_ib_profile pf_profile = {
|
||||
STAGE_CREATE(MLX5_IB_STAGE_PRE_IB_REG_UMR,
|
||||
NULL,
|
||||
mlx5_ib_stage_pre_ib_reg_umr_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_WHITELIST_UID,
|
||||
mlx5_ib_stage_devx_init,
|
||||
mlx5_ib_stage_devx_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_IB_REG,
|
||||
mlx5_ib_stage_ib_reg_init,
|
||||
mlx5_ib_stage_ib_reg_cleanup),
|
||||
@@ -6265,9 +6358,15 @@ static const struct mlx5_ib_profile nic_rep_profile = {
|
||||
STAGE_CREATE(MLX5_IB_STAGE_ROCE,
|
||||
mlx5_ib_stage_rep_roce_init,
|
||||
mlx5_ib_stage_rep_roce_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_SRQ,
|
||||
mlx5_init_srq_table,
|
||||
mlx5_cleanup_srq_table),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_RESOURCES,
|
||||
mlx5_ib_stage_dev_res_init,
|
||||
mlx5_ib_stage_dev_res_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_DEVICE_NOTIFIER,
|
||||
mlx5_ib_stage_dev_notifier_init,
|
||||
mlx5_ib_stage_dev_notifier_cleanup),
|
||||
STAGE_CREATE(MLX5_IB_STAGE_COUNTERS,
|
||||
mlx5_ib_stage_counters_init,
|
||||
mlx5_ib_stage_counters_cleanup),
|
||||
@@ -6385,7 +6484,6 @@ static void mlx5_ib_remove(struct mlx5_core_dev *mdev, void *context)
|
||||
static struct mlx5_interface mlx5_ib_interface = {
|
||||
.add = mlx5_ib_add,
|
||||
.remove = mlx5_ib_remove,
|
||||
.event = mlx5_ib_event,
|
||||
.protocol = MLX5_INTERFACE_PROTOCOL_IB,
|
||||
};
|
||||
|
||||
|
@@ -41,7 +41,6 @@
|
||||
#include <linux/mlx5/cq.h>
|
||||
#include <linux/mlx5/fs.h>
|
||||
#include <linux/mlx5/qp.h>
|
||||
#include <linux/mlx5/srq.h>
|
||||
#include <linux/mlx5/fs.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/mlx5/transobj.h>
|
||||
@@ -50,6 +49,8 @@
|
||||
#include <rdma/uverbs_ioctl.h>
|
||||
#include <rdma/mlx5_user_ioctl_cmds.h>
|
||||
|
||||
#include "srq.h"
|
||||
|
||||
#define mlx5_ib_dbg(_dev, format, arg...) \
|
||||
dev_dbg(&(_dev)->ib_dev.dev, "%s:%d:(pid %d): " format, __func__, \
|
||||
__LINE__, current->pid, ##arg)
|
||||
@@ -776,13 +777,16 @@ enum mlx5_ib_stages {
|
||||
MLX5_IB_STAGE_CAPS,
|
||||
MLX5_IB_STAGE_NON_DEFAULT_CB,
|
||||
MLX5_IB_STAGE_ROCE,
|
||||
MLX5_IB_STAGE_SRQ,
|
||||
MLX5_IB_STAGE_DEVICE_RESOURCES,
|
||||
MLX5_IB_STAGE_DEVICE_NOTIFIER,
|
||||
MLX5_IB_STAGE_ODP,
|
||||
MLX5_IB_STAGE_COUNTERS,
|
||||
MLX5_IB_STAGE_CONG_DEBUGFS,
|
||||
MLX5_IB_STAGE_UAR,
|
||||
MLX5_IB_STAGE_BFREG,
|
||||
MLX5_IB_STAGE_PRE_IB_REG_UMR,
|
||||
MLX5_IB_STAGE_WHITELIST_UID,
|
||||
MLX5_IB_STAGE_IB_REG,
|
||||
MLX5_IB_STAGE_POST_IB_REG_UMR,
|
||||
MLX5_IB_STAGE_DELAY_DROP,
|
||||
@@ -807,6 +811,7 @@ struct mlx5_ib_multiport_info {
|
||||
struct list_head list;
|
||||
struct mlx5_ib_dev *ibdev;
|
||||
struct mlx5_core_dev *mdev;
|
||||
struct notifier_block mdev_events;
|
||||
struct completion unref_comp;
|
||||
u64 sys_image_guid;
|
||||
u32 mdev_refcnt;
|
||||
@@ -893,6 +898,7 @@ struct mlx5_ib_pf_eq {
|
||||
struct mlx5_ib_dev {
|
||||
struct ib_device ib_dev;
|
||||
struct mlx5_core_dev *mdev;
|
||||
struct notifier_block mdev_events;
|
||||
struct mlx5_roce roce[MLX5_MAX_PORTS];
|
||||
int num_ports;
|
||||
/* serialize update of capability mask
|
||||
@@ -938,6 +944,7 @@ struct mlx5_ib_dev {
|
||||
u64 sys_image_guid;
|
||||
struct mlx5_memic memic;
|
||||
u16 devx_whitelist_uid;
|
||||
struct mlx5_srq_table srq_table;
|
||||
};
|
||||
|
||||
static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
|
||||
|
@@ -1,46 +1,15 @@
|
||||
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
|
||||
/*
|
||||
* Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved.
|
||||
*
|
||||
* This software is available to you under a choice of one of two
|
||||
* licenses. You may choose to be licensed under the terms of the GNU
|
||||
* General Public License (GPL) Version 2, available from the file
|
||||
* COPYING in the main directory of this source tree, or the
|
||||
* OpenIB.org BSD license below:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that the following
|
||||
* conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* Copyright (c) 2013-2018, Mellanox Technologies inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/mlx5/qp.h>
|
||||
#include <linux/mlx5/srq.h>
|
||||
#include <linux/slab.h>
|
||||
#include <rdma/ib_umem.h>
|
||||
#include <rdma/ib_user_verbs.h>
|
||||
|
||||
#include "mlx5_ib.h"
|
||||
|
||||
/* not supported currently */
|
||||
static int srq_signature;
|
||||
#include "srq.h"
|
||||
|
||||
static void *get_wqe(struct mlx5_ib_srq *srq, int n)
|
||||
{
|
||||
@@ -206,7 +175,7 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq,
|
||||
err = -ENOMEM;
|
||||
goto err_in;
|
||||
}
|
||||
srq->wq_sig = !!srq_signature;
|
||||
srq->wq_sig = 0;
|
||||
|
||||
in->log_page_size = srq->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT;
|
||||
if (MLX5_CAP_GEN(dev->mdev, cqe_version) == MLX5_CQE_VERSION_V1 &&
|
||||
@@ -331,7 +300,7 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
|
||||
|
||||
in.pd = to_mpd(pd)->pdn;
|
||||
in.db_record = srq->db.dma;
|
||||
err = mlx5_core_create_srq(dev->mdev, &srq->msrq, &in);
|
||||
err = mlx5_cmd_create_srq(dev, &srq->msrq, &in);
|
||||
kvfree(in.pas);
|
||||
if (err) {
|
||||
mlx5_ib_dbg(dev, "create SRQ failed, err %d\n", err);
|
||||
@@ -355,7 +324,7 @@ struct ib_srq *mlx5_ib_create_srq(struct ib_pd *pd,
|
||||
return &srq->ibsrq;
|
||||
|
||||
err_core:
|
||||
mlx5_core_destroy_srq(dev->mdev, &srq->msrq);
|
||||
mlx5_cmd_destroy_srq(dev, &srq->msrq);
|
||||
|
||||
err_usr_kern_srq:
|
||||
if (pd->uobject)
|
||||
@@ -385,7 +354,7 @@ int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&srq->mutex);
|
||||
ret = mlx5_core_arm_srq(dev->mdev, &srq->msrq, attr->srq_limit, 1);
|
||||
ret = mlx5_cmd_arm_srq(dev, &srq->msrq, attr->srq_limit, 1);
|
||||
mutex_unlock(&srq->mutex);
|
||||
|
||||
if (ret)
|
||||
@@ -406,7 +375,7 @@ int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr)
|
||||
if (!out)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = mlx5_core_query_srq(dev->mdev, &srq->msrq, out);
|
||||
ret = mlx5_cmd_query_srq(dev, &srq->msrq, out);
|
||||
if (ret)
|
||||
goto out_box;
|
||||
|
||||
@@ -424,7 +393,7 @@ int mlx5_ib_destroy_srq(struct ib_srq *srq)
|
||||
struct mlx5_ib_dev *dev = to_mdev(srq->device);
|
||||
struct mlx5_ib_srq *msrq = to_msrq(srq);
|
||||
|
||||
mlx5_core_destroy_srq(dev->mdev, &msrq->msrq);
|
||||
mlx5_cmd_destroy_srq(dev, &msrq->msrq);
|
||||
|
||||
if (srq->uobject) {
|
||||
mlx5_ib_db_unmap_user(to_mucontext(srq->uobject->context), &msrq->db);
|
||||
|
73
drivers/infiniband/hw/mlx5/srq.h
Parasts fails
73
drivers/infiniband/hw/mlx5/srq.h
Parasts fails
@@ -0,0 +1,73 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
|
||||
/*
|
||||
* Copyright (c) 2013-2018, Mellanox Technologies. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef MLX5_IB_SRQ_H
|
||||
#define MLX5_IB_SRQ_H
|
||||
|
||||
enum {
|
||||
MLX5_SRQ_FLAG_ERR = (1 << 0),
|
||||
MLX5_SRQ_FLAG_WQ_SIG = (1 << 1),
|
||||
MLX5_SRQ_FLAG_RNDV = (1 << 2),
|
||||
};
|
||||
|
||||
struct mlx5_srq_attr {
|
||||
u32 type;
|
||||
u32 flags;
|
||||
u32 log_size;
|
||||
u32 wqe_shift;
|
||||
u32 log_page_size;
|
||||
u32 wqe_cnt;
|
||||
u32 srqn;
|
||||
u32 xrcd;
|
||||
u32 page_offset;
|
||||
u32 cqn;
|
||||
u32 pd;
|
||||
u32 lwm;
|
||||
u32 user_index;
|
||||
u64 db_record;
|
||||
__be64 *pas;
|
||||
u32 tm_log_list_size;
|
||||
u32 tm_next_tag;
|
||||
u32 tm_hw_phase_cnt;
|
||||
u32 tm_sw_phase_cnt;
|
||||
u16 uid;
|
||||
};
|
||||
|
||||
struct mlx5_ib_dev;
|
||||
|
||||
struct mlx5_core_srq {
|
||||
struct mlx5_core_rsc_common common; /* must be first */
|
||||
u32 srqn;
|
||||
int max;
|
||||
size_t max_gs;
|
||||
size_t max_avail_gather;
|
||||
int wqe_shift;
|
||||
void (*event)(struct mlx5_core_srq *srq, enum mlx5_event e);
|
||||
|
||||
atomic_t refcount;
|
||||
struct completion free;
|
||||
u16 uid;
|
||||
};
|
||||
|
||||
struct mlx5_srq_table {
|
||||
struct notifier_block nb;
|
||||
/* protect radix tree
|
||||
*/
|
||||
spinlock_t lock;
|
||||
struct radix_tree_root tree;
|
||||
};
|
||||
|
||||
int mlx5_cmd_create_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *in);
|
||||
int mlx5_cmd_destroy_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq);
|
||||
int mlx5_cmd_query_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *out);
|
||||
int mlx5_cmd_arm_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
u16 lwm, int is_srq);
|
||||
struct mlx5_core_srq *mlx5_cmd_get_srq(struct mlx5_ib_dev *dev, u32 srqn);
|
||||
|
||||
int mlx5_init_srq_table(struct mlx5_ib_dev *dev);
|
||||
void mlx5_cleanup_srq_table(struct mlx5_ib_dev *dev);
|
||||
#endif /* MLX5_IB_SRQ_H */
|
722
drivers/infiniband/hw/mlx5/srq_cmd.c
Parasts fails
722
drivers/infiniband/hw/mlx5/srq_cmd.c
Parasts fails
@@ -0,0 +1,722 @@
|
||||
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
|
||||
/*
|
||||
* Copyright (c) 2013-2018, Mellanox Technologies inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/mlx5/driver.h>
|
||||
#include <linux/mlx5/cmd.h>
|
||||
#include "mlx5_ib.h"
|
||||
#include "srq.h"
|
||||
|
||||
static int get_pas_size(struct mlx5_srq_attr *in)
|
||||
{
|
||||
u32 log_page_size = in->log_page_size + 12;
|
||||
u32 log_srq_size = in->log_size;
|
||||
u32 log_rq_stride = in->wqe_shift;
|
||||
u32 page_offset = in->page_offset;
|
||||
u32 po_quanta = 1 << (log_page_size - 6);
|
||||
u32 rq_sz = 1 << (log_srq_size + 4 + log_rq_stride);
|
||||
u32 page_size = 1 << log_page_size;
|
||||
u32 rq_sz_po = rq_sz + (page_offset * po_quanta);
|
||||
u32 rq_num_pas = DIV_ROUND_UP(rq_sz_po, page_size);
|
||||
|
||||
return rq_num_pas * sizeof(u64);
|
||||
}
|
||||
|
||||
static void set_wq(void *wq, struct mlx5_srq_attr *in)
|
||||
{
|
||||
MLX5_SET(wq, wq, wq_signature, !!(in->flags
|
||||
& MLX5_SRQ_FLAG_WQ_SIG));
|
||||
MLX5_SET(wq, wq, log_wq_pg_sz, in->log_page_size);
|
||||
MLX5_SET(wq, wq, log_wq_stride, in->wqe_shift + 4);
|
||||
MLX5_SET(wq, wq, log_wq_sz, in->log_size);
|
||||
MLX5_SET(wq, wq, page_offset, in->page_offset);
|
||||
MLX5_SET(wq, wq, lwm, in->lwm);
|
||||
MLX5_SET(wq, wq, pd, in->pd);
|
||||
MLX5_SET64(wq, wq, dbr_addr, in->db_record);
|
||||
}
|
||||
|
||||
static void set_srqc(void *srqc, struct mlx5_srq_attr *in)
|
||||
{
|
||||
MLX5_SET(srqc, srqc, wq_signature, !!(in->flags
|
||||
& MLX5_SRQ_FLAG_WQ_SIG));
|
||||
MLX5_SET(srqc, srqc, log_page_size, in->log_page_size);
|
||||
MLX5_SET(srqc, srqc, log_rq_stride, in->wqe_shift);
|
||||
MLX5_SET(srqc, srqc, log_srq_size, in->log_size);
|
||||
MLX5_SET(srqc, srqc, page_offset, in->page_offset);
|
||||
MLX5_SET(srqc, srqc, lwm, in->lwm);
|
||||
MLX5_SET(srqc, srqc, pd, in->pd);
|
||||
MLX5_SET64(srqc, srqc, dbr_addr, in->db_record);
|
||||
MLX5_SET(srqc, srqc, xrcd, in->xrcd);
|
||||
MLX5_SET(srqc, srqc, cqn, in->cqn);
|
||||
}
|
||||
|
||||
static void get_wq(void *wq, struct mlx5_srq_attr *in)
|
||||
{
|
||||
if (MLX5_GET(wq, wq, wq_signature))
|
||||
in->flags &= MLX5_SRQ_FLAG_WQ_SIG;
|
||||
in->log_page_size = MLX5_GET(wq, wq, log_wq_pg_sz);
|
||||
in->wqe_shift = MLX5_GET(wq, wq, log_wq_stride) - 4;
|
||||
in->log_size = MLX5_GET(wq, wq, log_wq_sz);
|
||||
in->page_offset = MLX5_GET(wq, wq, page_offset);
|
||||
in->lwm = MLX5_GET(wq, wq, lwm);
|
||||
in->pd = MLX5_GET(wq, wq, pd);
|
||||
in->db_record = MLX5_GET64(wq, wq, dbr_addr);
|
||||
}
|
||||
|
||||
static void get_srqc(void *srqc, struct mlx5_srq_attr *in)
|
||||
{
|
||||
if (MLX5_GET(srqc, srqc, wq_signature))
|
||||
in->flags &= MLX5_SRQ_FLAG_WQ_SIG;
|
||||
in->log_page_size = MLX5_GET(srqc, srqc, log_page_size);
|
||||
in->wqe_shift = MLX5_GET(srqc, srqc, log_rq_stride);
|
||||
in->log_size = MLX5_GET(srqc, srqc, log_srq_size);
|
||||
in->page_offset = MLX5_GET(srqc, srqc, page_offset);
|
||||
in->lwm = MLX5_GET(srqc, srqc, lwm);
|
||||
in->pd = MLX5_GET(srqc, srqc, pd);
|
||||
in->db_record = MLX5_GET64(srqc, srqc, dbr_addr);
|
||||
}
|
||||
|
||||
struct mlx5_core_srq *mlx5_cmd_get_srq(struct mlx5_ib_dev *dev, u32 srqn)
|
||||
{
|
||||
struct mlx5_srq_table *table = &dev->srq_table;
|
||||
struct mlx5_core_srq *srq;
|
||||
|
||||
spin_lock(&table->lock);
|
||||
|
||||
srq = radix_tree_lookup(&table->tree, srqn);
|
||||
if (srq)
|
||||
atomic_inc(&srq->refcount);
|
||||
|
||||
spin_unlock(&table->lock);
|
||||
|
||||
return srq;
|
||||
}
|
||||
|
||||
static int create_srq_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *in)
|
||||
{
|
||||
u32 create_out[MLX5_ST_SZ_DW(create_srq_out)] = {0};
|
||||
void *create_in;
|
||||
void *srqc;
|
||||
void *pas;
|
||||
int pas_size;
|
||||
int inlen;
|
||||
int err;
|
||||
|
||||
pas_size = get_pas_size(in);
|
||||
inlen = MLX5_ST_SZ_BYTES(create_srq_in) + pas_size;
|
||||
create_in = kvzalloc(inlen, GFP_KERNEL);
|
||||
if (!create_in)
|
||||
return -ENOMEM;
|
||||
|
||||
MLX5_SET(create_srq_in, create_in, uid, in->uid);
|
||||
srqc = MLX5_ADDR_OF(create_srq_in, create_in, srq_context_entry);
|
||||
pas = MLX5_ADDR_OF(create_srq_in, create_in, pas);
|
||||
|
||||
set_srqc(srqc, in);
|
||||
memcpy(pas, in->pas, pas_size);
|
||||
|
||||
MLX5_SET(create_srq_in, create_in, opcode,
|
||||
MLX5_CMD_OP_CREATE_SRQ);
|
||||
|
||||
err = mlx5_cmd_exec(dev->mdev, create_in, inlen, create_out,
|
||||
sizeof(create_out));
|
||||
kvfree(create_in);
|
||||
if (!err) {
|
||||
srq->srqn = MLX5_GET(create_srq_out, create_out, srqn);
|
||||
srq->uid = in->uid;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int destroy_srq_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq)
|
||||
{
|
||||
u32 srq_in[MLX5_ST_SZ_DW(destroy_srq_in)] = {0};
|
||||
u32 srq_out[MLX5_ST_SZ_DW(destroy_srq_out)] = {0};
|
||||
|
||||
MLX5_SET(destroy_srq_in, srq_in, opcode,
|
||||
MLX5_CMD_OP_DESTROY_SRQ);
|
||||
MLX5_SET(destroy_srq_in, srq_in, srqn, srq->srqn);
|
||||
MLX5_SET(destroy_srq_in, srq_in, uid, srq->uid);
|
||||
|
||||
return mlx5_cmd_exec(dev->mdev, srq_in, sizeof(srq_in), srq_out,
|
||||
sizeof(srq_out));
|
||||
}
|
||||
|
||||
static int arm_srq_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
u16 lwm, int is_srq)
|
||||
{
|
||||
u32 srq_in[MLX5_ST_SZ_DW(arm_rq_in)] = {0};
|
||||
u32 srq_out[MLX5_ST_SZ_DW(arm_rq_out)] = {0};
|
||||
|
||||
MLX5_SET(arm_rq_in, srq_in, opcode, MLX5_CMD_OP_ARM_RQ);
|
||||
MLX5_SET(arm_rq_in, srq_in, op_mod, MLX5_ARM_RQ_IN_OP_MOD_SRQ);
|
||||
MLX5_SET(arm_rq_in, srq_in, srq_number, srq->srqn);
|
||||
MLX5_SET(arm_rq_in, srq_in, lwm, lwm);
|
||||
MLX5_SET(arm_rq_in, srq_in, uid, srq->uid);
|
||||
|
||||
return mlx5_cmd_exec(dev->mdev, srq_in, sizeof(srq_in), srq_out,
|
||||
sizeof(srq_out));
|
||||
}
|
||||
|
||||
static int query_srq_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *out)
|
||||
{
|
||||
u32 srq_in[MLX5_ST_SZ_DW(query_srq_in)] = {0};
|
||||
u32 *srq_out;
|
||||
void *srqc;
|
||||
int err;
|
||||
|
||||
srq_out = kvzalloc(MLX5_ST_SZ_BYTES(query_srq_out), GFP_KERNEL);
|
||||
if (!srq_out)
|
||||
return -ENOMEM;
|
||||
|
||||
MLX5_SET(query_srq_in, srq_in, opcode,
|
||||
MLX5_CMD_OP_QUERY_SRQ);
|
||||
MLX5_SET(query_srq_in, srq_in, srqn, srq->srqn);
|
||||
err = mlx5_cmd_exec(dev->mdev, srq_in, sizeof(srq_in), srq_out,
|
||||
MLX5_ST_SZ_BYTES(query_srq_out));
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
srqc = MLX5_ADDR_OF(query_srq_out, srq_out, srq_context_entry);
|
||||
get_srqc(srqc, out);
|
||||
if (MLX5_GET(srqc, srqc, state) != MLX5_SRQC_STATE_GOOD)
|
||||
out->flags |= MLX5_SRQ_FLAG_ERR;
|
||||
out:
|
||||
kvfree(srq_out);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int create_xrc_srq_cmd(struct mlx5_ib_dev *dev,
|
||||
struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *in)
|
||||
{
|
||||
u32 create_out[MLX5_ST_SZ_DW(create_xrc_srq_out)];
|
||||
void *create_in;
|
||||
void *xrc_srqc;
|
||||
void *pas;
|
||||
int pas_size;
|
||||
int inlen;
|
||||
int err;
|
||||
|
||||
pas_size = get_pas_size(in);
|
||||
inlen = MLX5_ST_SZ_BYTES(create_xrc_srq_in) + pas_size;
|
||||
create_in = kvzalloc(inlen, GFP_KERNEL);
|
||||
if (!create_in)
|
||||
return -ENOMEM;
|
||||
|
||||
MLX5_SET(create_xrc_srq_in, create_in, uid, in->uid);
|
||||
xrc_srqc = MLX5_ADDR_OF(create_xrc_srq_in, create_in,
|
||||
xrc_srq_context_entry);
|
||||
pas = MLX5_ADDR_OF(create_xrc_srq_in, create_in, pas);
|
||||
|
||||
set_srqc(xrc_srqc, in);
|
||||
MLX5_SET(xrc_srqc, xrc_srqc, user_index, in->user_index);
|
||||
memcpy(pas, in->pas, pas_size);
|
||||
MLX5_SET(create_xrc_srq_in, create_in, opcode,
|
||||
MLX5_CMD_OP_CREATE_XRC_SRQ);
|
||||
|
||||
memset(create_out, 0, sizeof(create_out));
|
||||
err = mlx5_cmd_exec(dev->mdev, create_in, inlen, create_out,
|
||||
sizeof(create_out));
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
srq->srqn = MLX5_GET(create_xrc_srq_out, create_out, xrc_srqn);
|
||||
srq->uid = in->uid;
|
||||
out:
|
||||
kvfree(create_in);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int destroy_xrc_srq_cmd(struct mlx5_ib_dev *dev,
|
||||
struct mlx5_core_srq *srq)
|
||||
{
|
||||
u32 xrcsrq_in[MLX5_ST_SZ_DW(destroy_xrc_srq_in)] = {0};
|
||||
u32 xrcsrq_out[MLX5_ST_SZ_DW(destroy_xrc_srq_out)] = {0};
|
||||
|
||||
MLX5_SET(destroy_xrc_srq_in, xrcsrq_in, opcode,
|
||||
MLX5_CMD_OP_DESTROY_XRC_SRQ);
|
||||
MLX5_SET(destroy_xrc_srq_in, xrcsrq_in, xrc_srqn, srq->srqn);
|
||||
MLX5_SET(destroy_xrc_srq_in, xrcsrq_in, uid, srq->uid);
|
||||
|
||||
return mlx5_cmd_exec(dev->mdev, xrcsrq_in, sizeof(xrcsrq_in),
|
||||
xrcsrq_out, sizeof(xrcsrq_out));
|
||||
}
|
||||
|
||||
static int arm_xrc_srq_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
u16 lwm)
|
||||
{
|
||||
u32 xrcsrq_in[MLX5_ST_SZ_DW(arm_xrc_srq_in)] = {0};
|
||||
u32 xrcsrq_out[MLX5_ST_SZ_DW(arm_xrc_srq_out)] = {0};
|
||||
|
||||
MLX5_SET(arm_xrc_srq_in, xrcsrq_in, opcode, MLX5_CMD_OP_ARM_XRC_SRQ);
|
||||
MLX5_SET(arm_xrc_srq_in, xrcsrq_in, op_mod, MLX5_ARM_XRC_SRQ_IN_OP_MOD_XRC_SRQ);
|
||||
MLX5_SET(arm_xrc_srq_in, xrcsrq_in, xrc_srqn, srq->srqn);
|
||||
MLX5_SET(arm_xrc_srq_in, xrcsrq_in, lwm, lwm);
|
||||
MLX5_SET(arm_xrc_srq_in, xrcsrq_in, uid, srq->uid);
|
||||
|
||||
return mlx5_cmd_exec(dev->mdev, xrcsrq_in, sizeof(xrcsrq_in),
|
||||
xrcsrq_out, sizeof(xrcsrq_out));
|
||||
}
|
||||
|
||||
static int query_xrc_srq_cmd(struct mlx5_ib_dev *dev,
|
||||
struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *out)
|
||||
{
|
||||
u32 xrcsrq_in[MLX5_ST_SZ_DW(query_xrc_srq_in)];
|
||||
u32 *xrcsrq_out;
|
||||
void *xrc_srqc;
|
||||
int err;
|
||||
|
||||
xrcsrq_out = kvzalloc(MLX5_ST_SZ_BYTES(query_xrc_srq_out), GFP_KERNEL);
|
||||
if (!xrcsrq_out)
|
||||
return -ENOMEM;
|
||||
memset(xrcsrq_in, 0, sizeof(xrcsrq_in));
|
||||
|
||||
MLX5_SET(query_xrc_srq_in, xrcsrq_in, opcode,
|
||||
MLX5_CMD_OP_QUERY_XRC_SRQ);
|
||||
MLX5_SET(query_xrc_srq_in, xrcsrq_in, xrc_srqn, srq->srqn);
|
||||
|
||||
err = mlx5_cmd_exec(dev->mdev, xrcsrq_in, sizeof(xrcsrq_in),
|
||||
xrcsrq_out, MLX5_ST_SZ_BYTES(query_xrc_srq_out));
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
xrc_srqc = MLX5_ADDR_OF(query_xrc_srq_out, xrcsrq_out,
|
||||
xrc_srq_context_entry);
|
||||
get_srqc(xrc_srqc, out);
|
||||
if (MLX5_GET(xrc_srqc, xrc_srqc, state) != MLX5_XRC_SRQC_STATE_GOOD)
|
||||
out->flags |= MLX5_SRQ_FLAG_ERR;
|
||||
|
||||
out:
|
||||
kvfree(xrcsrq_out);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int create_rmp_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *in)
|
||||
{
|
||||
void *create_out = NULL;
|
||||
void *create_in = NULL;
|
||||
void *rmpc;
|
||||
void *wq;
|
||||
int pas_size;
|
||||
int outlen;
|
||||
int inlen;
|
||||
int err;
|
||||
|
||||
pas_size = get_pas_size(in);
|
||||
inlen = MLX5_ST_SZ_BYTES(create_rmp_in) + pas_size;
|
||||
outlen = MLX5_ST_SZ_BYTES(create_rmp_out);
|
||||
create_in = kvzalloc(inlen, GFP_KERNEL);
|
||||
create_out = kvzalloc(outlen, GFP_KERNEL);
|
||||
if (!create_in || !create_out) {
|
||||
err = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rmpc = MLX5_ADDR_OF(create_rmp_in, create_in, ctx);
|
||||
wq = MLX5_ADDR_OF(rmpc, rmpc, wq);
|
||||
|
||||
MLX5_SET(rmpc, rmpc, state, MLX5_RMPC_STATE_RDY);
|
||||
MLX5_SET(create_rmp_in, create_in, uid, in->uid);
|
||||
set_wq(wq, in);
|
||||
memcpy(MLX5_ADDR_OF(rmpc, rmpc, wq.pas), in->pas, pas_size);
|
||||
|
||||
MLX5_SET(create_rmp_in, create_in, opcode, MLX5_CMD_OP_CREATE_RMP);
|
||||
err = mlx5_cmd_exec(dev->mdev, create_in, inlen, create_out, outlen);
|
||||
if (!err) {
|
||||
srq->srqn = MLX5_GET(create_rmp_out, create_out, rmpn);
|
||||
srq->uid = in->uid;
|
||||
}
|
||||
|
||||
out:
|
||||
kvfree(create_in);
|
||||
kvfree(create_out);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int destroy_rmp_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq)
|
||||
{
|
||||
u32 in[MLX5_ST_SZ_DW(destroy_rmp_in)] = {};
|
||||
u32 out[MLX5_ST_SZ_DW(destroy_rmp_out)] = {};
|
||||
|
||||
MLX5_SET(destroy_rmp_in, in, opcode, MLX5_CMD_OP_DESTROY_RMP);
|
||||
MLX5_SET(destroy_rmp_in, in, rmpn, srq->srqn);
|
||||
MLX5_SET(destroy_rmp_in, in, uid, srq->uid);
|
||||
return mlx5_cmd_exec(dev->mdev, in, sizeof(in), out, sizeof(out));
|
||||
}
|
||||
|
||||
static int arm_rmp_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
u16 lwm)
|
||||
{
|
||||
void *out = NULL;
|
||||
void *in = NULL;
|
||||
void *rmpc;
|
||||
void *wq;
|
||||
void *bitmask;
|
||||
int outlen;
|
||||
int inlen;
|
||||
int err;
|
||||
|
||||
inlen = MLX5_ST_SZ_BYTES(modify_rmp_in);
|
||||
outlen = MLX5_ST_SZ_BYTES(modify_rmp_out);
|
||||
|
||||
in = kvzalloc(inlen, GFP_KERNEL);
|
||||
out = kvzalloc(outlen, GFP_KERNEL);
|
||||
if (!in || !out) {
|
||||
err = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rmpc = MLX5_ADDR_OF(modify_rmp_in, in, ctx);
|
||||
bitmask = MLX5_ADDR_OF(modify_rmp_in, in, bitmask);
|
||||
wq = MLX5_ADDR_OF(rmpc, rmpc, wq);
|
||||
|
||||
MLX5_SET(modify_rmp_in, in, rmp_state, MLX5_RMPC_STATE_RDY);
|
||||
MLX5_SET(modify_rmp_in, in, rmpn, srq->srqn);
|
||||
MLX5_SET(modify_rmp_in, in, uid, srq->uid);
|
||||
MLX5_SET(wq, wq, lwm, lwm);
|
||||
MLX5_SET(rmp_bitmask, bitmask, lwm, 1);
|
||||
MLX5_SET(rmpc, rmpc, state, MLX5_RMPC_STATE_RDY);
|
||||
MLX5_SET(modify_rmp_in, in, opcode, MLX5_CMD_OP_MODIFY_RMP);
|
||||
|
||||
err = mlx5_cmd_exec(dev->mdev, in, inlen, out, outlen);
|
||||
|
||||
out:
|
||||
kvfree(in);
|
||||
kvfree(out);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int query_rmp_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *out)
|
||||
{
|
||||
u32 *rmp_out = NULL;
|
||||
u32 *rmp_in = NULL;
|
||||
void *rmpc;
|
||||
int outlen;
|
||||
int inlen;
|
||||
int err;
|
||||
|
||||
outlen = MLX5_ST_SZ_BYTES(query_rmp_out);
|
||||
inlen = MLX5_ST_SZ_BYTES(query_rmp_in);
|
||||
|
||||
rmp_out = kvzalloc(outlen, GFP_KERNEL);
|
||||
rmp_in = kvzalloc(inlen, GFP_KERNEL);
|
||||
if (!rmp_out || !rmp_in) {
|
||||
err = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
|
||||
MLX5_SET(query_rmp_in, rmp_in, opcode, MLX5_CMD_OP_QUERY_RMP);
|
||||
MLX5_SET(query_rmp_in, rmp_in, rmpn, srq->srqn);
|
||||
err = mlx5_cmd_exec(dev->mdev, rmp_in, inlen, rmp_out, outlen);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
rmpc = MLX5_ADDR_OF(query_rmp_out, rmp_out, rmp_context);
|
||||
get_wq(MLX5_ADDR_OF(rmpc, rmpc, wq), out);
|
||||
if (MLX5_GET(rmpc, rmpc, state) != MLX5_RMPC_STATE_RDY)
|
||||
out->flags |= MLX5_SRQ_FLAG_ERR;
|
||||
|
||||
out:
|
||||
kvfree(rmp_out);
|
||||
kvfree(rmp_in);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int create_xrq_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *in)
|
||||
{
|
||||
u32 create_out[MLX5_ST_SZ_DW(create_xrq_out)] = {0};
|
||||
void *create_in;
|
||||
void *xrqc;
|
||||
void *wq;
|
||||
int pas_size;
|
||||
int inlen;
|
||||
int err;
|
||||
|
||||
pas_size = get_pas_size(in);
|
||||
inlen = MLX5_ST_SZ_BYTES(create_xrq_in) + pas_size;
|
||||
create_in = kvzalloc(inlen, GFP_KERNEL);
|
||||
if (!create_in)
|
||||
return -ENOMEM;
|
||||
|
||||
xrqc = MLX5_ADDR_OF(create_xrq_in, create_in, xrq_context);
|
||||
wq = MLX5_ADDR_OF(xrqc, xrqc, wq);
|
||||
|
||||
set_wq(wq, in);
|
||||
memcpy(MLX5_ADDR_OF(xrqc, xrqc, wq.pas), in->pas, pas_size);
|
||||
|
||||
if (in->type == IB_SRQT_TM) {
|
||||
MLX5_SET(xrqc, xrqc, topology, MLX5_XRQC_TOPOLOGY_TAG_MATCHING);
|
||||
if (in->flags & MLX5_SRQ_FLAG_RNDV)
|
||||
MLX5_SET(xrqc, xrqc, offload, MLX5_XRQC_OFFLOAD_RNDV);
|
||||
MLX5_SET(xrqc, xrqc,
|
||||
tag_matching_topology_context.log_matching_list_sz,
|
||||
in->tm_log_list_size);
|
||||
}
|
||||
MLX5_SET(xrqc, xrqc, user_index, in->user_index);
|
||||
MLX5_SET(xrqc, xrqc, cqn, in->cqn);
|
||||
MLX5_SET(create_xrq_in, create_in, opcode, MLX5_CMD_OP_CREATE_XRQ);
|
||||
MLX5_SET(create_xrq_in, create_in, uid, in->uid);
|
||||
err = mlx5_cmd_exec(dev->mdev, create_in, inlen, create_out,
|
||||
sizeof(create_out));
|
||||
kvfree(create_in);
|
||||
if (!err) {
|
||||
srq->srqn = MLX5_GET(create_xrq_out, create_out, xrqn);
|
||||
srq->uid = in->uid;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int destroy_xrq_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq)
|
||||
{
|
||||
u32 in[MLX5_ST_SZ_DW(destroy_xrq_in)] = {0};
|
||||
u32 out[MLX5_ST_SZ_DW(destroy_xrq_out)] = {0};
|
||||
|
||||
MLX5_SET(destroy_xrq_in, in, opcode, MLX5_CMD_OP_DESTROY_XRQ);
|
||||
MLX5_SET(destroy_xrq_in, in, xrqn, srq->srqn);
|
||||
MLX5_SET(destroy_xrq_in, in, uid, srq->uid);
|
||||
|
||||
return mlx5_cmd_exec(dev->mdev, in, sizeof(in), out, sizeof(out));
|
||||
}
|
||||
|
||||
static int arm_xrq_cmd(struct mlx5_ib_dev *dev,
|
||||
struct mlx5_core_srq *srq,
|
||||
u16 lwm)
|
||||
{
|
||||
u32 out[MLX5_ST_SZ_DW(arm_rq_out)] = {0};
|
||||
u32 in[MLX5_ST_SZ_DW(arm_rq_in)] = {0};
|
||||
|
||||
MLX5_SET(arm_rq_in, in, opcode, MLX5_CMD_OP_ARM_RQ);
|
||||
MLX5_SET(arm_rq_in, in, op_mod, MLX5_ARM_RQ_IN_OP_MOD_XRQ);
|
||||
MLX5_SET(arm_rq_in, in, srq_number, srq->srqn);
|
||||
MLX5_SET(arm_rq_in, in, lwm, lwm);
|
||||
MLX5_SET(arm_rq_in, in, uid, srq->uid);
|
||||
|
||||
return mlx5_cmd_exec(dev->mdev, in, sizeof(in), out, sizeof(out));
|
||||
}
|
||||
|
||||
static int query_xrq_cmd(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *out)
|
||||
{
|
||||
u32 in[MLX5_ST_SZ_DW(query_xrq_in)] = {0};
|
||||
u32 *xrq_out;
|
||||
int outlen = MLX5_ST_SZ_BYTES(query_xrq_out);
|
||||
void *xrqc;
|
||||
int err;
|
||||
|
||||
xrq_out = kvzalloc(outlen, GFP_KERNEL);
|
||||
if (!xrq_out)
|
||||
return -ENOMEM;
|
||||
|
||||
MLX5_SET(query_xrq_in, in, opcode, MLX5_CMD_OP_QUERY_XRQ);
|
||||
MLX5_SET(query_xrq_in, in, xrqn, srq->srqn);
|
||||
|
||||
err = mlx5_cmd_exec(dev->mdev, in, sizeof(in), xrq_out, outlen);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
xrqc = MLX5_ADDR_OF(query_xrq_out, xrq_out, xrq_context);
|
||||
get_wq(MLX5_ADDR_OF(xrqc, xrqc, wq), out);
|
||||
if (MLX5_GET(xrqc, xrqc, state) != MLX5_XRQC_STATE_GOOD)
|
||||
out->flags |= MLX5_SRQ_FLAG_ERR;
|
||||
out->tm_next_tag =
|
||||
MLX5_GET(xrqc, xrqc,
|
||||
tag_matching_topology_context.append_next_index);
|
||||
out->tm_hw_phase_cnt =
|
||||
MLX5_GET(xrqc, xrqc,
|
||||
tag_matching_topology_context.hw_phase_cnt);
|
||||
out->tm_sw_phase_cnt =
|
||||
MLX5_GET(xrqc, xrqc,
|
||||
tag_matching_topology_context.sw_phase_cnt);
|
||||
|
||||
out:
|
||||
kvfree(xrq_out);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int create_srq_split(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *in)
|
||||
{
|
||||
if (!dev->mdev->issi)
|
||||
return create_srq_cmd(dev, srq, in);
|
||||
switch (srq->common.res) {
|
||||
case MLX5_RES_XSRQ:
|
||||
return create_xrc_srq_cmd(dev, srq, in);
|
||||
case MLX5_RES_XRQ:
|
||||
return create_xrq_cmd(dev, srq, in);
|
||||
default:
|
||||
return create_rmp_cmd(dev, srq, in);
|
||||
}
|
||||
}
|
||||
|
||||
static int destroy_srq_split(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq)
|
||||
{
|
||||
if (!dev->mdev->issi)
|
||||
return destroy_srq_cmd(dev, srq);
|
||||
switch (srq->common.res) {
|
||||
case MLX5_RES_XSRQ:
|
||||
return destroy_xrc_srq_cmd(dev, srq);
|
||||
case MLX5_RES_XRQ:
|
||||
return destroy_xrq_cmd(dev, srq);
|
||||
default:
|
||||
return destroy_rmp_cmd(dev, srq);
|
||||
}
|
||||
}
|
||||
|
||||
int mlx5_cmd_create_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *in)
|
||||
{
|
||||
struct mlx5_srq_table *table = &dev->srq_table;
|
||||
int err;
|
||||
|
||||
switch (in->type) {
|
||||
case IB_SRQT_XRC:
|
||||
srq->common.res = MLX5_RES_XSRQ;
|
||||
break;
|
||||
case IB_SRQT_TM:
|
||||
srq->common.res = MLX5_RES_XRQ;
|
||||
break;
|
||||
default:
|
||||
srq->common.res = MLX5_RES_SRQ;
|
||||
}
|
||||
|
||||
err = create_srq_split(dev, srq, in);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
atomic_set(&srq->refcount, 1);
|
||||
init_completion(&srq->free);
|
||||
|
||||
spin_lock_irq(&table->lock);
|
||||
err = radix_tree_insert(&table->tree, srq->srqn, srq);
|
||||
spin_unlock_irq(&table->lock);
|
||||
if (err)
|
||||
goto err_destroy_srq_split;
|
||||
|
||||
return 0;
|
||||
|
||||
err_destroy_srq_split:
|
||||
destroy_srq_split(dev, srq);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mlx5_cmd_destroy_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq)
|
||||
{
|
||||
struct mlx5_srq_table *table = &dev->srq_table;
|
||||
struct mlx5_core_srq *tmp;
|
||||
int err;
|
||||
|
||||
spin_lock_irq(&table->lock);
|
||||
tmp = radix_tree_delete(&table->tree, srq->srqn);
|
||||
spin_unlock_irq(&table->lock);
|
||||
if (!tmp || tmp != srq)
|
||||
return -EINVAL;
|
||||
|
||||
err = destroy_srq_split(dev, srq);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (atomic_dec_and_test(&srq->refcount))
|
||||
complete(&srq->free);
|
||||
wait_for_completion(&srq->free);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx5_cmd_query_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
struct mlx5_srq_attr *out)
|
||||
{
|
||||
if (!dev->mdev->issi)
|
||||
return query_srq_cmd(dev, srq, out);
|
||||
switch (srq->common.res) {
|
||||
case MLX5_RES_XSRQ:
|
||||
return query_xrc_srq_cmd(dev, srq, out);
|
||||
case MLX5_RES_XRQ:
|
||||
return query_xrq_cmd(dev, srq, out);
|
||||
default:
|
||||
return query_rmp_cmd(dev, srq, out);
|
||||
}
|
||||
}
|
||||
|
||||
int mlx5_cmd_arm_srq(struct mlx5_ib_dev *dev, struct mlx5_core_srq *srq,
|
||||
u16 lwm, int is_srq)
|
||||
{
|
||||
if (!dev->mdev->issi)
|
||||
return arm_srq_cmd(dev, srq, lwm, is_srq);
|
||||
switch (srq->common.res) {
|
||||
case MLX5_RES_XSRQ:
|
||||
return arm_xrc_srq_cmd(dev, srq, lwm);
|
||||
case MLX5_RES_XRQ:
|
||||
return arm_xrq_cmd(dev, srq, lwm);
|
||||
default:
|
||||
return arm_rmp_cmd(dev, srq, lwm);
|
||||
}
|
||||
}
|
||||
|
||||
static int srq_event_notifier(struct notifier_block *nb,
|
||||
unsigned long type, void *data)
|
||||
{
|
||||
struct mlx5_srq_table *table;
|
||||
struct mlx5_core_srq *srq;
|
||||
struct mlx5_eqe *eqe;
|
||||
u32 srqn;
|
||||
|
||||
if (type != MLX5_EVENT_TYPE_SRQ_CATAS_ERROR &&
|
||||
type != MLX5_EVENT_TYPE_SRQ_RQ_LIMIT)
|
||||
return NOTIFY_DONE;
|
||||
|
||||
table = container_of(nb, struct mlx5_srq_table, nb);
|
||||
|
||||
eqe = data;
|
||||
srqn = be32_to_cpu(eqe->data.qp_srq.qp_srq_n) & 0xffffff;
|
||||
|
||||
spin_lock(&table->lock);
|
||||
|
||||
srq = radix_tree_lookup(&table->tree, srqn);
|
||||
if (srq)
|
||||
atomic_inc(&srq->refcount);
|
||||
|
||||
spin_unlock(&table->lock);
|
||||
|
||||
if (!srq)
|
||||
return NOTIFY_OK;
|
||||
|
||||
srq->event(srq, eqe->type);
|
||||
|
||||
if (atomic_dec_and_test(&srq->refcount))
|
||||
complete(&srq->free);
|
||||
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
int mlx5_init_srq_table(struct mlx5_ib_dev *dev)
|
||||
{
|
||||
struct mlx5_srq_table *table = &dev->srq_table;
|
||||
|
||||
memset(table, 0, sizeof(*table));
|
||||
spin_lock_init(&table->lock);
|
||||
INIT_RADIX_TREE(&table->tree, GFP_ATOMIC);
|
||||
|
||||
table->nb.notifier_call = srq_event_notifier;
|
||||
mlx5_notifier_register(dev->mdev, &table->nb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mlx5_cleanup_srq_table(struct mlx5_ib_dev *dev)
|
||||
{
|
||||
struct mlx5_srq_table *table = &dev->srq_table;
|
||||
|
||||
mlx5_notifier_unregister(dev->mdev, &table->nb);
|
||||
}
|
Atsaukties uz šo jaunā problēmā
Block a user