Skip to content

Commit a4ae2bc

Browse files
Yufeng Modavem330
authored andcommitted
net: hns3: split function hns3_get_tx_timeo_queue_info()
Function hns3_get_tx_timeo_queue_info() is a bit too long. So add two new functions hns3_dump_queue_stats() and hns3_dump_queue_reg() to simplify code and improve code readability. Signed-off-by: Yufeng Mo <[email protected]> Signed-off-by: Guangbin Huang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e6fe5e1 commit a4ae2bc

File tree

2 files changed

+57
-48
lines changed

2 files changed

+57
-48
lines changed

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

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,18 +2659,8 @@ static int hns3_nic_change_mtu(struct net_device *netdev, int new_mtu)
26592659
return ret;
26602660
}
26612661

2662-
static bool hns3_get_tx_timeo_queue_info(struct net_device *ndev)
2662+
static int hns3_get_timeout_queue(struct net_device *ndev)
26632663
{
2664-
struct hns3_nic_priv *priv = netdev_priv(ndev);
2665-
struct hnae3_handle *h = hns3_get_handle(ndev);
2666-
struct hns3_enet_ring *tx_ring;
2667-
struct napi_struct *napi;
2668-
int timeout_queue = 0;
2669-
int hw_head, hw_tail;
2670-
int fbd_num, fbd_oft;
2671-
int ebd_num, ebd_oft;
2672-
int bd_num, bd_err;
2673-
int ring_en, tc;
26742664
int i;
26752665

26762666
/* Find the stopped queue the same way the stack does */
@@ -2690,25 +2680,22 @@ static bool hns3_get_tx_timeo_queue_info(struct net_device *ndev)
26902680
dql->last_obj_cnt, dql->num_queued,
26912681
dql->adj_limit, dql->num_completed);
26922682
#endif
2693-
timeout_queue = i;
26942683
netdev_info(ndev, "queue state: 0x%lx, delta msecs: %u\n",
26952684
q->state,
26962685
jiffies_to_msecs(jiffies - trans_start));
26972686
break;
26982687
}
26992688
}
27002689

2701-
if (i == ndev->num_tx_queues) {
2702-
netdev_info(ndev,
2703-
"no netdev TX timeout queue found, timeout count: %llu\n",
2704-
priv->tx_timeout_count);
2705-
return false;
2706-
}
2707-
2708-
priv->tx_timeout_count++;
2690+
return i;
2691+
}
27092692

