net: hinic3: Support ethtool ops
Subsystems (4)
Fan Gong
maintainerPATCH v14 1/2 hinic3: Add ethtool statistic ops part1
In reply to Fan Gong Add PF/VF statistics functions in TX and RX processing. Implement following ethtool callback function:
.get_strings
.get_sset_count
.get_ethtool_stats
These callbacks allow users to utilize ethtool for detailed
TX and RX netdev stats monitoring.
--- .../ethernet/huawei/hinic3/hinic3_ethtool.c | 317 ++++++++++++++++++ .../ethernet/huawei/hinic3/hinic3_hw_intf.h | 11 + .../huawei/hinic3/hinic3_mgmt_interface.h | 37 ++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.c | 64 ++++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.h | 108 ++++++ .../net/ethernet/huawei/hinic3/hinic3_rx.c | 80 ++++- .../net/ethernet/huawei/hinic3/hinic3_rx.h | 7 +- .../net/ethernet/huawei/hinic3/hinic3_tx.c | 67 +++- .../net/ethernet/huawei/hinic3/hinic3_tx.h | 4 +- 9 files changed, 678 insertions(+), 17 deletions(-)
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +317 -0
@@ -13,8 +13,11 @@#include "hinic3_lld.h" #include "hinic3_hw_comm.h" +#include "hinic3_hwif.h" #include "hinic3_nic_dev.h" #include "hinic3_nic_cfg.h" +#include "hinic3_tx.h" +#include "hinic3_rx.h" #define HINIC3_MGMT_VERSION_MAX_LEN 32
@@ -409,6 +412,317 @@ hinic3_get_link_ksettings(struct net_device *netdev,return 0 ; } +struct hinic3_stats { +char name[ETH_GSTRING_LEN ]; +int offset; +}; + +#define HINIC3_STAT_SIZE_CHECK (type, member) \ + BUILD_BUG_ON_ZERO(sizeof_field(type, member) != sizeof(u64)) + +#define HINIC3_FUNC_STAT (_stat_item) { \ + .name = #_stat_item, \ + .offset = offsetof(struct l2nic_vport_stats, _stat_item) \ + + 0 * HINIC3_STAT_SIZE_CHECK(struct l2nic_vport_stats, \ + _stat_item) \ +} + +static struct hinic3_stats hinic3_function_stats[] = { +HINIC3_FUNC_STAT (tx_unicast_pkts_vport), +HINIC3_FUNC_STAT (tx_unicast_bytes_vport), +HINIC3_FUNC_STAT (tx_multicast_pkts_vport), +HINIC3_FUNC_STAT (tx_multicast_bytes_vport), +HINIC3_FUNC_STAT (tx_broadcast_pkts_vport), +HINIC3_FUNC_STAT (tx_broadcast_bytes_vport), + +HINIC3_FUNC_STAT (rx_unicast_pkts_vport), +HINIC3_FUNC_STAT (rx_unicast_bytes_vport), +HINIC3_FUNC_STAT (rx_multicast_pkts_vport), +HINIC3_FUNC_STAT (rx_multicast_bytes_vport), +HINIC3_FUNC_STAT (rx_broadcast_pkts_vport), +HINIC3_FUNC_STAT (rx_broadcast_bytes_vport), + +HINIC3_FUNC_STAT (tx_discard_vport), +HINIC3_FUNC_STAT (rx_discard_vport), +HINIC3_FUNC_STAT (tx_err_vport), +HINIC3_FUNC_STAT (rx_err_vport), +}; + +#define HINIC3_PORT_STAT (_stat_item) { \ + .name = #_stat_item, \ + .offset = offsetof(struct mag_cmd_port_stats, _stat_item) \ + + 0 * HINIC3_STAT_SIZE_CHECK(struct mag_cmd_port_stats, \ + _stat_item) \ +} + +static struct hinic3_stats hinic3_port_stats[] = { +HINIC3_PORT_STAT (mac_tx_fragment_pkt_num), +HINIC3_PORT_STAT (mac_tx_undersize_pkt_num), +HINIC3_PORT_STAT (mac_tx_undermin_pkt_num), +HINIC3_PORT_STAT (mac_tx_64_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_65_127_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_128_255_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_256_511_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_512_1023_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_1024_1518_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_1519_2047_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_2048_4095_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_4096_8191_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_8192_9216_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_9217_12287_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_12288_16383_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_1519_max_bad_pkt_num), +HINIC3_PORT_STAT (mac_tx_1519_max_good_pkt_num), +HINIC3_PORT_STAT (mac_tx_oversize_pkt_num), +HINIC3_PORT_STAT (mac_tx_jabber_pkt_num), +HINIC3_PORT_STAT (mac_tx_bad_pkt_num), +HINIC3_PORT_STAT (mac_tx_bad_oct_num), +HINIC3_PORT_STAT (mac_tx_total_pkt_num), +HINIC3_PORT_STAT (mac_tx_uni_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri0_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri1_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri2_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri3_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri4_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri5_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri6_pkt_num), +HINIC3_PORT_STAT (mac_tx_pfc_pri7_pkt_num), +HINIC3_PORT_STAT (mac_tx_err_all_pkt_num), +HINIC3_PORT_STAT (mac_tx_from_app_good_pkt_num), +HINIC3_PORT_STAT (mac_tx_from_app_bad_pkt_num), + +HINIC3_PORT_STAT (mac_rx_fragment_pkt_num), +HINIC3_PORT_STAT (mac_rx_undersize_pkt_num), +HINIC3_PORT_STAT (mac_rx_undermin_pkt_num), +HINIC3_PORT_STAT (mac_rx_64_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_65_127_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_128_255_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_256_511_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_512_1023_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_1024_1518_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_1519_2047_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_2048_4095_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_4096_8191_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_8192_9216_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_9217_12287_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_12288_16383_oct_pkt_num), +HINIC3_PORT_STAT (mac_rx_1519_max_bad_pkt_num), +HINIC3_PORT_STAT (mac_rx_1519_max_good_pkt_num), +HINIC3_PORT_STAT (mac_rx_bad_pkt_num), +HINIC3_PORT_STAT (mac_rx_bad_oct_num), +HINIC3_PORT_STAT (mac_rx_total_pkt_num), +HINIC3_PORT_STAT (mac_rx_uni_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri0_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri1_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri2_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri3_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri4_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri5_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri6_pkt_num), +HINIC3_PORT_STAT (mac_rx_pfc_pri7_pkt_num), +HINIC3_PORT_STAT (mac_rx_send_app_good_pkt_num), +HINIC3_PORT_STAT (mac_rx_send_app_bad_pkt_num), +HINIC3_PORT_STAT (mac_rx_unfilter_pkt_num), +}; + +#define HINIC3_TXQ_STAT (_stat_item) { \ + .name = "txq%d_"#_stat_item, \ + .offset = offsetof(struct hinic3_txq_stats, _stat_item) \ + + 0 * HINIC3_STAT_SIZE_CHECK(struct hinic3_txq_stats, \ + _stat_item) \ +} + +#define HINIC3_RXQ_STAT (_stat_item) { \ + .name = "rxq%d_"#_stat_item, \ + .offset = offsetof(struct hinic3_rxq_stats, _stat_item) \ + + 0 * HINIC3_STAT_SIZE_CHECK(struct hinic3_rxq_stats, \ + _stat_item) \ +} + +static struct hinic3_stats hinic3_tx_queue_stats[] = { +HINIC3_TXQ_STAT (busy), +HINIC3_TXQ_STAT (skb_pad_err), +HINIC3_TXQ_STAT (offload_cow_skb_err), +HINIC3_TXQ_STAT (map_frag_err), +HINIC3_TXQ_STAT (unknown_tunnel_pkt), +}; + +static struct hinic3_stats hinic3_rx_queue_stats[] = { +HINIC3_RXQ_STAT (csum_errors), +HINIC3_RXQ_STAT (other_errors), +HINIC3_RXQ_STAT (rx_buf_empty), +HINIC3_RXQ_STAT (alloc_skb_err), +HINIC3_RXQ_STAT (alloc_rx_buf_err), +}; + +static u16 hinic3_get_hw_stats_strings (struct hinic3_nic_dev *nic_dev,char *p) +{ +u16 i, cnt =0 ; + +for (i =0 ; i <ARRAY_SIZE (hinic3_function_stats); i++) { +memcpy (p, hinic3_function_stats[i].name,ETH_GSTRING_LEN ); + p +=ETH_GSTRING_LEN ; + cnt++; + } + +if (!HINIC3_IS_VF (nic_dev->hwdev)) { +for (i =0 ; i <ARRAY_SIZE (hinic3_port_stats); i++) { +memcpy (p, hinic3_port_stats[i].name,ETH_GSTRING_LEN ); + p +=ETH_GSTRING_LEN ; + cnt++; + } + } + +return cnt; +} + +static void hinic3_get_qp_stats_strings (struct hinic3_nic_dev *nic_dev,char *p) +{ +u8 *data = p; +u16 i, j; + +for (i =0 ; i < nic_dev->q_params.num_qps; i++) { +for (j =0 ; j <ARRAY_SIZE (hinic3_tx_queue_stats); j++) +ethtool_sprintf (&data, + hinic3_tx_queue_stats[j].name, i); + } + +for (i =0 ; i < nic_dev->q_params.num_qps; i++) { +for (j =0 ; j <ARRAY_SIZE (hinic3_rx_queue_stats); j++) +ethtool_sprintf (&data, + hinic3_rx_queue_stats[j].name, i); + } +} + +static void hinic3_get_strings (struct net_device *netdev, +u32 stringset,u8 *data) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +char *p = (char *)data; +u16 offset; + +switch (stringset) { +case ETH_SS_STATS : + offset =hinic3_get_hw_stats_strings (nic_dev, p); +hinic3_get_qp_stats_strings (nic_dev, + p + offset *ETH_GSTRING_LEN ); + +break ; + } +} + +static int hinic3_get_sset_count (struct net_device *netdev,int sset) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +int count, q_num; + +switch (sset) { +case ETH_SS_STATS : + q_num = nic_dev->q_params.num_qps; + count =ARRAY_SIZE (hinic3_function_stats) + + (ARRAY_SIZE (hinic3_tx_queue_stats) + +ARRAY_SIZE (hinic3_rx_queue_stats)) * + q_num; + +if (!HINIC3_IS_VF (nic_dev->hwdev)) + count +=ARRAY_SIZE (hinic3_port_stats); + +return count; +default : +return -EOPNOTSUPP ; + } +} + +static u16 hinic3_get_ethtool_port_stats (struct net_device *netdev,u64 *data) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct mag_cmd_port_stats *ps; +u16 i =0 , j; +char *p; +int err; + + ps =kmalloc_obj (*ps); +if (!ps) + goto err_zero_stats; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err (netdev,"Failed to get port stats from fw\n" ); + goto err_zero_stats; + } + +for (j =0 ; j <ARRAY_SIZE (hinic3_port_stats); j++, i++) { + p = (char *)ps + hinic3_port_stats[j].offset; + data[i] = *(u64 *)p; + } + +kfree (ps); + +return i; + +err_zero_stats: +memset (&data[i],0 ,ARRAY_SIZE (hinic3_port_stats) *sizeof (*data)); + +return i +ARRAY_SIZE (hinic3_port_stats); +} + +static void hinic3_get_drv_queue_stats (struct net_device *netdev,u64 *data) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct hinic3_txq_stats txq_stats = {}; +struct hinic3_rxq_stats rxq_stats = {}; +u16 i =0 , j, qid; +char *p; + +for (qid =0 ; qid < nic_dev->q_params.num_qps; qid++) { +hinic3_txq_get_stats (&nic_dev->txqs[qid], &txq_stats); +for (j =0 ; j <ARRAY_SIZE (hinic3_tx_queue_stats); j++, i++) { + p = (char *)&txq_stats + + hinic3_tx_queue_stats[j].offset; + data[i] = *(u64 *)p; + } + } + + i = nic_dev->q_params.num_qps *ARRAY_SIZE (hinic3_tx_queue_stats); +for (qid =0 ; qid < nic_dev->q_params.num_qps; qid++) { +hinic3_rxq_get_stats (&nic_dev->rxqs[qid], &rxq_stats); +for (j =0 ; j <ARRAY_SIZE (hinic3_rx_queue_stats); j++, i++) { + p = (char *)&rxq_stats + + hinic3_rx_queue_stats[j].offset; + data[i] = *(u64 *)p; + } + } +} + +static void hinic3_get_ethtool_stats (struct net_device *netdev, +struct ethtool_stats *stats,u64 *data) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct l2nic_vport_stats vport_stats = {}; +u16 i =0 , j; +char *p; +int err; + + err =hinic3_get_vport_stats (nic_dev->hwdev, +hinic3_global_func_id (nic_dev->hwdev), + &vport_stats); +if (err) +netdev_err (netdev,"Failed to get function stats from fw\n" ); + +for (j =0 ; j <ARRAY_SIZE (hinic3_function_stats); j++, i++) { + p = (char *)&vport_stats + hinic3_function_stats[j].offset; + data[i] = *(u64 *)p; + } + +if (!HINIC3_IS_VF (nic_dev->hwdev)) + i +=hinic3_get_ethtool_port_stats (netdev, data + i); + +hinic3_get_drv_queue_stats (netdev, data + i); +} +static const struct ethtool_ops hinic3_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_PKT_RATE_RX_USECS ,
@@ -417,6 +731,9 @@ static const struct ethtool_ops hinic3_ethtool_ops = { .get_msglevel = hinic3_get_msglevel, .set_msglevel = hinic3_set_msglevel, .get_link = ethtool_op_get_link, + .get_strings = hinic3_get_strings, + .get_sset_count = hinic3_get_sset_count, + .get_ethtool_stats = hinic3_get_ethtool_stats, };void hinic3_set_ethtool_ops (struct net_device *netdev)
drivers/net/ethernet/huawei/hinic3/hinic3_hw_intf.h +11 -0
@@ -53,6 +53,17 @@ static inline void mgmt_msg_params_init_default(struct mgmt_msg_params *msg_para msg_params->timeout_ms =0 ; } +static inline void +mgmt_msg_params_init_in_out (struct mgmt_msg_params *msg_params,void *in_buf, +void *out_buf,u32 in_buf_size,u32 out_buf_size) +{ + msg_params->buf_in = in_buf; + msg_params->buf_out = out_buf; + msg_params->in_size = in_buf_size; + msg_params->expected_out_size = out_buf_size; + msg_params->timeout_ms =0 ; +} +enum cfg_cmd {CFG_CMD_GET_DEV_CAP =0 , };
drivers/net/ethernet/huawei/hinic3/hinic3_mgmt_interface.h +37 -0
@@ -143,6 +143,41 @@ struct l2nic_cmd_set_dcb_state {u8 rsvd[7 ]; }; +struct l2nic_port_stats_info { +struct mgmt_msg_head msg_head; +u16 func_id; +u16 rsvd1; +}; + +struct l2nic_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 l2nic_cmd_vport_stats { +struct mgmt_msg_head msg_head; +u32 stats_size; +u32 rsvd1; +struct l2nic_vport_stats stats; +u64 rsvd2[6 ]; +}; +struct l2nic_cmd_lro_config {struct mgmt_msg_head msg_head;u16 func_id;
@@ -234,6 +269,7 @@ enum l2nic_cmd {L2NIC_CMD_SET_VPORT_ENABLE =6 ,L2NIC_CMD_SET_RX_MODE =7 ,L2NIC_CMD_SET_SQ_CI_ATTR =8 , +L2NIC_CMD_GET_VPORT_STAT =9 ,L2NIC_CMD_CLEAR_QP_RESOURCE =11 ,L2NIC_CMD_CFG_RX_LRO =13 , L2NIC_CMD_CFG_LRO_TIMER = 14,
@@ -272,6 +308,7 @@ enum mag_cmd {MAG_CMD_SET_PORT_ENABLE =6 ,MAG_CMD_GET_LINK_STATUS =7 , +MAG_CMD_GET_PORT_STAT =151 , MAG_CMD_GET_PORT_INFO = 153, };
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c +64 -0
67 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.h +108 -0
118 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +70 -10
151 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_rx.h +6 -1
@@ -8,6 +8,10 @@#include <linux/dim.h> #include <linux/netdevice.h> +/* rx cqe checksum err */ +#define HINIC3_RX_CSUM_HW_CHECK_NONE BIT(7) +#define HINIC3_RX_CSUM_IPSU_OTHER_ERR BIT(8) +#define RQ_CQE_OFFOLAD_TYPE_PKT_TYPE_MASK GENMASK(4, 0)#define RQ_CQE_OFFOLAD_TYPE_IP_TYPE_MASK GENMASK(6, 5)#define RQ_CQE_OFFOLAD_TYPE_TUNNEL_PKT_FORMAT_MASK GENMASK(11, 8)
@@ -39,7 +43,6 @@ struct hinic3_rxq_stats {u64 rx_buf_empty;u64 alloc_skb_err;u64 alloc_rx_buf_err; -u64 restore_drop_sge;struct u64_stats_sync syncp; };
@@ -125,4 +128,6 @@ int hinic3_configure_rxqs(struct net_device *netdev, u16 num_rq, u32 rq_depth, struct hinic3_dyna_rxq_res *rxqs_res);int hinic3_rx_poll (struct hinic3_rxq *rxq,int budget); +void hinic3_rxq_get_stats (struct hinic3_rxq *rxq, +struct hinic3_rxq_stats *stats);#endif
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c +63 -4
133 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_tx.h +2 -2
@@ -106,11 +106,9 @@ struct hinic3_txq_stats {u64 busy;u64 dropped;u64 skb_pad_err; -u64 frag_len_overflow;u64 offload_cow_skb_err;u64 map_frag_err;u64 unknown_tunnel_pkt; -u64 frag_size_err;struct u64_stats_sync syncp; };
@@ -160,4 +158,6 @@ netdev_tx_t hinic3_xmit_frame(struct sk_buff *skb, struct net_device *netdev);bool hinic3_tx_poll (struct hinic3_txq *txq,int budget);void hinic3_flush_txqs (struct net_device *netdev); +void hinic3_txq_get_stats (struct hinic3_txq *txq, +struct hinic3_txq_stats *stats);#endif
Signature · 1 line
2.43.0
Fan Gong
maintainerv14 cover net: hinic3: Support ethtool ops
This is [3/3] part of hinic3 Ethernet driver second submission. With this patch hinic3 becomes a complete Ethernet driver.
These patch-set will include all ethtool interfaces for hinic3. To facilitate review, this interfaces will be Split into multiple submissions, with each commit limited to approximately 1000 lines of code.
Add:
.get_strings
.get_sset_count
.get_ethtool_stats
.get_eth_phy_stats
.get_eth_mac_stats
.get_eth_ctrl_stats
.get_rmon_stats
.get_pause_stats
Changes:
PATCH 03 V01: https://lore.kernel.org/netdev/[email protected]/
* Add rmon/pause/phy/mac/ctrl stats (Ioana Ciornei)
PATCH 03 V02: https://lore.kernel.org/netdev/[email protected]/
* Remove OutOfRangeLengthField, FrameToolong and InRangeLengthErrors (Ioana Ciornei)
* Remove redundant mtu commit (Maxime Chevallier)
* Modify "return -EINVAL" intension problem (AI review)
* Use le16_to_cpu for rss_indir pair.out->buf (AI review)
* Use u32 instead of int in coalesce_limits to avoid overflow (AI review)
* Remove redundant u64_stats_update_begin/end when reading stats without concurrent reader (AI review)
* Modify nic_dev->stats.syncp logic (AI review)
* Complete rxq/txq stats stats fileds in hinic3_rx/txq_get_stats (AI review)
* Remove statistics values in rtnl_link_stats64 from ethtool statistics values (AI review)
* Add channel_cfg_lock & channel_res_lock to protect resources access (AI review)
PATCH 03 V03: https://lore.kernel.org/netdev/[email protected]/
* Change unnedd to unneeded (AI review)
* Remove packets,bytes,errors and dropped in hinic3_rx/tx_queue_stats (AI review)
* Remove duplicated entried in hinic3_port_stats[] (AI review)
* change stats_info.head.status to ps->head.status (AI review)
PATCH 03 V04: https://lore.kernel.org/netdev/[email protected]/
* Use old_q_param to store old config and use it in error handling (Mohsin Bashir)
* Add netdev_info to inform the user that depth is trimmed (Mohsin Bashir)
* Remove const in hinic3_get_qp_stats_strings parameters (Mohsin Bashir)
* Change EOPNOTSUPP to ERANGE in is_coalesce_exceed_limit (Mohsin Bashir)
* Update nic_dev->rss_type after hinic3_set_rss_type (Mohsin Bashir)
* Modify MGMT_STATUS_CMD_UNSUPPORTED to EOPNOTSUPP for complying with the error code specifications (Mohsin Bashir)
* Remove restore_drop_sge in hinic3_rx_queue_stats (AI review)
* Remove hinic3_nic_stats (AI review)
PATCH 03 V05: https://lore.kernel.org/netdev/[email protected]/
* As tx and rx share interrupts, we only use ETHTOOL_COALESCE_RX_USECS for user setting to avoid user misunderstanding. So we do not add ETHTOOL_COALESCE_TX_USECS. (Mohsin Bashir & AI review)
* Clear HINIC3_CHANGE_RES_INVALID bit in error handling (AI review)
* Use low >= high to avoid low=high in is_coalesce_legal (AI review)
PATCH 03 V06: https://lore.kernel.org/netdev/[email protected]/
* Remove redundant rx_jumbo_pending and rx_mini_pending judgement (Jakub Kicinski)
* Remove redundant max tx_pending judgement when .get_ringparam already got the max value (Jakub Kicinski)
* Use extack instead of netdev_err/netdev_info/netdev_warning (Jakub Kicinski)
* Remove HINIC3_CHANNEL_RES_VALID and only use HINIC3_CHANGE_RES_INVALID
bit (Jakub Kicinski)
* Deference freed pointers in hinic3_change_channel_settings error
handling (Jakub Kicinski)
* Modify hinic3_open_channel (Jakub Kicinski)
PATCH 03 V07: https://lore.kernel.org/netdev/[email protected]/
* Remove the trailing '\n' in NL_SET_ERR_MSG* (Jakub Kicinski)
PATCH 03 V08: https://lore.kernel.org/netdev/[email protected]/
* Update patch commit to be more accurate for change information (AI review)
* Modify <net/devlink.h> to <linux/netlink.h> (AI review)
* Use sq/rq_depth instead of rx/txqs[0].q_depth (AI review)
* hinic3_change_channel_settings() runs under change_res_mutex
to protect dynamic channel updates (AI review)
* hinic3_close() serializes close and channel reconfiguration paths (AI review)
* Remove useless u64_stats_init in hinic3_get_drv_queue_stats() (AI review)
* hinic3_get_drv_queue_stats() fills rxq stats at correct idx
when txq is null (AI review)
* Remove unnecessary semicolons after the closing bracket of
static inline functions (AI review)
* Disable preemption in hinic3_rx_fill_buffers() (AI review)
* Add spinlock to protect per-queue coalesce parameters from
concurrent access (AI review)
* Reject static coalesce config when adaptive RX coalesce is
enabled (AI review)
* Validate interface state and queue ID before modifying coalesce parameters (AI review)
* Differentiate get_coalesce output for adaptive/static modes and zero-fill the struct (AI review)
* Return -ERANGE for invalid coalesce frame limits and simplify
error message (AI review)
* Remove unused watchdog timeout definition and assignment (AI review)
* Return -EOPNOTSUPP when RSS type query is unsupported by firmware (AI review)
* Reject L4 hash bits for pure L3 flow types (AI review)
* Split RSS type conversion to correctly handle L3-only flows (AI review)
* Reprogram RSS indir table and HW parameters after channel count changes (AI review)
* Propagate exact error code from channel parameter validation (AI review)
* Update SW RSS indir copy only after HW programming succeeds (AI review)
* Program RSS hash type to HW before updating SW state to prevent inconsistency (AI review)
PATCH 03 V09: https://lore.kernel.org/netdev/[email protected]/
* Remove useless messages in hinic3_set_ringparam() (Jakub Kicinski)
* Solve the big-endian and little-endian issue (Jakub Kicinski)
PATCH 03 V10: https://lore.kernel.org/netdev/[email protected]/
* Unify 3 mutex in struct hinic3_nic_dev: port_state_mutex, change_res_mutex, coal_lock.(Simon Horman)
* Use rxq->q_mask instead of rxq->q_depth - 1 in hinic3_configure_rxqs() (Dimitri Daskalakis)
* Implement dedicated get_rx_ring_count ethtool operation (Dimitri Daskalakis)
* Correct copy-paste error in hinic3_get_ringparam() (AI Review and Harshitha Ramamurthy)
* Clarify extack error message in hinic3_check_ringparam_valid() (Harshitha Ramamurthy)
* Use rounddown_pow_of_two() instead of 1U << ilog2() in hinic3_set_ringparam() for readability. (Harshitha Ramamurthy)
* hinic3_set_interrupt_moder() now compare q_id and num_qps inside mutex lock (AI Review)
* Error branches in hinic3_link_status_change() goto unlock mutex before return (AI Review)
* In hinic3_change_channel_settings(), hinic3_config_num_qps() and hinic3_alloc_channel_resources() now run inside mutex lock. (AI Review)
* Call hinic3_free_qp_ctxts() in error paths of hinic3_open_channel(), thus hinic3_change_channel_settings() don't call it in error path (AI Review)
* Unset HINIC3_INTF_UP during close and reopen in hinic3_change_channel_settings
* hinic3_change_channel_settings() restore previous resources before freeing new_qp_params (AI Review)
* Delete unused macro HINIC3_LRO_PKT_HDR_LEN (AI Review)
* Drop packets when skb_checksum_help() return error (AI Review)
* Protect interrupt coalesce parameter reads with state_lock to prevent data races(AI Review)
* Restore previous coalesce parameters on HW configuration failure (AI Review)
* Always report all coalesce parameters regardless of adaptive mode (AI Review)
* Safely stop DIM work when disabling adaptive RX coalescing (AI Review)
* Change coalesce disabled message from extack error to info log (AI Review)
* Pass new RSS hash type to HW instead of the old one (AI Review)
* Initialize default RSS indirection table before HW programming when not user-configured(AI Review)
* Revert queue count on RSS reprogramming failure (AI Review)
* Use sizeof for RSS indirection table copy to prevent size mismatch (AI Review)
PATCH 03 V11: https://lore.kernel.org/all/[email protected]/
* Remove state_lock in hinic3_set_interrupt_moder() and hinic3_link_status_change() (Andrew Lunn and AI Review)
* In hinic3_change_channel_settings(), cur_trxq_params is read after taking lock, and get symmetrically restored when alloc resources failed. (AI Review)
* Remove preempt_disable()/preempt_enable() pairs in hinic3_rx_fill_buffers(). (AI Review)
* Add a comment about csum_err, and rewrite its judgement in hinic3_rx_csum(). (AI Review)
* Rollback hash function type to previous state if setting RSS indirection table or key fails (AI Review)
* Allow users to disable L3 hashing for IPV4/IPV6 flows by properly handling empty hash tuple in ethtool (AI Review)
* Update software queue coalesce state only after successful hardware configuration to avoid manual rollback (AI Review)
* Use READ_ONCE and WRITE_ONCE for adaptive_rx_coal to ensure safe concurrent memory access (AI Review)
* Reset RX queue DIM state to DIM_START_MEASURE when canceling
adaptive RX coalescing work (AI Review)
* Remove unnecessary state_lock mutexes when reading queue coalesce parameters in IRQ and update paths (AI Review)
* Rename is_coalesce_legal to hinic3_validate_coalesce for better code readability and naming consistency (AI Review)
PATCH 03 V12: https://lore.kernel.org/all/[email protected]/
* Remove get_val_of_ptr() which is unnecessary (Dimitri Daskalakis)
* Split the monolithic patch into multiple patches (Mohsin Bashir)
* Fix MSI-X leak and defer q_params publication and add error-path
rollback to prevent regressions (AI Review)
* Rfactor hinic3_update_hash_func_type() (AI Review)
* Guard irq_cfg traversal with INTF_UP check to prevent NULL dereference and fully reinitialize DIM state on adaptive re-enable (AI Review)
* Snapshot per-queue coalesce configs before applying and rollback via backup array on partial failure to ensure atomic set_coalesce (AI Review)
PATCH 03 V13: https://lore.kernel.org/netdev/[email protected]/
* Split previous version into 3 parts. The first 2 patches were sent to net tree, patch #5, #6 and #8 stayes in this series, and others will be sent in the future. (Larysa Zaremba and Jakub Kicinski)
* Remove dead size field from struct hinic3_stats and add HINIC3_STAT_SIZE_CHECK() with BUILD_BUG_ON_ZERO to enforce
per-entry compile-time verification that all stats members are u64. (AI Review)
* Remove never-incremented frag_len_overflow and frag_size_err from hinic3_txq_stats, hinic3_txq_clean_stats(), hinic3_txq_get_stats()
and the hinic3_tx_queue_stats ethtool table. (AI Review)
* Add missing txq_stats.busy increment in hinic3_send_one_skb() when returning NETDEV_TX_BUSY due to insufficient WQEBBs. (AI Review)
* Add missing txq_stats.offload_cow_skb_err increment when offload
type is invalid in hinic3_send_one_skb(). (AI Review)
* Remove mac_tx_good_oct_num and mac_rx_good_oct_num from the hinic3_port_stats private table as they are already reported through
the get_eth_mac_stats standard interface. (AI Review)
* Fix OctetsTransmittedOK/ReceivedOK mapping in
hinic3_get_eth_mac_stats() to use mac_tx/rx_good_oct_num instead
of mac_tx/rx_total_oct_num per RFC 2863 (error-free frames only). (AI Review)
* Add HINIC3_IS_VF guard to hinic3_get_eth_phy_stats() to prevent
VF from reading physical port stats, consistent with the ethtool
-S path which already gates hinic3_port_stats on PF-only. (AI Review)
* Use u64_stats_update_begin_irqsave/end_irqrestore in hinic3_rx_fill_buffers() where the function can be called from preemptible process context via hinic3_configure_rxqs(), avoiding seqcount deadlock on 32-bit systems. (AI Review)
* Expand state_lock protection scope in hinic3_get_coalesce() and hinic3_set_coalesce() to cover intr_coalesce array accesses. (AI Review)
* Use standard net_dim_work_cancel() in hinic3_set_coalesce() to cancel DIM work instead of manually clearing struct fields, ensuring safe DIM state reset and simplifying error rollback. (AI Review)
PATCH 03 V14:
* Remove if (!nic_dev->txqs) & if (!nic_dev->rxqs). (Vadim Fedorenko)
* All comments regarding this submission have been documented and will be addressed incrementally in subsequent patch-set.
Fan Gong (2):
hinic3: Add ethtool statistic ops part1
hinic3: Add ethtool statistic ops part2
.../ethernet/huawei/hinic3/hinic3_ethtool.c | 495 ++++++++++++++++++ .../ethernet/huawei/hinic3/hinic3_hw_intf.h | 11 + .../huawei/hinic3/hinic3_mgmt_interface.h | 37 ++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.c | 64 +++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.h | 108 ++++ .../net/ethernet/huawei/hinic3/hinic3_rx.c | 80 ++- .../net/ethernet/huawei/hinic3/hinic3_rx.h | 7 +- .../net/ethernet/huawei/hinic3/hinic3_tx.c | 67 ++- .../net/ethernet/huawei/hinic3/hinic3_tx.h | 4 +- 9 files changed, 856 insertions(+), 17 deletions(-)
base-commit: 93f51579e7df248780214094418f205253383cc5
Signature · 1 line
2.43.0
Fan Gong
maintainerPATCH v14 2/2 hinic3: Add ethtool statistic ops part2
Add PF/VF statistics functions in TX and RX processing. Implement following ethtool callback function:
.get_eth_phy_stats
.get_eth_mac_stats
.get_eth_ctrl_stats
.get_rmon_stats
.get_pause_stats
These callbacks allow users to utilize ethtool for detailed
TX and RX netdev stats monitoring.
--- .../ethernet/huawei/hinic3/hinic3_ethtool.c | 178 ++++++++++++++++++ 1 file changed, 178 insertions(+)
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +178 -0
@@ -723,6 +723,179 @@ static void hinic3_get_ethtool_stats(struct net_device *netdev,hinic3_get_drv_queue_stats (netdev, data + i); } +static void hinic3_get_eth_phy_stats (struct net_device *netdev, +struct ethtool_eth_phy_stats *phy_stats) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct mag_cmd_port_stats *ps; +int err; + +if (HINIC3_IS_VF (nic_dev->hwdev)) +return ; + + ps =kmalloc_obj (*ps); +if (!ps) +return ; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err (netdev,"Failed to get eth phy stats from fw\n" ); +return ; + } + + phy_stats->SymbolErrorDuringCarrier = ps->mac_rx_sym_err_pkt_num; + +kfree (ps); +} + +static void hinic3_get_eth_mac_stats (struct net_device *netdev, +struct ethtool_eth_mac_stats *mac_stats) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct mag_cmd_port_stats *ps; +int err; + + ps =kmalloc_obj (*ps); +if (!ps) +return ; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err (netdev,"Failed to get eth mac stats from fw\n" ); +return ; + } + + mac_stats->FramesTransmittedOK = ps->mac_tx_good_pkt_num; + mac_stats->FramesReceivedOK = ps->mac_rx_good_pkt_num; + mac_stats->FrameCheckSequenceErrors = ps->mac_rx_fcs_err_pkt_num; + mac_stats->OctetsTransmittedOK = ps->mac_tx_good_oct_num; + mac_stats->OctetsReceivedOK = ps->mac_rx_good_oct_num; + mac_stats->MulticastFramesXmittedOK = ps->mac_tx_multi_pkt_num; + mac_stats->BroadcastFramesXmittedOK = ps->mac_tx_broad_pkt_num; + mac_stats->MulticastFramesReceivedOK = ps->mac_rx_multi_pkt_num; + mac_stats->BroadcastFramesReceivedOK = ps->mac_rx_broad_pkt_num; + +kfree (ps); +} + +static void hinic3_get_eth_ctrl_stats (struct net_device *netdev, +struct ethtool_eth_ctrl_stats *ctrl_stats) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct mag_cmd_port_stats *ps; +int err; + + ps =kmalloc_obj (*ps); +if (!ps) +return ; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err (netdev,"Failed to get eth ctrl stats from fw\n" ); +return ; + } + + ctrl_stats->MACControlFramesTransmitted = ps->mac_tx_control_pkt_num; + ctrl_stats->MACControlFramesReceived = ps->mac_rx_control_pkt_num; + +kfree (ps); +} + +static const struct ethtool_rmon_hist_range hinic3_rmon_ranges[] = { + {0 ,64 }, + {65 ,127 }, + {128 ,255 }, + {256 ,511 }, + {512 ,1023 }, + {1024 ,1518 }, + {1519 ,2047 }, + {2048 ,4095 }, + {4096 ,8191 }, + {8192 ,9216 }, + {9217 ,12287 }, + {} +}; + +static void hinic3_get_rmon_stats (struct net_device *netdev, +struct ethtool_rmon_stats *rmon_stats, +const struct ethtool_rmon_hist_range **ranges) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct mag_cmd_port_stats *ps; +int err; + + ps =kmalloc_obj (*ps); +if (!ps) +return ; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err (netdev,"Failed to get eth rmon stats from fw\n" ); +return ; + } + + rmon_stats->undersize_pkts = ps->mac_rx_undersize_pkt_num; + rmon_stats->oversize_pkts = ps->mac_rx_oversize_pkt_num; + rmon_stats->fragments = ps->mac_rx_fragment_pkt_num; + rmon_stats->jabbers = ps->mac_rx_jabber_pkt_num; + + rmon_stats->hist[0 ] = ps->mac_rx_64_oct_pkt_num; + rmon_stats->hist[1 ] = ps->mac_rx_65_127_oct_pkt_num; + rmon_stats->hist[2 ] = ps->mac_rx_128_255_oct_pkt_num; + rmon_stats->hist[3 ] = ps->mac_rx_256_511_oct_pkt_num; + rmon_stats->hist[4 ] = ps->mac_rx_512_1023_oct_pkt_num; + rmon_stats->hist[5 ] = ps->mac_rx_1024_1518_oct_pkt_num; + rmon_stats->hist[6 ] = ps->mac_rx_1519_2047_oct_pkt_num; + rmon_stats->hist[7 ] = ps->mac_rx_2048_4095_oct_pkt_num; + rmon_stats->hist[8 ] = ps->mac_rx_4096_8191_oct_pkt_num; + rmon_stats->hist[9 ] = ps->mac_rx_8192_9216_oct_pkt_num; + rmon_stats->hist[10 ] = ps->mac_rx_9217_12287_oct_pkt_num; + + rmon_stats->hist_tx[0 ] = ps->mac_tx_64_oct_pkt_num; + rmon_stats->hist_tx[1 ] = ps->mac_tx_65_127_oct_pkt_num; + rmon_stats->hist_tx[2 ] = ps->mac_tx_128_255_oct_pkt_num; + rmon_stats->hist_tx[3 ] = ps->mac_tx_256_511_oct_pkt_num; + rmon_stats->hist_tx[4 ] = ps->mac_tx_512_1023_oct_pkt_num; + rmon_stats->hist_tx[5 ] = ps->mac_tx_1024_1518_oct_pkt_num; + rmon_stats->hist_tx[6 ] = ps->mac_tx_1519_2047_oct_pkt_num; + rmon_stats->hist_tx[7 ] = ps->mac_tx_2048_4095_oct_pkt_num; + rmon_stats->hist_tx[8 ] = ps->mac_tx_4096_8191_oct_pkt_num; + rmon_stats->hist_tx[9 ] = ps->mac_tx_8192_9216_oct_pkt_num; + rmon_stats->hist_tx[10 ] = ps->mac_tx_9217_12287_oct_pkt_num; + + *ranges = hinic3_rmon_ranges; + +kfree (ps); +} + +static void hinic3_get_pause_stats (struct net_device *netdev, +struct ethtool_pause_stats *pause_stats) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct mag_cmd_port_stats *ps; +int err; + + ps =kmalloc_obj (*ps); +if (!ps) +return ; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err (netdev,"Failed to get eth pause stats from fw\n" ); +return ; + } + + pause_stats->tx_pause_frames = ps->mac_tx_pause_num; + pause_stats->rx_pause_frames = ps->mac_rx_pause_num; + +kfree (ps); +} +static const struct ethtool_ops hinic3_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_PKT_RATE_RX_USECS ,
@@ -734,6 +907,11 @@ static const struct ethtool_ops hinic3_ethtool_ops = { .get_strings = hinic3_get_strings, .get_sset_count = hinic3_get_sset_count, .get_ethtool_stats = hinic3_get_ethtool_stats, + .get_eth_phy_stats = hinic3_get_eth_phy_stats, + .get_eth_mac_stats = hinic3_get_eth_mac_stats, + .get_eth_ctrl_stats = hinic3_get_eth_ctrl_stats, + .get_rmon_stats = hinic3_get_rmon_stats, + .get_pause_stats = hinic3_get_pause_stats, };void hinic3_set_ethtool_ops (struct net_device *netdev)
Signature · 1 line
2.43.0
Re: [PATCH net-next v14 1/2] hinic3: Add ethtool statistic ops part1
In reply to Fan GongQuoted 5 lines · Fan Gong
Add PF/VF statistics functions in TX and RX processing. Implement following ethtool callback function:
.get_strings
.get_sset_count
.get_ethtool_stats
Please break these into the standard statistic groups. Only proprietary counters which are not part of standard groups should be reported via this interface.
Andrew
---
pw-bot: cr
[email protected]
AI reviewRe: [PATCH net-next v14 1/2] hinic3: Add ethtool statistic ops part1
In reply to Fan GongThank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 4 (1) · Low: 2 (1)
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] hinic3_rx_poll() now returns budget instead of nr_pkts when the loop exits because num_wqe >= nic_dev->lro_replenish_thld (new…
- [Medium] The new ethtool -S string tables add driver-private counters that already have a standard kernel uAPI, which networking-drivers.md…
- [Medium] hinic3_get_pkt_stats() uses (gso_segs - 1) * skb_tcp_all_headers(skb) to compute the replicated header bytes for…
- [Medium] net: hinic3: LRO packets undercounted in RX statistics
- [Low] In hinic3_rx_csum() the patch adds a second copy of the comment '/* pkt type is recognized by HW, and csum is wrong */' above the new…
- [Low] Each call to hinic3_get_ethtool_stats() sends L2NIC_CMD_GET_VPORT_STAT and, on a PF, MAG_CMD_GET_PORT_STAT to the…
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the new rx_buf_empty counter in hinic3_rx_fill_buffers() records an RQ-…
- [Low] The patch adds txq_stats.dropped++ on hinic3_send_one_skb()'s err_out path.
--
hinic3: Add ethtool statistic ops part1
This commit adds per-queue TX/RX software counters and firmware-backed vport and physical port statistics to the hinic3 driver. It implements the .get_strings, .get_sset_count and .get_ethtool_stats callbacks so these can be read with ethtool -S, and adds packet/byte accounting to the RX and TX hot paths.
Quoted 4 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +6
-0+static struct hinic3_stats hinic3_port_stats[] = { +HINIC3_PORT_STAT (mac_tx_fragment_pkt_num), +HINIC3_PORT_STAT (mac_tx_undersize_pkt_num), +HINIC3_PORT_STAT (mac_tx_undermin_pkt_num), +HINIC3_PORT_STAT (mac_tx_64_oct_pkt_num), +HINIC3_PORT_STAT (mac_tx_65_127_oct_pkt_num),
[ ... ]
Quoted 5 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +5
-0+HINIC3_PORT_STAT (mac_rx_fragment_pkt_num), +HINIC3_PORT_STAT (mac_rx_undersize_pkt_num), +HINIC3_PORT_STAT (mac_rx_undermin_pkt_num), +HINIC3_PORT_STAT (mac_rx_64_oct_pkt_num), + HINIC3_PORT_STAT(mac_rx_65_127_oct_pkt_num),
[ ... ]
Quoted 5 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +5
-0+static struct hinic3_stats hinic3_tx_queue_stats[] = { +HINIC3_TXQ_STAT (busy), +HINIC3_TXQ_STAT (skb_pad_err), +HINIC3_TXQ_STAT (offload_cow_skb_err), +HINIC3_TXQ_STAT (map_frag_err),
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c hinic3_get_link_ksettings(struct net_device *netdev, · line 558
Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +10
-0+ HINIC3_TXQ_STAT(unknown_tunnel_pkt), +}; + +static struct hinic3_stats hinic3_rx_queue_stats[] = { +HINIC3_RXQ_STAT (csum_errors), +HINIC3_RXQ_STAT (other_errors), +HINIC3_RXQ_STAT (rx_buf_empty), +HINIC3_RXQ_STAT (alloc_skb_err), +HINIC3_RXQ_STAT (alloc_rx_buf_err), +};
[Severity: Medium]
Several of these ethtool -S strings look like duplicates of counters that already have a standard uAPI.
In the port stats, mac_{rx,tx}_64_oct_pkt_num through mac_{rx,tx}_12288_16383_oct_pkt_num map onto the ethtool_rmon_stats hist[] and hist_tx[] buckets. mac_rx_fragment_pkt_num and mac_rx_undersize_pkt_num map onto ethtool_rmon_stats fragments and undersize_pkts. The per-priority PFC counters overlap with the DCB ieee_pfc requests/indications.
In the per-queue stats:
rxq%d_csum_errors corresponds to netdev_queue_stats_rx csum_bad rxq%d_alloc_skb_err and rxq%d_alloc_rx_buf_err correspond to netdev_queue_stats_rx alloc_fail
txq%d_busy is close to netdev_queue_stats_tx stop
All of these are exposed through netdev netlink qstats (struct netdev_stat_ops), which hinic3 does not implement yet.
The follow-up "hinic3: Add ethtool statistic ops part2" adds .get_rmon_stats, .get_pause_stats and .get_eth_mac_stats, and fills hist[]/hist_tx[] from the same mac_*_oct_pkt_num fields. It does not remove those entries from hinic3_port_stats[], though. At the end of the series, won't the histogram, fragment and undersize counters be exported twice?
Could these entries be dropped from the ethtool -S tables in favour of the standard interfaces, with netdev_stat_ops added for the per-queue ones?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +4
-0+static void hinic3_get_ethtool_stats (struct net_device *netdev, +struct ethtool_stats *stats,u64 *data) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev);
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c hinic3_get_link_ksettings(struct net_device *netdev, · line 713
Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +10
-0+struct l2nic_vport_stats vport_stats = {}; +u16 i =0 , j; +char *p; +int err; + + err =hinic3_get_vport_stats (nic_dev->hwdev, +hinic3_global_func_id (nic_dev->hwdev), + &vport_stats); +if (err) +netdev_err (netdev,"Failed to get function stats from fw\n" );
[Severity: Low]__dev_ethtool() does not require CAP_NET_ADMIN for ETHTOOL_GSTATS. Every call here sends L2NIC_CMD_GET_VPORT_STAT to the management firmware, and on a PF it also sends MAG_CMD_GET_PORT_STAT through hinic3_get_ethtool_port_stats().
If the firmware rejects these commands or is unresponsive, each call logs a dev_err() from hinic3_get_vport_stats() and hinic3_get_phy_port_stats(), plus the netdev_err() calls here and in hinic3_get_ethtool_port_stats(). None of these are rate limited.
Could an unprivileged user running ethtool -S in a loop flood the kernel log this way, while also keeping the mailbox busy under rtnl? Would a ratelimited variant, or logging only once per failure path, work better here? The part2 commit appears to add more firmware-backed callbacks that follow the same pattern.
[ ... ]
Quoted 4 lines
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +0
-0
[ ... ]
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c static u32 hinic3_rx_fill_buffers(struct hinic3_rxq *rxq) · line 180
Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +5
-0@@ -170,6 +172,11 @@ static u32 hinic3_rx_fill_buffers(struct hinic3_rxq *rxq) rxq->next_to_update << HINIC3_NORMAL_RQ_WQE); rxq->delta -= i; rxq->next_to_alloc = rxq->next_to_update; + }else if (free_wqebbs == rxq->q_depth -1 ) { + syncp = &rxq->rxq_stats.syncp; + flags =u64_stats_update_begin_irqsave (syncp); + rxq->rxq_stats.rx_buf_empty++; +u64_stats_update_end_irqrestore (syncp, flags); }
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch. The new rx_buf_empty counter records a state that the driver does not appear to recover from by itself.
The only runtime refill is in hinic3_rx_poll():
if (rxq->delta >= HINIC3_RX_BUFFER_WRITE) hinic3_rx_fill_buffers(rxq);
Suppose page_pool_dev_alloc_frag() keeps failing under memory pressure until every posted buffer has been consumed. The RQ then has no posted WQEs and the NIC stops producing RX CQEs. hinic3_poll() calls napi_complete_done() and re-enables MSI-X, and no timer or work item retries the refill.
The SQ and RQ share the MSI-X vector, so a TX completion on the same queue pair would schedule NAPI again. On a queue pair with no TX traffic, does RX stay stalled until the interface is reset?
Quoted 2 lines
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +0
-0return i;
[ ... ]
Quoted 1 line
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +0
-0@@ -330,10 +337,24 @@ static void hinic3_rx_csum(struct hinic3_rxq *rxq, u32 offload_type,
[ ... ]
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c static void hinic3_rx_csum(struct hinic3_rxq *rxq, u32 offload_type, · line 360
Quoted 11 lines
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +7
-0if (unlikely (csum_err)) { +/* pkt type is recognized by HW, and csum is wrong */ +if (csum_err !=HINIC3_RX_CSUM_HW_CHECK_NONE && + csum_err !=HINIC3_RX_CSUM_IPSU_OTHER_ERR ) { +u64_stats_update_begin (&rxq->rxq_stats.syncp); + rxq->rxq_stats.csum_errors++; +u64_stats_update_end (&rxq->rxq_stats.syncp); + }/* pkt type is recognized by HW, and csum is wrong */ skb->ip_summed =CHECKSUM_NONE ;return ;
[Severity: Low]
This isn't a bug, but the comment "pkt type is recognized by HW, and csum is wrong" now appears twice. The second copy sits above the fallback that also runs for HINIC3_RX_CSUM_HW_CHECK_NONE and HINIC3_RX_CSUM_IPSU_OTHER_ERR. The new condition treats those two values as not being checksum errors.
Could the second copy be removed or reworded?
[ ... ]
Quoted 1 line
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +0
-0@@ -575,18 +603,50 @@ int hinic3_rx_poll(struct hinic3_rxq *rxq, int budget)
[ ... ]
Quoted 8 lines
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +3
-1rx_cqe->status =0 ; -if (num_wqe >= nic_dev->lro_replenish_thld) +if (num_wqe >= nic_dev->lro_replenish_thld) { + poll_again = true;break ; + } }
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c int hinic3_rx_poll(struct hinic3_rxq *rxq, int budget) · line 635
Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c +5
-1if (rxq->delta >=HINIC3_RX_BUFFER_WRITE )hinic3_rx_fill_buffers (rxq); -return nr_pkts; +u64_stats_update_begin (&rxq->rxq_stats.syncp); + rxq->rxq_stats.packets += (u64 )nr_pkts; + rxq->rxq_stats.bytes += rx_bytes; +u64_stats_update_end (&rxq->rxq_stats.syncp); +return poll_again ? budget : nr_pkts;
[Severity: Medium]
Are the RX packet and byte counters meant to measure the same thing for LRO completions? Right now they don't.
When num_lro is non-zero, hinic3_rx_poll() adds
(num_lro - 1) * pkt_hdr_len to rx_bytes. That rebuilds the header bytes the hardware stripped while coalescing, so rx_bytes approximates the bytes of all num_lro frames seen on the wire.
rxq_stats.packets is bumped by nr_pkts, though, and nr_pkts only counts one per CQE. A completion that coalesced num_lro segments adds the wire bytes of num_lro frames but counts as a single packet.
These counters feed rx_packets and rx_bytes in hinic3_get_stats64(). With LRO enabled, rx_packets is undercounted and the average RX packet size looks inflated. The TX side does count wire packets:hinic3_get_pkt_stats() adds gso_segs to txq_stats.packets. So TX and RX now use different conventions.
Should the loop keep a separate packet count that adds num_lro (or 1 when num_lro is 0) and use that for rxq_stats.packets? nr_pkts would stay as the NAPI budget counter. Alternatively, if per-aggregate counting is what you want, should the header-length adjustment to rx_bytes be dropped so both counters agree?
[Severity: Medium]
This changes the return value when the loop exits on the LRO replenish threshold. It used to return nr_pkts and now returns budget.
In hinic3_poll():
work_done = hinic3_rx_poll(irq_cfg->rxq, budget); busy |= work_done >= budget; if (busy) return budget;
As a result, the threshold exit now skips napi_complete_done(), hinic3_net_dim() and the MSI-X re-enable. NAPI keeps polling instead of waiting for the next interrupt.
This seems unrelated to statistics, and the commit message does not mention it. Was it intended? If it fixes an LRO stall, could it go in a separate patch with its own explanation and a Fixes: tag?
Quoted 4 lines
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c +0
-0
[ ... ]
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c static u16 hinic3_set_wqe_combo(struct hinic3_txq *txq, · line 505
Quoted 12 lines
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c +8
-0@@ -487,6 +495,27 @@ static u16 hinic3_set_wqe_combo(struct hinic3_txq *txq, num_sge + !!offload); } +static void hinic3_get_pkt_stats (struct hinic3_txq *txq,struct sk_buff *skb) +{ +u32 hdr_len, tx_bytes; +unsigned short pkts; + +if (skb_is_gso (skb)) { + hdr_len = (skb_shinfo (skb)->gso_segs -1 ) * +skb_tcp_all_headers (skb);
[Severity: Medium]
Is skb_tcp_all_headers() correct for encapsulated GSO skbs? When VXLAN offload is supported, the driver advertises NETIF_F_GSO_UDP_TUNNEL and NETIF_F_GSO_UDP_TUNNEL_CSUM, so VXLAN-encapsulated TSO skbs reach this code.
For those skbs, skb_transport_header() points at the outer UDP header. tcp_hdrlen() then reads doff from the VXLAN header (the first VNI byte) instead of the inner TCP header. That usually gives 0, not the size of the replicated headers.
hinic3_tso() already switches to skb_inner_transport_header() when skb->encapsulation is set, and include/linux/tcp.h provides skb_inner_tcp_all_headers() for this case. hinic3_get_stats64() reports txq_stats.bytes as tx_bytes, so wouldn't tx_bytes be undercounted for tunnel traffic?
Quoted 3 lines
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c +3
-0+ tx_bytes = skb->len + hdr_len; + pkts =skb_shinfo (skb)->gso_segs; + }else {
[ ... ]
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c static netdev_tx_t hinic3_send_one_skb(struct sk_buff *skb, · line 655
Quoted 9 lines
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c +3
-0@@ -608,6 +648,9 @@ static netdev_tx_t hinic3_send_one_skb(struct sk_buff *skb, err_drop_pkt:dev_kfree_skb_any (skb); err_out: +u64_stats_update_begin (&txq->txq_stats.syncp); + txq->txq_stats.dropped++; +u64_stats_update_end (&txq->txq_stats.syncp);return NETDEV_TX_OK ; }
[Severity: Low]
This isn't a bug introduced by this patch, but hinic3_xmit_frame() has its own drop path that never reaches err_out:
if (unlikely(!netif_carrier_ok(netdev))) goto err_drop_pkt; if (unlikely(q_id >= nic_dev->q_params.num_qps)) goto err_drop_pkt; ... err_drop_pkt: dev_kfree_skb_any(skb); return NETDEV_TX_OK;
Drops taken here are not counted anywhere, so they will not show up in tx_dropped. Is that intended?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1791858167.git.gongfan1%40huawei.com
[email protected]
AI reviewRe: [PATCH net-next v14 2/2] hinic3: Add ethtool statistic ops part2
In reply to Fan GongThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Of the five new callbacks, only hinic3_get_eth_phy_stats() returns early for VFs (if (HINIC3_IS_VF(nic_dev->hwdev)) return;).
- [Medium] Several counters are now reported through both the private ethtool -S table and the standard RMON uAPI.
- [Medium] Nothing can ever call hinic3_get_pause_stats().
- [Low] The commit message does not describe this patch.
--
hinic3: Add ethtool statistic ops part2
This commit adds five standard ethtool statistics callbacks to the hinic3
driver: get_eth_phy_stats, get_eth_mac_stats, get_eth_ctrl_stats, get_rmon_stats and get_pause_stats. Each callback reads the physical port counters from firmware via hinic3_get_phy_port_stats() and copies them into the standard ethtool structures.
Quoted 1 line
Add PF/VF statistics functions in TX and RX processing.
[Severity: Low]
This isn't a bug, but this sentence matches the one in the part1 commit ("hinic3: Add ethtool statistic ops part1"). This patch doesn't touch any TX or RX processing code. It only adds read-only ethtool callbacks in hinic3_ethtool.c that use the MAG_CMD_GET_PORT_STAT firmware query.
The message also doesn't say how VFs are handled. Only hinic3_get_eth_phy_stats() returns early for VFs.
Could the commit message be updated to describe what this patch does?
Quoted 17 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +9
-0@@ -723,6 +723,179 @@ static void hinic3_get_ethtool_stats(struct net_device *netdev,hinic3_get_drv_queue_stats (netdev, data + i); } +static void hinic3_get_eth_phy_stats (struct net_device *netdev, +struct ethtool_eth_phy_stats *phy_stats) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct mag_cmd_port_stats *ps; +int err; + +if (HINIC3_IS_VF (nic_dev->hwdev)) +return ;
[ ... ]
Quoted 7 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +7
-0+static void hinic3_get_eth_mac_stats (struct net_device *netdev, +struct ethtool_eth_mac_stats *mac_stats) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct mag_cmd_port_stats *ps; +int err; +
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c static void hinic3_get_ethtool_stats(struct net_device *netdev, · line 768
Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +10
-0+ ps =kmalloc_obj (*ps); +if (!ps) +return ; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err (netdev,"Failed to get eth mac stats from fw\n" ); +return ; + }
[Severity: Medium]
Should this callback, and the new ctrl, rmon and pause callbacks, have the same HINIC3_IS_VF() check as hinic3_get_eth_phy_stats()?
As written, on a VF these call hinic3_get_phy_port_stats(), which sends MAG_CMD_GET_PORT_STAT for hinic3_physical_port_id(hwdev).
The rest of the driver keeps physical port stats away from VFs. For example, hinic3_get_ethtool_stats() does:
if (!HINIC3_IS_VF(nic_dev->hwdev)) i += hinic3_get_ethtool_port_stats(netdev, data + i);
hinic3_get_hw_stats_strings() and hinic3_get_sset_count() do the same. hinic3_get_link_settings() also skips the pause query on VFs.
ETHTOOL_MSG_STATS_GET does not require admin permission. Any unprivileged user can reach these callbacks with something like
"ethtool -S <vf> --groups eth-mac eth-ctrl rmon".
If firmware accepts the query from a VF, the VF sees port-wide MAC, control and RMON counters. Those include traffic from the PF and every other VF on the port.
If firmware rejects it, each request makes several blocking mailbox round trips. Each failure also logs an unratelimited dev_err() in hinic3_get_phy_port_stats() plus a netdev_err() in the callback. Could that be used to flood the kernel log?
[ ... ]
Quoted 4 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +4
-0+static void hinic3_get_rmon_stats (struct net_device *netdev, +struct ethtool_rmon_stats *rmon_stats, +const struct ethtool_rmon_hist_range **ranges) +{
[ ... ]
Quoted 6 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +6
-0+ rmon_stats->undersize_pkts = ps->mac_rx_undersize_pkt_num; + rmon_stats->oversize_pkts = ps->mac_rx_oversize_pkt_num; + rmon_stats->fragments = ps->mac_rx_fragment_pkt_num; + rmon_stats->jabbers = ps->mac_rx_jabber_pkt_num; + + rmon_stats->hist[0 ] = ps->mac_rx_64_oct_pkt_num;
[ ... ]
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c static void hinic3_get_ethtool_stats(struct net_device *netdev, · line 868
Quoted 1 line
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +1
-0+ rmon_stats->hist_tx[10 ] = ps->mac_tx_9217_12287_oct_pkt_num;
[Severity: Medium]
Are these counters now reported to userspace twice? hinic3_port_stats[], added by the part1 patch, still exports the same values through ethtool -S:
HINIC3_PORT_STAT(mac_tx_64_oct_pkt_num), ... HINIC3_PORT_STAT(mac_tx_9217_12287_oct_pkt_num), ... HINIC3_PORT_STAT(mac_rx_fragment_pkt_num), HINIC3_PORT_STAT(mac_rx_undersize_pkt_num), ... HINIC3_PORT_STAT(mac_rx_64_oct_pkt_num), ... HINIC3_PORT_STAT(mac_rx_9217_12287_oct_pkt_num),
The table already omits the counters that the new mac, ctrl, pause and phy callbacks report (good, multi and broad counts, pause, control, oversize, jabber, sym_err, fcs_err). The RMON histogram, fragment and undersize entries are still in it.
Counters that have a standard uAPI should not be duplicated in ethtool -S. Should these 24 entries be removed from hinic3_port_stats[]?
[ ... ]
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c static const struct ethtool_ops hinic3_ethtool_ops = { · line 915
Quoted 10 lines
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +5
-0@@ -734,6 +907,11 @@ static const struct ethtool_ops hinic3_ethtool_ops = { .get_strings = hinic3_get_strings, .get_sset_count = hinic3_get_sset_count, .get_ethtool_stats = hinic3_get_ethtool_stats, + .get_eth_phy_stats = hinic3_get_eth_phy_stats, + .get_eth_mac_stats = hinic3_get_eth_mac_stats, + .get_eth_ctrl_stats = hinic3_get_eth_ctrl_stats, + .get_rmon_stats = hinic3_get_rmon_stats, + .get_pause_stats = hinic3_get_pause_stats, };
[Severity: Medium]
Can hinic3_get_pause_stats() ever be called? The driver doesn't provide a .get_pauseparam callback, and pause_prepare_data() in net/ethtool/pause.c returns before it calls get_pause_stats:
if (!dev->ethtool_ops->get_pauseparam) return -EOPNOTSUPP; ... dev->ethtool_ops->get_pauseparam(dev, &data->pauseparam); if (req_base->flags & ETHTOOL_FLAG_STATS && dev->ethtool_ops->get_pause_stats) dev->ethtool_ops->get_pause_stats(dev, &data->pausestat);
Pause stats aren't part of the ETHTOOL_MSG_STATS_GET groups either. So "ethtool -I -a <dev>" fails with -EOPNOTSUPP, and there is no standard way to read mac_tx_pause_num or mac_rx_pause_num.
Does this patch also need a .get_pauseparam implementation?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1791858167.git.gongfan1%40huawei.com