Commit e54fbbdf authored by Xue Chaojing's avatar Xue Chaojing Committed by David S. Miller

hinic: implement the statistical interface of ethtool

This patch implement the statistical interface of ethtool, user can use
ethtool -S to show hinic statistics.
Signed-off-by: default avatarXue Chaojing <xuechaojing@huawei.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7d30a7f6
...@@ -45,6 +45,14 @@ enum hinic_port_cmd { ...@@ -45,6 +45,14 @@ enum hinic_port_cmd {
HINIC_PORT_CMD_SET_RX_CSUM = 26, HINIC_PORT_CMD_SET_RX_CSUM = 26,
HINIC_PORT_CMD_GET_PORT_STATISTICS = 28,
HINIC_PORT_CMD_CLEAR_PORT_STATISTICS = 29,
HINIC_PORT_CMD_GET_VPORT_STAT = 30,
HINIC_PORT_CMD_CLEAN_VPORT_STAT = 31,
HINIC_PORT_CMD_GET_RSS_TEMPLATE_INDIR_TBL = 37, HINIC_PORT_CMD_GET_RSS_TEMPLATE_INDIR_TBL = 37,
HINIC_PORT_CMD_SET_PORT_STATE = 41, HINIC_PORT_CMD_SET_PORT_STATE = 41,
......
...@@ -83,6 +83,9 @@ static void update_rx_stats(struct hinic_dev *nic_dev, struct hinic_rxq *rxq) ...@@ -83,6 +83,9 @@ static void update_rx_stats(struct hinic_dev *nic_dev, struct hinic_rxq *rxq)
u64_stats_update_begin(&nic_rx_stats->syncp); u64_stats_update_begin(&nic_rx_stats->syncp);
nic_rx_stats->bytes += rx_stats.bytes; nic_rx_stats->bytes += rx_stats.bytes;
nic_rx_stats->pkts += rx_stats.pkts; nic_rx_stats->pkts += rx_stats.pkts;
nic_rx_stats->errors += rx_stats.errors;
nic_rx_stats->csum_errors += rx_stats.csum_errors;
nic_rx_stats->other_errors += rx_stats.other_errors;
u64_stats_update_end(&nic_rx_stats->syncp); u64_stats_update_end(&nic_rx_stats->syncp);
hinic_rxq_clean_stats(rxq); hinic_rxq_clean_stats(rxq);
...@@ -103,6 +106,7 @@ static void update_tx_stats(struct hinic_dev *nic_dev, struct hinic_txq *txq) ...@@ -103,6 +106,7 @@ static void update_tx_stats(struct hinic_dev *nic_dev, struct hinic_txq *txq)
nic_tx_stats->tx_busy += tx_stats.tx_busy; nic_tx_stats->tx_busy += tx_stats.tx_busy;
nic_tx_stats->tx_wake += tx_stats.tx_wake; nic_tx_stats->tx_wake += tx_stats.tx_wake;
nic_tx_stats->tx_dropped += tx_stats.tx_dropped; nic_tx_stats->tx_dropped += tx_stats.tx_dropped;
nic_tx_stats->big_frags_pkts += tx_stats.big_frags_pkts;
u64_stats_update_end(&nic_tx_stats->syncp); u64_stats_update_end(&nic_tx_stats->syncp);
hinic_txq_clean_stats(txq); hinic_txq_clean_stats(txq);
...@@ -782,6 +786,7 @@ static void hinic_get_stats64(struct net_device *netdev, ...@@ -782,6 +786,7 @@ static void hinic_get_stats64(struct net_device *netdev,
stats->rx_bytes = nic_rx_stats->bytes; stats->rx_bytes = nic_rx_stats->bytes;
stats->rx_packets = nic_rx_stats->pkts; stats->rx_packets = nic_rx_stats->pkts;
stats->rx_errors = nic_rx_stats->errors;
stats->tx_bytes = nic_tx_stats->bytes; stats->tx_bytes = nic_tx_stats->bytes;
stats->tx_packets = nic_tx_stats->pkts; stats->tx_packets = nic_tx_stats->pkts;
......
...@@ -942,3 +942,69 @@ int hinic_rss_template_free(struct hinic_dev *nic_dev, u8 tmpl_idx) ...@@ -942,3 +942,69 @@ int hinic_rss_template_free(struct hinic_dev *nic_dev, u8 tmpl_idx)
return 0; return 0;
} }
int hinic_get_vport_stats(struct hinic_dev *nic_dev,
struct hinic_vport_stats *stats)
{
struct hinic_cmd_vport_stats vport_stats = { 0 };
struct hinic_port_stats_info stats_info = { 0 };
struct hinic_hwdev *hwdev = nic_dev->hwdev;
struct hinic_hwif *hwif = hwdev->hwif;
u16 out_size = sizeof(vport_stats);
struct pci_dev *pdev = hwif->pdev;
int err;
stats_info.stats_version = HINIC_PORT_STATS_VERSION;
stats_info.func_id = HINIC_HWIF_FUNC_IDX(hwif);
stats_info.stats_size = sizeof(vport_stats);
err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_GET_VPORT_STAT,
&stats_info, sizeof(stats_info),
&vport_stats, &out_size);
if (err || !out_size || vport_stats.status) {
dev_err(&pdev->dev,
"Failed to get function statistics, err: %d, status: 0x%x, out size: 0x%x\n",
err, vport_stats.status, out_size);
return -EFAULT;
}
memcpy(stats, &vport_stats.stats, sizeof(*stats));
return 0;
}
int hinic_get_phy_port_stats(struct hinic_dev *nic_dev,
struct hinic_phy_port_stats *stats)
{
struct hinic_port_stats_info stats_info = { 0 };
struct hinic_hwdev *hwdev = nic_dev->hwdev;
struct hinic_hwif *hwif = hwdev->hwif;
struct hinic_port_stats *port_stats;
u16 out_size = sizeof(*port_stats);
struct pci_dev *pdev = hwif->pdev;
int err;
port_stats = kzalloc(sizeof(*port_stats), GFP_KERNEL);
if (!port_stats)
return -ENOMEM;
stats_info.stats_version = HINIC_PORT_STATS_VERSION;
stats_info.stats_size = sizeof(*port_stats);
err = hinic_port_msg_cmd(hwdev, HINIC_PORT_CMD_GET_PORT_STATISTICS,
&stats_info, sizeof(stats_info),
port_stats, &out_size);
if (err || !out_size || port_stats->status) {
dev_err(&pdev->dev,
"Failed to get port statistics, err: %d, status: 0x%x, out size: 0x%x\n",
err, port_stats->status, out_size);
err = -EINVAL;
goto out;
}
memcpy(stats, &port_stats->stats, sizeof(*stats));
out:
kfree(port_stats);
return err;
}
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define HINIC_RSS_KEY_SIZE 40 #define HINIC_RSS_KEY_SIZE 40
#define HINIC_RSS_INDIR_SIZE 256 #define HINIC_RSS_INDIR_SIZE 256
#define HINIC_PORT_STATS_VERSION 0
enum hinic_rx_mode { enum hinic_rx_mode {
HINIC_RX_MODE_UC = BIT(0), HINIC_RX_MODE_UC = BIT(0),
...@@ -316,6 +317,173 @@ struct hinic_rss_config { ...@@ -316,6 +317,173 @@ struct hinic_rss_config {
u8 rsvd1[11]; u8 rsvd1[11];
}; };
struct hinic_stats {
char name[ETH_GSTRING_LEN];
u32 size;
int offset;
};
struct hinic_vport_stats {
u64 tx_unicast_pkts_vport;
u64 tx_unicast_bytes_vport;
u64 tx_multicast_pkts_vport;
u64 tx_multicast_bytes_vport;
u64 tx_broadcast_pkts_vport;
u64 tx_broadcast_bytes_vport;
u64 rx_unicast_pkts_vport;
u64 rx_unicast_bytes_vport;
u64 rx_multicast_pkts_vport;
u64 rx_multicast_bytes_vport;
u64 rx_broadcast_pkts_vport;
u64 rx_broadcast_bytes_vport;
u64 tx_discard_vport;
u64 rx_discard_vport;
u64 tx_err_vport;
u64 rx_err_vport;
};
struct hinic_phy_port_stats {
u64 mac_rx_total_pkt_num;
u64 mac_rx_total_oct_num;
u64 mac_rx_bad_pkt_num;
u64 mac_rx_bad_oct_num;
u64 mac_rx_good_pkt_num;
u64 mac_rx_good_oct_num;
u64 mac_rx_uni_pkt_num;
u64 mac_rx_multi_pkt_num;
u64 mac_rx_broad_pkt_num;
u64 mac_tx_total_pkt_num;
u64 mac_tx_total_oct_num;
u64 mac_tx_bad_pkt_num;
u64 mac_tx_bad_oct_num;
u64 mac_tx_good_pkt_num;
u64 mac_tx_good_oct_num;
u64 mac_tx_uni_pkt_num;
u64 mac_tx_multi_pkt_num;
u64 mac_tx_broad_pkt_num;
u64 mac_rx_fragment_pkt_num;
u64 mac_rx_undersize_pkt_num;
u64 mac_rx_undermin_pkt_num;
u64 mac_rx_64_oct_pkt_num;
u64 mac_rx_65_127_oct_pkt_num;
u64 mac_rx_128_255_oct_pkt_num;
u64 mac_rx_256_511_oct_pkt_num;
u64 mac_rx_512_1023_oct_pkt_num;
u64 mac_rx_1024_1518_oct_pkt_num;
u64 mac_rx_1519_2047_oct_pkt_num;
u64 mac_rx_2048_4095_oct_pkt_num;
u64 mac_rx_4096_8191_oct_pkt_num;
u64 mac_rx_8192_9216_oct_pkt_num;
u64 mac_rx_9217_12287_oct_pkt_num;
u64 mac_rx_12288_16383_oct_pkt_num;
u64 mac_rx_1519_max_bad_pkt_num;
u64 mac_rx_1519_max_good_pkt_num;
u64 mac_rx_oversize_pkt_num;
u64 mac_rx_jabber_pkt_num;
u64 mac_rx_pause_num;
u64 mac_rx_pfc_pkt_num;
u64 mac_rx_pfc_pri0_pkt_num;
u64 mac_rx_pfc_pri1_pkt_num;
u64 mac_rx_pfc_pri2_pkt_num;
u64 mac_rx_pfc_pri3_pkt_num;
u64 mac_rx_pfc_pri4_pkt_num;
u64 mac_rx_pfc_pri5_pkt_num;
u64 mac_rx_pfc_pri6_pkt_num;
u64 mac_rx_pfc_pri7_pkt_num;
u64 mac_rx_control_pkt_num;
u64 mac_rx_y1731_pkt_num;
u64 mac_rx_sym_err_pkt_num;
u64 mac_rx_fcs_err_pkt_num;
u64 mac_rx_send_app_good_pkt_num;
u64 mac_rx_send_app_bad_pkt_num;
u64 mac_tx_fragment_pkt_num;
u64 mac_tx_undersize_pkt_num;
u64 mac_tx_undermin_pkt_num;
u64 mac_tx_64_oct_pkt_num;
u64 mac_tx_65_127_oct_pkt_num;
u64 mac_tx_128_255_oct_pkt_num;
u64 mac_tx_256_511_oct_pkt_num;
u64 mac_tx_512_1023_oct_pkt_num;
u64 mac_tx_1024_1518_oct_pkt_num;
u64 mac_tx_1519_2047_oct_pkt_num;
u64 mac_tx_2048_4095_oct_pkt_num;
u64 mac_tx_4096_8191_oct_pkt_num;
u64 mac_tx_8192_9216_oct_pkt_num;
u64 mac_tx_9217_12287_oct_pkt_num;
u64 mac_tx_12288_16383_oct_pkt_num;
u64 mac_tx_1519_max_bad_pkt_num;
u64 mac_tx_1519_max_good_pkt_num;
u64 mac_tx_oversize_pkt_num;
u64 mac_tx_jabber_pkt_num;
u64 mac_tx_pause_num;
u64 mac_tx_pfc_pkt_num;
u64 mac_tx_pfc_pri0_pkt_num;
u64 mac_tx_pfc_pri1_pkt_num;
u64 mac_tx_pfc_pri2_pkt_num;
u64 mac_tx_pfc_pri3_pkt_num;
u64 mac_tx_pfc_pri4_pkt_num;
u64 mac_tx_pfc_pri5_pkt_num;
u64 mac_tx_pfc_pri6_pkt_num;
u64 mac_tx_pfc_pri7_pkt_num;
u64 mac_tx_control_pkt_num;
u64 mac_tx_y1731_pkt_num;
u64 mac_tx_1588_pkt_num;
u64 mac_tx_err_all_pkt_num;
u64 mac_tx_from_app_good_pkt_num;
u64 mac_tx_from_app_bad_pkt_num;
u64 mac_rx_higig2_ext_pkt_num;
u64 mac_rx_higig2_message_pkt_num;
u64 mac_rx_higig2_error_pkt_num;
u64 mac_rx_higig2_cpu_ctrl_pkt_num;
u64 mac_rx_higig2_unicast_pkt_num;
u64 mac_rx_higig2_broadcast_pkt_num;
u64 mac_rx_higig2_l2_multicast_pkt_num;
u64 mac_rx_higig2_l3_multicast_pkt_num;
u64 mac_tx_higig2_message_pkt_num;
u64 mac_tx_higig2_ext_pkt_num;
u64 mac_tx_higig2_cpu_ctrl_pkt_num;
u64 mac_tx_higig2_unicast_pkt_num;
u64 mac_tx_higig2_broadcast_pkt_num;
u64 mac_tx_higig2_l2_multicast_pkt_num;
u64 mac_tx_higig2_l3_multicast_pkt_num;
};
struct hinic_port_stats_info {
u8 status;
u8 version;
u8 rsvd0[6];
u16 func_id;
u16 rsvd1;
u32 stats_version;
u32 stats_size;
};
struct hinic_port_stats {
u8 status;
u8 version;
u8 rsvd[6];
struct hinic_phy_port_stats stats;
};
struct hinic_cmd_vport_stats {
u8 status;
u8 version;
u8 rsvd0[6];
struct hinic_vport_stats stats;
};
int hinic_port_add_mac(struct hinic_dev *nic_dev, const u8 *addr, int hinic_port_add_mac(struct hinic_dev *nic_dev, const u8 *addr,
u16 vlan_id); u16 vlan_id);
...@@ -384,4 +552,10 @@ int hinic_rss_get_template_tbl(struct hinic_dev *nic_dev, u32 tmpl_idx, ...@@ -384,4 +552,10 @@ int hinic_rss_get_template_tbl(struct hinic_dev *nic_dev, u32 tmpl_idx,
int hinic_rss_get_hash_engine(struct hinic_dev *nic_dev, u8 tmpl_idx, int hinic_rss_get_hash_engine(struct hinic_dev *nic_dev, u8 tmpl_idx,
u8 *type); u8 *type);
int hinic_get_phy_port_stats(struct hinic_dev *nic_dev,
struct hinic_phy_port_stats *stats);
int hinic_get_vport_stats(struct hinic_dev *nic_dev,
struct hinic_vport_stats *stats);
#endif #endif
...@@ -56,6 +56,9 @@ void hinic_rxq_clean_stats(struct hinic_rxq *rxq) ...@@ -56,6 +56,9 @@ void hinic_rxq_clean_stats(struct hinic_rxq *rxq)
u64_stats_update_begin(&rxq_stats->syncp); u64_stats_update_begin(&rxq_stats->syncp);
rxq_stats->pkts = 0; rxq_stats->pkts = 0;
rxq_stats->bytes = 0; rxq_stats->bytes = 0;
rxq_stats->errors = 0;
rxq_stats->csum_errors = 0;
rxq_stats->other_errors = 0;
u64_stats_update_end(&rxq_stats->syncp); u64_stats_update_end(&rxq_stats->syncp);
} }
...@@ -74,6 +77,10 @@ void hinic_rxq_get_stats(struct hinic_rxq *rxq, struct hinic_rxq_stats *stats) ...@@ -74,6 +77,10 @@ void hinic_rxq_get_stats(struct hinic_rxq *rxq, struct hinic_rxq_stats *stats)
start = u64_stats_fetch_begin(&rxq_stats->syncp); start = u64_stats_fetch_begin(&rxq_stats->syncp);
stats->pkts = rxq_stats->pkts; stats->pkts = rxq_stats->pkts;
stats->bytes = rxq_stats->bytes; stats->bytes = rxq_stats->bytes;
stats->errors = rxq_stats->csum_errors +
rxq_stats->other_errors;
stats->csum_errors = rxq_stats->csum_errors;
stats->other_errors = rxq_stats->other_errors;
} while (u64_stats_fetch_retry(&rxq_stats->syncp, start)); } while (u64_stats_fetch_retry(&rxq_stats->syncp, start));
u64_stats_update_end(&stats->syncp); u64_stats_update_end(&stats->syncp);
} }
...@@ -101,10 +108,14 @@ static void rx_csum(struct hinic_rxq *rxq, u32 status, ...@@ -101,10 +108,14 @@ static void rx_csum(struct hinic_rxq *rxq, u32 status,
if (!(netdev->features & NETIF_F_RXCSUM)) if (!(netdev->features & NETIF_F_RXCSUM))
return; return;
if (!csum_err) if (!csum_err) {
skb->ip_summed = CHECKSUM_UNNECESSARY; skb->ip_summed = CHECKSUM_UNNECESSARY;
else } else {
if (!(csum_err & (HINIC_RX_CSUM_HW_CHECK_NONE |
HINIC_RX_CSUM_IPSU_OTHER_ERR)))
rxq->rxq_stats.csum_errors++;
skb->ip_summed = CHECKSUM_NONE; skb->ip_summed = CHECKSUM_NONE;
}
} }
/** /**
* rx_alloc_skb - allocate skb and map it to dma address * rx_alloc_skb - allocate skb and map it to dma address
......
...@@ -21,7 +21,10 @@ ...@@ -21,7 +21,10 @@
struct hinic_rxq_stats { struct hinic_rxq_stats {
u64 pkts; u64 pkts;
u64 bytes; u64 bytes;
u64 errors;
u64 csum_errors;
u64 other_errors;
u64 alloc_skb_err;
struct u64_stats_sync syncp; struct u64_stats_sync syncp;
}; };
......
...@@ -83,6 +83,7 @@ void hinic_txq_clean_stats(struct hinic_txq *txq) ...@@ -83,6 +83,7 @@ void hinic_txq_clean_stats(struct hinic_txq *txq)
txq_stats->tx_busy = 0; txq_stats->tx_busy = 0;
txq_stats->tx_wake = 0; txq_stats->tx_wake = 0;
txq_stats->tx_dropped = 0; txq_stats->tx_dropped = 0;
txq_stats->big_frags_pkts = 0;
u64_stats_update_end(&txq_stats->syncp); u64_stats_update_end(&txq_stats->syncp);
} }
...@@ -104,6 +105,7 @@ void hinic_txq_get_stats(struct hinic_txq *txq, struct hinic_txq_stats *stats) ...@@ -104,6 +105,7 @@ void hinic_txq_get_stats(struct hinic_txq *txq, struct hinic_txq_stats *stats)
stats->tx_busy = txq_stats->tx_busy; stats->tx_busy = txq_stats->tx_busy;
stats->tx_wake = txq_stats->tx_wake; stats->tx_wake = txq_stats->tx_wake;
stats->tx_dropped = txq_stats->tx_dropped; stats->tx_dropped = txq_stats->tx_dropped;
stats->big_frags_pkts = txq_stats->big_frags_pkts;
} while (u64_stats_fetch_retry(&txq_stats->syncp, start)); } while (u64_stats_fetch_retry(&txq_stats->syncp, start));
u64_stats_update_end(&stats->syncp); u64_stats_update_end(&stats->syncp);
} }
...@@ -464,6 +466,12 @@ netdev_tx_t hinic_xmit_frame(struct sk_buff *skb, struct net_device *netdev) ...@@ -464,6 +466,12 @@ netdev_tx_t hinic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
} }
nr_sges = skb_shinfo(skb)->nr_frags + 1; nr_sges = skb_shinfo(skb)->nr_frags + 1;
if (nr_sges > 17) {
u64_stats_update_begin(&txq->txq_stats.syncp);
txq->txq_stats.big_frags_pkts++;
u64_stats_update_end(&txq->txq_stats.syncp);
}
if (nr_sges > txq->max_sges) { if (nr_sges > txq->max_sges) {
netdev_err(netdev, "Too many Tx sges\n"); netdev_err(netdev, "Too many Tx sges\n");
goto skb_error; goto skb_error;
......
...@@ -21,6 +21,7 @@ struct hinic_txq_stats { ...@@ -21,6 +21,7 @@ struct hinic_txq_stats {
u64 tx_busy; u64 tx_busy;
u64 tx_wake; u64 tx_wake;
u64 tx_dropped; u64 tx_dropped;
u64 big_frags_pkts;
struct u64_stats_sync syncp; struct u64_stats_sync syncp;
}; };
......
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