2710-
tx_ring = &priv->ring[timeout_queue];
2711-
napi = &tx_ring->tqp_vector->napi;
2693+
static void hns3_dump_queue_stats(struct net_device *ndev,
2694+
struct hns3_enet_ring *tx_ring,
2695+
int timeout_queue)
2696+
{
2697+
struct napi_struct *napi = &tx_ring->tqp_vector->napi;
2698+
struct hns3_nic_priv *priv = netdev_priv(ndev);
27122699

27132700
netdev_info(ndev,
27142701
"tx_timeout count: %llu, queue id: %d, SW_NTU: 0x%x, SW_NTC: 0x%x, napi state: %lu\n",
@@ -2724,6 +2711,48 @@ static bool hns3_get_tx_timeo_queue_info(struct net_device *ndev)
27242711
"seg_pkt_cnt: %llu, tx_more: %llu, restart_queue: %llu, tx_busy: %llu\n",
27252712
tx_ring->stats.seg_pkt_cnt, tx_ring->stats.tx_more,
27262713
tx_ring->stats.restart_queue, tx_ring->stats.tx_busy);
2714+
}
2715+
2716+
static void hns3_dump_queue_reg(struct net_device *ndev,
2717+
struct hns3_enet_ring *tx_ring)
2718+
{
2719+
netdev_info(ndev,
2720+
"BD_NUM: 0x%x HW_HEAD: 0x%x, HW_TAIL: 0x%x, BD_ERR: 0x%x, INT: 0x%x\n",
2721+
hns3_tqp_read_reg(tx_ring, HNS3_RING_TX_RING_BD_NUM_REG),
2722+
hns3_tqp_read_reg(tx_ring, HNS3_RING_TX_RING_HEAD_REG),
2723+
hns3_tqp_read_reg(tx_ring, HNS3_RING_TX_RING_TAIL_REG),
2724+
hns3_tqp_read_reg(tx_ring, HNS3_RING_TX_RING_BD_ERR_REG),
2725+
readl(tx_ring->tqp_vector->mask_addr));
2726+
netdev_info(ndev,
2727+
"RING_EN: 0x%x, TC: 0x%x, FBD_NUM: 0x%x FBD_OFT: 0x%x, EBD_NUM: 0x%x, EBD_OFT: 0x%x\n",
2728+
hns3_tqp_read_reg(tx_ring, HNS3_RING_EN_REG),
2729+
hns3_tqp_read_reg(tx_ring, HNS3_RING_TX_RING_TC_REG),
2730+
hns3_tqp_read_reg(tx_ring, HNS3_RING_TX_RING_FBDNUM_REG),
2731+
hns3_tqp_read_reg(tx_ring, HNS3_RING_TX_RING_OFFSET_REG),
2732+
hns3_tqp_read_reg(tx_ring, HNS3_RING_TX_RING_EBDNUM_REG),
2733+
hns3_tqp_read_reg(tx_ring,
2734+
HNS3_RING_TX_RING_EBD_OFFSET_REG));
2735+
}
2736+
2737+
static bool hns3_get_tx_timeo_queue_info(struct net_device *ndev)
2738+
{
2739+
struct hns3_nic_priv *priv = netdev_priv(ndev);
2740+
struct hnae3_handle *h = hns3_get_handle(ndev);
2741+
struct hns3_enet_ring *tx_ring;
2742+
int timeout_queue;
2743+
2744+
timeout_queue = hns3_get_timeout_queue(ndev);
2745+
if (timeout_queue >= ndev->num_tx_queues) {
2746+
netdev_info(ndev,
2747+
"no netdev TX timeout queue found, timeout count: %llu\n",
2748+
priv->tx_timeout_count);
2749+
return false;
2750+
}
2751+
2752+
priv->tx_timeout_count++;
2753+
2754+
tx_ring = &priv->ring[timeout_queue];
2755+
hns3_dump_queue_stats(ndev, tx_ring, timeout_queue);
27272756

27282757
/* When mac received many pause frames continuous, it's unable to send
27292758
* packets, which may cause tx timeout
@@ -2736,32 +2765,7 @@ static bool hns3_get_tx_timeo_queue_info(struct net_device *ndev)
27362765
mac_stats.tx_pause_cnt, mac_stats.rx_pause_cnt);
27372766
}
27382767

2739-
hw_head = readl_relaxed(tx_ring->tqp->io_base +
2740-
HNS3_RING_TX_RING_HEAD_REG);
2741-
hw_tail = readl_relaxed(tx_ring->tqp->io_base +
2742-
HNS3_RING_TX_RING_TAIL_REG);
2743-
fbd_num = readl_relaxed(tx_ring->tqp->io_base +
2744-
HNS3_RING_TX_RING_FBDNUM_REG);
2745-
fbd_oft = readl_relaxed(tx_ring->tqp->io_base +
2746-
HNS3_RING_TX_RING_OFFSET_REG);
2747-
ebd_num = readl_relaxed(tx_ring->tqp->io_base +
2748-
HNS3_RING_TX_RING_EBDNUM_REG);
2749-
ebd_oft = readl_relaxed(tx_ring->tqp->io_base +
2750-
HNS3_RING_TX_RING_EBD_OFFSET_REG);
2751-
bd_num = readl_relaxed(tx_ring->tqp->io_base +
2752-
HNS3_RING_TX_RING_BD_NUM_REG);
2753-
bd_err = readl_relaxed(tx_ring->tqp->io_base +
2754-
HNS3_RING_TX_RING_BD_ERR_REG);
2755-
ring_en = readl_relaxed(tx_ring->tqp->io_base + HNS3_RING_EN_REG);
2756-
tc = readl_relaxed(tx_ring->tqp->io_base + HNS3_RING_TX_RING_TC_REG);
2757-
2758-
netdev_info(ndev,
2759-
"BD_NUM: 0x%x HW_HEAD: 0x%x, HW_TAIL: 0x%x, BD_ERR: 0x%x, INT: 0x%x\n",
2760-
bd_num, hw_head, hw_tail, bd_err,
2761-
readl(tx_ring->tqp_vector->mask_addr));
2762-
netdev_info(ndev,
2763-
"RING_EN: 0x%x, TC: 0x%x, FBD_NUM: 0x%x FBD_OFT: 0x%x, EBD_NUM: 0x%x, EBD_OFT: 0x%x\n",
2764-
ring_en, tc, fbd_num, fbd_oft, ebd_num, ebd_oft);
2768+
hns3_dump_queue_reg(ndev, tx_ring);
27652769

27662770
return true;
27672771
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ static inline int ring_space(struct hns3_enet_ring *ring)
621621
(begin - end)) - 1;
622622
}
623623

624+
static inline u32 hns3_tqp_read_reg(struct hns3_enet_ring *ring, u32 reg)
625+
{
626+
return readl_relaxed(ring->tqp->io_base + reg);
627+
}
628+
624629
static inline u32 hns3_read_reg(void __iomem *base, u32 reg)
625630
{
626631
return readl(base + reg);

0 commit comments

Comments
 (0)