Skip to content

Commit 9f9f0f1

Browse files
Yunsheng Lindavem330
authored andcommitted
net: hns3: fix for miscalculation of rx unused desc
rx unused desc is the desc that need attatching new buffer before refilling to hw to receive new packet, the number of desc need attatching new buffer is calculated using next_to_use and next_to_clean. when next_to_use == next_to_clean, currently hns3 driver assumes that all the desc has the buffer attatched, but 'next_to_use == next_to_clean' also means all the desc need attatching new buffer if hw has comsumed all the desc and the driver has not attatched any buffer to the desc yet. This patch adds 'refill' in desc_cb to indicate whether a new buffer has been refilled to a desc. Fixes: 76ad4f0 ("net: hns3: Add support of HNS3 Ethernet Driver for hip08 SoC") Signed-off-by: Yunsheng Lin <[email protected]> Signed-off-by: Guangbin Huang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent adfb7b4 commit 9f9f0f1

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,7 @@ static void hns3_buffer_detach(struct hns3_enet_ring *ring, int i)
32553255
{
32563256
hns3_unmap_buffer(ring, &ring->desc_cb[i]);
32573257
ring->desc[i].addr = 0;
3258+
ring->desc_cb[i].refill = 0;
32583259
}
32593260

32603261
static void hns3_free_buffer_detach(struct hns3_enet_ring *ring, int i,
@@ -3333,6 +3334,7 @@ static int hns3_alloc_and_attach_buffer(struct hns3_enet_ring *ring, int i)
33333334

33343335
ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma +
33353336
ring->desc_cb[i].page_offset);
3337+
ring->desc_cb[i].refill = 1;
33363338

33373339
return 0;
33383340
}
@@ -3362,6 +3364,7 @@ static void hns3_replace_buffer(struct hns3_enet_ring *ring, int i,
33623364
{
33633365
hns3_unmap_buffer(ring, &ring->desc_cb[i]);
33643366
ring->desc_cb[i] = *res_cb;
3367+
ring->desc_cb[i].refill = 1;
33653368
ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma +
33663369
ring->desc_cb[i].page_offset);
33673370
ring->desc[i].rx.bd_base_info = 0;
@@ -3370,6 +3373,7 @@ static void hns3_replace_buffer(struct hns3_enet_ring *ring, int i,
33703373
static void hns3_reuse_buffer(struct hns3_enet_ring *ring, int i)
33713374
{
33723375
ring->desc_cb[i].reuse_flag = 0;
3376+
ring->desc_cb[i].refill = 1;
33733377
ring->desc[i].addr = cpu_to_le64(ring->desc_cb[i].dma +
33743378
ring->desc_cb[i].page_offset);
33753379
ring->desc[i].rx.bd_base_info = 0;
@@ -3476,6 +3480,9 @@ static int hns3_desc_unused(struct hns3_enet_ring *ring)
34763480
int ntc = ring->next_to_clean;
34773481
int ntu = ring->next_to_use;
34783482

3483+
if (unlikely(ntc == ntu && !ring->desc_cb[ntc].refill))
3484+
return ring->desc_num;
3485+
34793486
return ((ntc >= ntu) ? 0 : ring->desc_num) + ntc - ntu;
34803487
}
34813488

@@ -3821,6 +3828,7 @@ static void hns3_rx_ring_move_fw(struct hns3_enet_ring *ring)
38213828
{
38223829
ring->desc[ring->next_to_clean].rx.bd_base_info &=
38233830
cpu_to_le32(~BIT(HNS3_RXD_VLD_B));
3831+
ring->desc_cb[ring->next_to_clean].refill = 0;
38243832
ring->next_to_clean += 1;
38253833

38263834
if (unlikely(ring->next_to_clean == ring->desc_num))

drivers/net/ethernet/hisilicon/hns3/hns3_enet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ struct hns3_desc_cb {
330330
u32 length; /* length of the buffer */
331331

332332
u16 reuse_flag;
333+
u16 refill;
333334

334335
/* desc type, used by the ring user to mark the type of the priv data */
335336
u16 type;

0 commit comments

Comments
 (0)