Skip to content

Commit 8778372

Browse files
Hao Chendavem330
authored andcommitted
net: hns3: fix ethtool tx copybreak buf size indicating not aligned issue
When use ethtoool set tx copybreak buf size to a large value which causes order exceeding 10 or memory is not enough, it causes allocating tx copybreak buffer failed and print "the active tx spare buf is 0, not enabled tx spare buffer", however, use --get-tunable parameter query tx copybreak buf size and it indicates setting value not 0. So, it's necessary to change the print value from setting value to 0. Set kinfo.tx_spare_buf_size to 0 when set tx copybreak buf size failed. Fixes: e445f08 ("net: hns3: add support to set/get tx copybreak buf size via ethtool for hns3 driver") Signed-off-by: Hao Chen <chenhao288@hisilicon.com> Signed-off-by: Guangbin Huang <huangguangbin2@huawei.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent b50d3b4 commit 8778372

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,13 +1028,12 @@ static bool hns3_can_use_tx_sgl(struct hns3_enet_ring *ring,
10281028

10291029
static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)
10301030
{
1031+
u32 alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size;
10311032
struct hns3_tx_spare *tx_spare;
10321033
struct page *page;
1033-
u32 alloc_size;
10341034
dma_addr_t dma;
10351035
int order;
10361036

1037-
alloc_size = ring->tqp->handle->kinfo.tx_spare_buf_size;
10381037
if (!alloc_size)
10391038
return;
10401039

@@ -1044,30 +1043,35 @@ static void hns3_init_tx_spare_buffer(struct hns3_enet_ring *ring)
10441043
if (!tx_spare) {
10451044
/* The driver still work without the tx spare buffer */
10461045
dev_warn(ring_to_dev(ring), "failed to allocate hns3_tx_spare\n");
1047-
return;
1046+
goto devm_kzalloc_error;
10481047
}
10491048

10501049
page = alloc_pages_node(dev_to_node(ring_to_dev(ring)),
10511050
GFP_KERNEL, order);
10521051
if (!page) {
10531052
dev_warn(ring_to_dev(ring), "failed to allocate tx spare pages\n");
1054-
devm_kfree(ring_to_dev(ring), tx_spare);
1055-
return;
1053+
goto alloc_pages_error;
10561054
}
10571055

10581056
dma = dma_map_page(ring_to_dev(ring), page, 0,
10591057
PAGE_SIZE << order, DMA_TO_DEVICE);
10601058
if (dma_mapping_error(ring_to_dev(ring), dma)) {
10611059
dev_warn(ring_to_dev(ring), "failed to map pages for tx spare\n");
1062-
put_page(page);
1063-
devm_kfree(ring_to_dev(ring), tx_spare);
1064-
return;
1060+
goto dma_mapping_error;
10651061
}
10661062

10671063
tx_spare->dma = dma;
10681064
tx_spare->buf = page_address(page);
10691065
tx_spare->len = PAGE_SIZE << order;
10701066
ring->tx_spare = tx_spare;
1067+
return;
1068+
1069+
dma_mapping_error:
1070+
put_page(page);
1071+
alloc_pages_error:
1072+
devm_kfree(ring_to_dev(ring), tx_spare);
1073+
devm_kzalloc_error:
1074+
ring->tqp->handle->kinfo.tx_spare_buf_size = 0;
10711075
}
10721076

10731077
/* Use hns3_tx_spare_space() to make sure there is enough buffer

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,8 @@ static int hns3_set_tunable(struct net_device *netdev,
18181818
old_tx_spare_buf_size = h->kinfo.tx_spare_buf_size;
18191819
new_tx_spare_buf_size = *(u32 *)data;
18201820
ret = hns3_set_tx_spare_buf_size(netdev, new_tx_spare_buf_size);
1821-
if (ret) {
1821+
if (ret ||
1822+
(!priv->ring->tx_spare && new_tx_spare_buf_size != 0)) {
18221823
int ret1;
18231824

18241825
netdev_warn(netdev,

0 commit comments

Comments
 (0)