Skip to content

Commit

Permalink
anolis: RDMA/erdma: Update and bugfix
Browse files Browse the repository at this point in the history
ANBZ: torvalds#293

This patch includes the following updates:
1. Add atomic operations support.
2. More support for eadm tools.
3. Fix inline mtt count threshold.
4. Codestyle fixing.
5. Limit error print rate.
7. Flush support when modify qp to error.

Signed-off-by: Kai <KaiShen@linux.alibaba.com>
Reviewed-by: Cheng You <chengyou@linux.alibaba.com>
Link: https://gitee.com/anolis/cloud-kernel/pulls/900
  • Loading branch information
Kai authored and zychao66 committed Nov 25, 2022
1 parent 5dfcbf7 commit e205673
Show file tree
Hide file tree
Showing 16 changed files with 1,426 additions and 735 deletions.
20 changes: 14 additions & 6 deletions drivers/infiniband/hw/erdma/erdma.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */

/* Authors: Cheng Xu <chengyou@linux.alibaba.com> */
/* Kai Shen <kaishen@linux.alibaba.com> */
Expand All @@ -9,10 +9,13 @@

#include <linux/bitfield.h>
#include <linux/netdevice.h>
#include <linux/pci.h>
#include <linux/xarray.h>
#include <rdma/ib_verbs.h>

#include "erdma_debug.h"
#include "erdma_hw.h"
#include "erdma_ioctl.h"
#include "erdma_stats.h"

#ifndef RDMA_DRIVER_ERDMA
Expand All @@ -21,7 +24,7 @@

#define ERDMA_MAJOR_VER 0
#define ERDMA_MEDIUM_VER 2
#define ERDMA_MINOR_VER 14
#define ERDMA_MINOR_VER 35

#define DRV_MODULE_NAME "erdma"
#define ERDMA_NODE_DESC "Elastic RDMA(iWARP) stack"
Expand All @@ -46,7 +49,7 @@ struct erdma_eq {
atomic64_t event_num;
atomic64_t notify_num;

u64 __iomem *db_addr;
void __iomem *db;
u64 *db_record;
};

