Commit 78034cbe authored by Liming Sun's avatar Liming Sun Committed by Hans de Goede

platform/mellanox: mlxbf-tmfifo: Drop the Rx packet if no more descriptors

This commit fixes tmfifo console stuck issue when the virtual
networking interface is in down state. In such case, the network
Rx descriptors runs out and causes the Rx network packet staying
in the head of the tmfifo thus blocking the console packets. The
fix is to drop the Rx network packet when no more Rx descriptors.
Function name mlxbf_tmfifo_release_pending_pkt() is also renamed
to mlxbf_tmfifo_release_pkt() to be more approperiate.

Fixes: 1357dfd7 ("platform/mellanox: Add TmFifo driver for Mellanox BlueField Soc")
Signed-off-by: default avatarLiming Sun <limings@nvidia.com>
Reviewed-by: default avatarVadim Pasternak <vadimp@nvidia.com>
Reviewed-by: default avatarDavid Thompson <davthompson@nvidia.com>
Link: https://lore.kernel.org/r/8c0177dc938ae03f52ff7e0b62dbeee74b7bec09.1693322547.git.limings@nvidia.comSigned-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 0bb80ecc
...@@ -59,6 +59,7 @@ struct mlxbf_tmfifo; ...@@ -59,6 +59,7 @@ struct mlxbf_tmfifo;
* @vq: pointer to the virtio virtqueue * @vq: pointer to the virtio virtqueue
* @desc: current descriptor of the pending packet * @desc: current descriptor of the pending packet
* @desc_head: head descriptor of the pending packet * @desc_head: head descriptor of the pending packet
* @drop_desc: dummy desc for packet dropping
* @cur_len: processed length of the current descriptor * @cur_len: processed length of the current descriptor
* @rem_len: remaining length of the pending packet * @rem_len: remaining length of the pending packet
* @pkt_len: total length of the pending packet * @pkt_len: total length of the pending packet
...@@ -75,6 +76,7 @@ struct mlxbf_tmfifo_vring { ...@@ -75,6 +76,7 @@ struct mlxbf_tmfifo_vring {
struct virtqueue *vq; struct virtqueue *vq;
struct vring_desc *desc; struct vring_desc *desc;
struct vring_desc *desc_head; struct vring_desc *desc_head;
struct vring_desc drop_desc;
int cur_len; int cur_len;
int rem_len; int rem_len;
u32 pkt_len; u32 pkt_len;
...@@ -86,6 +88,14 @@ struct mlxbf_tmfifo_vring { ...@@ -86,6 +88,14 @@ struct mlxbf_tmfifo_vring {
struct mlxbf_tmfifo *fifo; struct mlxbf_tmfifo *fifo;
}; };
/* Check whether vring is in drop mode. */
#define IS_VRING_DROP(_r) ({ \
typeof(_r) (r) = (_r); \
(r->desc_head == &r->drop_desc ? true : false); })
/* A stub length to drop maximum length packet. */
#define VRING_DROP_DESC_MAX_LEN GENMASK(15, 0)
/* Interrupt types. */ /* Interrupt types. */
enum { enum {
MLXBF_TM_RX_LWM_IRQ, MLXBF_TM_RX_LWM_IRQ,
...@@ -262,6 +272,7 @@ static int mlxbf_tmfifo_alloc_vrings(struct mlxbf_tmfifo *fifo, ...@@ -262,6 +272,7 @@ static int mlxbf_tmfifo_alloc_vrings(struct mlxbf_tmfifo *fifo,
vring->align = SMP_CACHE_BYTES; vring->align = SMP_CACHE_BYTES;
vring->index = i; vring->index = i;
vring->vdev_id = tm_vdev->vdev.id.device; vring->vdev_id = tm_vdev->vdev.id.device;
vring->drop_desc.len = VRING_DROP_DESC_MAX_LEN;
dev = &tm_vdev->vdev.dev; dev = &tm_vdev->vdev.dev;
size = vring_size(vring->num, vring->align); size = vring_size(vring->num, vring->align);
...@@ -367,7 +378,7 @@ static u32 mlxbf_tmfifo_get_pkt_len(struct mlxbf_tmfifo_vring *vring, ...@@ -367,7 +378,7 @@ static u32 mlxbf_tmfifo_get_pkt_len(struct mlxbf_tmfifo_vring *vring,
return len; return len;
} }
static void mlxbf_tmfifo_release_pending_pkt(struct mlxbf_tmfifo_vring *vring) static void mlxbf_tmfifo_release_pkt(struct mlxbf_tmfifo_vring *vring)
{ {
struct vring_desc *desc_head; struct vring_desc *desc_head;
u32 len = 0; u32 len = 0;
...@@ -596,19 +607,25 @@ static void mlxbf_tmfifo_rxtx_word(struct mlxbf_tmfifo_vring *vring, ...@@ -596,19 +607,25 @@ static void mlxbf_tmfifo_rxtx_word(struct mlxbf_tmfifo_vring *vring,
if (vring->cur_len + sizeof(u64) <= len) { if (vring->cur_len + sizeof(u64) <= len) {
/* The whole word. */ /* The whole word. */
if (is_rx) if (!IS_VRING_DROP(vring)) {
memcpy(addr + vring->cur_len, &data, sizeof(u64)); if (is_rx)
else memcpy(addr + vring->cur_len, &data,
memcpy(&data, addr + vring->cur_len, sizeof(u64)); sizeof(u64));
else
memcpy(&data, addr + vring->cur_len,
sizeof(u64));
}
vring->cur_len += sizeof(u64); vring->cur_len += sizeof(u64);
} else { } else {
/* Leftover bytes. */ /* Leftover bytes. */
if (is_rx) if (!IS_VRING_DROP(vring)) {
memcpy(addr + vring->cur_len, &data, if (is_rx)
len - vring->cur_len); memcpy(addr + vring->cur_len, &data,
else len - vring->cur_len);
memcpy(&data, addr + vring->cur_len, else
len - vring->cur_len); memcpy(&data, addr + vring->cur_len,
len - vring->cur_len);
}
vring->cur_len = len; vring->cur_len = len;
} }
...@@ -709,8 +726,16 @@ static bool mlxbf_tmfifo_rxtx_one_desc(struct mlxbf_tmfifo_vring *vring, ...@@ -709,8 +726,16 @@ static bool mlxbf_tmfifo_rxtx_one_desc(struct mlxbf_tmfifo_vring *vring,
/* Get the descriptor of the next packet. */ /* Get the descriptor of the next packet. */
if (!vring->desc) { if (!vring->desc) {
desc = mlxbf_tmfifo_get_next_pkt(vring, is_rx); desc = mlxbf_tmfifo_get_next_pkt(vring, is_rx);
if (!desc) if (!desc) {
return false; /* Drop next Rx packet to avoid stuck. */
if (is_rx) {
desc = &vring->drop_desc;
vring->desc_head = desc;
vring->desc = desc;
} else {
return false;
}
}
} else { } else {
desc = vring->desc; desc = vring->desc;
} }
...@@ -743,17 +768,24 @@ static bool mlxbf_tmfifo_rxtx_one_desc(struct mlxbf_tmfifo_vring *vring, ...@@ -743,17 +768,24 @@ static bool mlxbf_tmfifo_rxtx_one_desc(struct mlxbf_tmfifo_vring *vring,
vring->rem_len -= len; vring->rem_len -= len;
/* Get the next desc on the chain. */ /* Get the next desc on the chain. */
if (vring->rem_len > 0 && if (!IS_VRING_DROP(vring) && vring->rem_len > 0 &&
(virtio16_to_cpu(vdev, desc->flags) & VRING_DESC_F_NEXT)) { (virtio16_to_cpu(vdev, desc->flags) & VRING_DESC_F_NEXT)) {
idx = virtio16_to_cpu(vdev, desc->next); idx = virtio16_to_cpu(vdev, desc->next);
desc = &vr->desc[idx]; desc = &vr->desc[idx];
goto mlxbf_tmfifo_desc_done; goto mlxbf_tmfifo_desc_done;
} }
/* Done and release the pending packet. */ /* Done and release the packet. */
mlxbf_tmfifo_release_pending_pkt(vring);
desc = NULL; desc = NULL;
fifo->vring[is_rx] = NULL; fifo->vring[is_rx] = NULL;
if (!IS_VRING_DROP(vring)) {
mlxbf_tmfifo_release_pkt(vring);
} else {
vring->pkt_len = 0;
vring->desc_head = NULL;
vring->desc = NULL;
return false;
}
/* /*
* Make sure the load/store are in order before * Make sure the load/store are in order before
...@@ -933,7 +965,7 @@ static void mlxbf_tmfifo_virtio_del_vqs(struct virtio_device *vdev) ...@@ -933,7 +965,7 @@ static void mlxbf_tmfifo_virtio_del_vqs(struct virtio_device *vdev)
/* Release the pending packet. */ /* Release the pending packet. */
if (vring->desc) if (vring->desc)
mlxbf_tmfifo_release_pending_pkt(vring); mlxbf_tmfifo_release_pkt(vring);
vq = vring->vq; vq = vring->vq;
if (vq) { if (vq) {
vring->vq = NULL; vring->vq = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment