cndm: Check for queue allocation failures in the driver

Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
Alex Forencich
2026-03-05 15:47:03 -08:00
parent f8764d581d
commit 39c9dce0fa
4 changed files with 40 additions and 2 deletions

View File

@@ -136,6 +136,9 @@ struct cndm_cq {
struct cndm_ring *src_ring; struct cndm_ring *src_ring;
void (*handler)(struct cndm_cq *cq); void (*handler)(struct cndm_cq *cq);
u32 db_offset;
u8 __iomem *db_addr;
}; };
struct cndm_priv { struct cndm_priv {

View File

@@ -27,6 +27,9 @@ struct cndm_cq *cndm_create_cq(struct cndm_priv *priv)
cq->cons_ptr = 0; cq->cons_ptr = 0;
cq->db_offset = 0;
cq->db_addr = NULL;
return cq; return cq;
} }
@@ -74,10 +77,20 @@ int cndm_open_cq(struct cndm_cq *cq, int irqn, int size)
cndm_exec_cmd(cq->cdev, &cmd, &rsp); cndm_exec_cmd(cq->cdev, &cmd, &rsp);
if (rsp.dboffs == 0) {
netdev_err(cq->priv->ndev, "Failed to allocate CQ");
ret = -1;
goto fail;
}
cq->cqn = rsp.qn; cq->cqn = rsp.qn;
cq->db_offset = rsp.dboffs;
cq->db_addr = cq->cdev->hw_addr + rsp.dboffs;
cq->enabled = 1; cq->enabled = 1;
netdev_dbg(cq->priv->ndev, "Opened CQ %d", cq->cqn);
return 0; return 0;
fail: fail:
@@ -102,6 +115,8 @@ void cndm_close_cq(struct cndm_cq *cq)
cndm_exec_cmd(cdev, &cmd, &rsp); cndm_exec_cmd(cdev, &cmd, &rsp);
cq->cqn = -1; cq->cqn = -1;
cq->db_offset = 0;
cq->db_addr = NULL;
} }
if (cq->buf) { if (cq->buf) {

View File

@@ -87,12 +87,20 @@ int cndm_open_rq(struct cndm_ring *rq, struct cndm_priv *priv, struct cndm_cq *c
cndm_exec_cmd(rq->cdev, &cmd, &rsp); cndm_exec_cmd(rq->cdev, &cmd, &rsp);
if (rsp.dboffs == 0) {
netdev_err(rq->priv->ndev, "Failed to allocate RQ");
ret = -1;
goto fail;
}
rq->index = rsp.qn; rq->index = rsp.qn;
rq->db_offset = rsp.dboffs; rq->db_offset = rsp.dboffs;
rq->db_addr = priv->cdev->hw_addr + rsp.dboffs; rq->db_addr = rq->cdev->hw_addr + rsp.dboffs;
rq->enabled = 1; rq->enabled = 1;
netdev_dbg(cq->priv->ndev, "Opened RQ %d (CQ %d)", rq->index, cq->cqn);
ret = cndm_refill_rx_buffers(rq); ret = cndm_refill_rx_buffers(rq);
if (ret) { if (ret) {
netdev_err(priv->ndev, "failed to allocate RX buffer for RX queue index %d (of %u total) entry index %u (of %u total)", netdev_err(priv->ndev, "failed to allocate RX buffer for RX queue index %d (of %u total) entry index %u (of %u total)",
@@ -135,6 +143,8 @@ void cndm_close_rq(struct cndm_ring *rq)
cndm_exec_cmd(cdev, &cmd, &rsp); cndm_exec_cmd(cdev, &cmd, &rsp);
rq->index = -1; rq->index = -1;
rq->db_offset = 0;
rq->db_addr = NULL;
} }
if (rq->buf) { if (rq->buf) {

View File

@@ -87,12 +87,20 @@ int cndm_open_sq(struct cndm_ring *sq, struct cndm_priv *priv, struct cndm_cq *c
cndm_exec_cmd(sq->cdev, &cmd, &rsp); cndm_exec_cmd(sq->cdev, &cmd, &rsp);
if (rsp.dboffs == 0) {
netdev_err(sq->priv->ndev, "Failed to allocate SQ");
ret = -1;
goto fail;
}
sq->index = rsp.qn; sq->index = rsp.qn;
sq->db_offset = rsp.dboffs; sq->db_offset = rsp.dboffs;
sq->db_addr = priv->cdev->hw_addr + rsp.dboffs; sq->db_addr = sq->cdev->hw_addr + rsp.dboffs;
sq->enabled = 1; sq->enabled = 1;
netdev_dbg(cq->priv->ndev, "Opened SQ %d (CQ %d)", sq->index, cq->cqn);
return 0; return 0;
fail: fail:
@@ -124,6 +132,8 @@ void cndm_close_sq(struct cndm_ring *sq)
cndm_exec_cmd(cdev, &cmd, &rsp); cndm_exec_cmd(cdev, &cmd, &rsp);
sq->index = -1; sq->index = -1;
sq->db_offset = 0;
sq->db_addr = NULL;
} }
if (sq->buf) { if (sq->buf) {