Expand Down Expand Up @@ -143,6 +146,7 @@ struct erdma_devattr {

int numa_node;
enum erdma_cc_alg cc;
u8 flags;
u32 grp_num;
int irq_num;

Expand Down Expand Up @@ -205,6 +209,7 @@ struct erdma_dev {
struct net_device *netdev;
struct pci_dev *pdev;
struct notifier_block netdev_nb;
struct workqueue_struct *reflush_wq;

resource_size_t func_bar_addr;
resource_size_t func_bar_len;
Expand All @@ -213,6 +218,7 @@ struct erdma_dev {
struct erdma_devattr attrs;
/* physical port state (only one port per device) */
enum ib_port_state state;
u32 mtu;

/* cmdq and aeq use the same msix vector */
struct erdma_irq comm_irq;
Expand All @@ -234,14 +240,16 @@ struct erdma_dev {
DECLARE_BITMAP(sdb_page, ERDMA_DWQE_TYPE0_CNT);
/*
* We provide max 496 uContexts that each has one SQ normal Db,
* and one directWQE db
* and one directWQE db.
*/
DECLARE_BITMAP(sdb_entry, ERDMA_DWQE_TYPE1_CNT);

atomic_t num_ctx;
atomic_t num_cep;
struct list_head cep_list;
bool is_registered;

struct dma_pool *db_pool;
struct dma_pool *resp_pool;
};

static inline void *get_queue_entry(void *qbuf, u32 idx, u32 depth, u32 shift)
Expand Down Expand Up @@ -289,7 +297,7 @@ void erdma_finish_cmdq_init(struct erdma_dev *dev);
void erdma_cmdq_destroy(struct erdma_dev *dev);

void erdma_cmdq_build_reqhdr(u64 *hdr, u32 mod, u32 op);
int erdma_post_cmd_wait(struct erdma_cmdq *cmdq, u64 *req, u32 req_size,
int erdma_post_cmd_wait(struct erdma_cmdq *cmdq, void *req, u32 req_size,
u64 *resp0, u64 *resp1);
void erdma_cmdq_completion_handler(struct erdma_cmdq *cmdq);

Expand Down
19 changes: 1 addition & 18 deletions drivers/infiniband/hw/erdma/erdma_cm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause

/* Authors: Cheng Xu <chengyou@linux.alibaba.com> */
/* Kai Shen <kaishen@linux.alibaba.com> */
Expand All @@ -10,23 +10,9 @@
/* Copyright (c) 2008-2019, IBM Corporation */
/* Copyright (c) 2017, Open Grid Computing, Inc. */

#include <linux/errno.h>
#include <linux/inetdevice.h>
#include <linux/net.h>
#include <linux/inetdevice.h>
#include <net/addrconf.h>
#include <linux/tcp.h>
#include <linux/types.h>
#include <linux/workqueue.h>
#include <net/sock.h>

#include <rdma/iw_cm.h>
#include <rdma/ib_smi.h>
#include <rdma/ib_user_verbs.h>
#include <rdma/ib_verbs.h>

#include "erdma.h"
#include "erdma_debug.h"
#include "erdma_cm.h"
#include "erdma_verbs.h"

Expand Down Expand Up @@ -320,11 +306,9 @@ void erdma_qp_cm_drop(struct erdma_qp *qp)
erdma_cm_upcall(cep, IW_CM_EVENT_CONNECT_REPLY,
-EINVAL);
break;

case ERDMA_EPSTATE_RDMA_MODE:
erdma_cm_upcall(cep, IW_CM_EVENT_CLOSE, 0);
break;

case ERDMA_EPSTATE_IDLE:
case ERDMA_EPSTATE_LISTENING:
case ERDMA_EPSTATE_CONNECTING:
Expand Down Expand Up @@ -360,7 +344,6 @@ void erdma_cep_put(struct erdma_cep *cep)
kref_read(&cep->ref) - 1);

WARN_ON(kref_read(&cep->ref) < 1);

kref_put(&cep->ref, __erdma_cep_dealloc);
}

Expand Down
5 changes: 2 additions & 3 deletions drivers/infiniband/hw/erdma/erdma_cm.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */

/* Authors: Cheng Xu <chengyou@linux.alibaba.com> */
/* Kai Shen <kaishen@linux.alibaba.com> */
Expand All @@ -12,9 +12,8 @@
#ifndef __ERDMA_CM_H__
#define __ERDMA_CM_H__

#include <net/sock.h>
#include <linux/tcp.h>

#include <net/sock.h>
#include <rdma/iw_cm.h>

/* iWarp MPA protocol defs */
Expand Down
101 changes: 41 additions & 60 deletions drivers/infiniband/hw/erdma/erdma_cmdq.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause

/* Authors: Cheng Xu <chengyou@linux.alibaba.com> */
/* Kai Shen <kaishen@linux.alibaba.com> */
/* Copyright (c) 2020-2022, Alibaba Group. */

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/pci.h>

#include "erdma.h"
#include "erdma_hw.h"
#include "erdma_verbs.h"

static void arm_cmdq_cq(struct erdma_cmdq *cmdq)
{
Expand Down Expand Up @@ -47,7 +41,7 @@ static struct erdma_comp_wait *get_comp_wait(struct erdma_cmdq *cmdq)
return ERR_PTR(-ENOMEM);
}

set_bit(comp_idx, cmdq->comp_wait_bitmap);
__set_bit(comp_idx, cmdq->comp_wait_bitmap);
spin_unlock(&cmdq->lock);

return &cmdq->wait_pool[comp_idx];
Expand All @@ -60,7 +54,7 @@ static void put_comp_wait(struct erdma_cmdq *cmdq,

cmdq->wait_pool[comp_wait->ctx_id].cmd_status = ERDMA_CMD_STATUS_INIT;
spin_lock(&cmdq->lock);
used = test_and_clear_bit(comp_wait->ctx_id, cmdq->comp_wait_bitmap);
used = __test_and_clear_bit(comp_wait->ctx_id, cmdq->comp_wait_bitmap);
spin_unlock(&cmdq->lock);

WARN_ON(!used);
Expand Down Expand Up @@ -127,6 +121,16 @@ static int erdma_cmdq_sq_init(struct erdma_dev *dev)
return 0;
}

static void erdma_cmdq_sq_destroy(struct erdma_dev *dev)
{
struct erdma_cmdq *cmdq = &dev->cmdq;

dma_free_coherent(&dev->pdev->dev,
(cmdq->sq.depth << SQEBB_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->sq.qbuf, cmdq->sq.qbuf_dma_addr);
}

static int erdma_cmdq_cq_init(struct erdma_dev *dev)
{
struct erdma_cmdq *cmdq = &dev->cmdq;
Expand Down Expand Up @@ -158,6 +162,16 @@ static int erdma_cmdq_cq_init(struct erdma_dev *dev)
return 0;
}

static void erdma_cmdq_cq_destroy(struct erdma_dev *dev)
{
struct erdma_cmdq *cmdq = &dev->cmdq;

dma_free_coherent(&dev->pdev->dev,
(cmdq->cq.depth << CQE_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->cq.qbuf, cmdq->cq.qbuf_dma_addr);
}

static int erdma_cmdq_eq_init(struct erdma_dev *dev)
{
struct erdma_cmdq *cmdq = &dev->cmdq;
Expand All @@ -176,8 +190,7 @@ static int erdma_cmdq_eq_init(struct erdma_dev *dev)
spin_lock_init(&eq->lock);
atomic64_set(&eq->event_num, 0);

eq->db_addr =
(u64 __iomem *)(dev->func_bar + ERDMA_REGS_CEQ_DB_BASE_REG);
eq->db = dev->func_bar + ERDMA_REGS_CEQ_DB_BASE_REG;
eq->db_record = (u64 *)(eq->qbuf + buf_size);

erdma_reg_write32(dev, ERDMA_REGS_CMDQ_EQ_ADDR_H_REG,
Expand All @@ -191,11 +204,20 @@ static int erdma_cmdq_eq_init(struct erdma_dev *dev)
return 0;
}

static void erdma_cmdq_eq_destroy(struct erdma_dev *dev)
{
struct erdma_cmdq *cmdq = &dev->cmdq;

dma_free_coherent(&dev->pdev->dev,
(cmdq->eq.depth << EQE_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->eq.qbuf, cmdq->eq.qbuf_dma_addr);
}

int erdma_cmdq_init(struct erdma_dev *dev)
{
int err, i;
struct erdma_cmdq *cmdq = &dev->cmdq;
u32 status, ctrl;
int err;

cmdq->max_outstandings = ERDMA_CMDQ_MAX_OUTSTANDING;
cmdq->use_event = false;
Expand All @@ -218,46 +240,14 @@ int erdma_cmdq_init(struct erdma_dev *dev)
if (err)
goto err_destroy_cq;

ctrl = FIELD_PREP(ERDMA_REG_DEV_CTRL_INIT_MASK, 1);
erdma_reg_write32(dev, ERDMA_REGS_DEV_CTRL_REG, ctrl);

for (i = 0; i < ERDMA_WAIT_DEV_DONE_CNT; i++) {
status =
erdma_reg_read32_filed(dev, ERDMA_REGS_DEV_ST_REG,
ERDMA_REG_DEV_ST_INIT_DONE_MASK);
if (status)
break;

msleep(ERDMA_REG_ACCESS_WAIT_MS);
}

if (i == ERDMA_WAIT_DEV_DONE_CNT) {
dev_err(&dev->pdev->dev, "wait init done failed.\n");
err = -ETIMEDOUT;
goto err_destroy_eq;
}

set_bit(ERDMA_CMDQ_STATE_OK_BIT, &cmdq->state);

return 0;

err_destroy_eq:
dma_free_coherent(&dev->pdev->dev,
(cmdq->eq.depth << EQE_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->eq.qbuf, cmdq->eq.qbuf_dma_addr);

err_destroy_cq:
dma_free_coherent(&dev->pdev->dev,
(cmdq->cq.depth << CQE_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->cq.qbuf, cmdq->cq.qbuf_dma_addr);

erdma_cmdq_cq_destroy(dev);
err_destroy_sq:
dma_free_coherent(&dev->pdev->dev,
(cmdq->sq.depth << SQEBB_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->sq.qbuf, cmdq->sq.qbuf_dma_addr);
erdma_cmdq_sq_destroy(dev);

return err;
}
Expand All @@ -275,18 +265,9 @@ void erdma_cmdq_destroy(struct erdma_dev *dev)

clear_bit(ERDMA_CMDQ_STATE_OK_BIT, &cmdq->state);

dma_free_coherent(&dev->pdev->dev,
(cmdq->eq.depth << EQE_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->eq.qbuf, cmdq->eq.qbuf_dma_addr);
dma_free_coherent(&dev->pdev->dev,
(cmdq->sq.depth << SQEBB_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->sq.qbuf, cmdq->sq.qbuf_dma_addr);
dma_free_coherent(&dev->pdev->dev,
(cmdq->cq.depth << CQE_SHIFT) +
ERDMA_EXTRA_BUFFER_SIZE,
cmdq->cq.qbuf, cmdq->cq.qbuf_dma_addr);
erdma_cmdq_eq_destroy(dev);
erdma_cmdq_cq_destroy(dev);
erdma_cmdq_sq_destroy(dev);
}

static void *get_next_valid_cmdq_cqe(struct erdma_cmdq *cmdq)
Expand Down Expand Up @@ -449,7 +430,7 @@ void erdma_cmdq_build_reqhdr(u64 *hdr, u32 mod, u32 op)
FIELD_PREP(ERDMA_CMD_HDR_OPCODE_MASK, op);
}

int erdma_post_cmd_wait(struct erdma_cmdq *cmdq, u64 *req, u32 req_size,
int erdma_post_cmd_wait(struct erdma_cmdq *cmdq, void *req, u32 req_size,
u64 *resp0, u64 *resp1)
{
struct erdma_comp_wait *comp_wait;
Expand Down
Loading

0 comments on commit e205673

Please sign in to comment.