net: hinic3: Support ethtool ops
Subsystems (4)
Fan Gong
maintainerv19 cover net: hinic3: Support ethtool ops
This series adds the ethtool statistics, per-queue netdev-genl stats and pause parameter support for the hinic3 driver. It is a subset of the larger hinic3 patch set; the RX stall fix is already in net-next, and the link settings, PHY LED, FEC, ringparam and Hi1872/HTN patches will be sent separately.
Add ethtool ops:
.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
.get_pauseparam
.set_pauseparam
Add netdev ops:
.get_queue_stats_rx
.get_queue_stats_tx
.get_base_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: https://lore.kernel.org/netdev/[email protected]/
* 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.
PATCH 03 V15: https://lore.kernel.org/netdev/[email protected]/
* Break get_ethtool_stats into the standard statistic groups.
Only retain the counters which are not part of standard groups. (Andrew Lunn and AI Review)
* Netdev netlink qstats (struct netdev_stat_ops) does not be implemented by hinic3, it will be implemented in future. So the per-queue stats of rxq%d_csum_errors etc. will be retained in ethtool -S.(AI Review)
* Change netdev_err to netdev_err_once and dev_err to dev_err_once.
(AI Review)
* The stall of hinic3_rx_fill_buffers() and LRO in extreme condition will go in a separate patch.(AI Review)
* Use the same algorithms for calculating the number of bytes and packets in the TSO and LRO statistics.(AI Review)
* Replace skb_inner_transport_header() with skb_inner_tcp_all_headers() will go in a separate patch.(AI Review)
* Drops taken in hinic3_xmit_frame() are counted.(AI Review)
* u64_stats_update_begin() in hinic3_rxq_clean_stats() and hinic3_txq_clean_stats() will go in a separate patch.(AI Review)
* get_pauseparam callback will go in a separate patch.(AI Review)
PATCH 03 V16: https://lore.kernel.org/netdev/[email protected]/
* Change lro_packets = 1 to lro_packets++.(Mohsin Bashir)
* Init txq at the correct place.(Mohsin Bashir)
* Statistics in hinic3_function_stats and rtnl_link_stats64 originate from different sources: the chip records the former, while the driver records the latter. Chip statistics are readable via ethtool -S, and driver statistics are returned via rtnl_link_stats64.(AI Review)
* Change u64 to __le64 in l2nic_vport_stats and mag_cmd_port_stats.(AI Review)
* Reset lro_packets and gso_packets.(AI Review)
PATCH 03 V17: https://lore.kernel.org/netdev/[email protected]/
* Use ethtool_puts().(Dimitri Daskalakis)
* Remove the casting of char *p = (char *)data.(Dimitri Daskalakis)
* It was clarified in the last patch that tx_unicast_pkts_vport and per-queue metrics are not standard statistics.(AI Review)
* Use le64_to_cpu() to handle variables definded as __le64.(AI Review)
* Optimize the txq initialization position to prevent out-of-bounds memory access.(Mohsin Bashir & AI Review)
PATCH 03 V18: https://lore.kernel.org/netdev/[email protected]/
* Merge the alloc_skb_err and alloc_rx_buf_err counters into a standard alloc_fail counter.(Jakub Kicinski)
* Rename mac_rx/tx_1519_max_* to mac_rx/tx_jumbo_*.(Jakub Kicinski)
* Remove gso_packets and lro_packets.(Jakub Kicinski)
* Implement netdev netlink qstats (struct netdev_stat_ops) in hinic3 for per-queue standard counter.(AI Review)
* Remove some vport counters form ethtool -S. They will go in a separate patch.(AI Review)
* Remove mac_tx/rx_pfc_pri_* counter from ethtool -S. They will go in a separate patch for the dcbnl struct ieee_pfc.(AI Review)
* Move csum_errors to csum_bad in netdev netlink qstats.(AI Review)
* Solve the coexistence of hinic3_get_stats64() and hinic3_get_pkt_stats() on a 32-bit system and remove hinic3_get_pkt_stats().(AI Review)
* Detailed statistics of TSO and LRO will go in a separate patch. The problem in dim_update_sample() will be solved.(AI Review)
* Implement .get_pauseparam and .set_pauseparam for hinic3_get_pause_stats(). (AI Review)
PATCH 03 V19:
* Save skb->len to a local variable before the doorbell, so the TX completion path cannot free the skb before the stats read.(AI Review)
* Update the TX packet/byte counters from hinic3_tx_poll() when the device completes the descriptors, so in-flight and flushed skbs are not reported as sent.(AI Review)
* Count TX wire packets with skb_shinfo(skb)->gso_segs and add the repeated TCP header length to tx_bytes for TCP GSO. Guard gso_segs against zero.(AI Review)
* Count tx-stop only when netif_subqueue_try_stop()/maybe_stop() really stops the queue, and count the normal stop path as well.(AI Review)
* Count RX packets with num_lro for LRO aggregates.(AI Review)
* Move csum_errors to the standard rx-csum-bad qstats and keep only other_errors in rtnl_link_stats64.rx_errors.(AI Review)
* Count csum_errors regardless of NETIF_F_RXCSUM so toggling RXCSUM does not change the meaning of the counter.(AI Review)
* Add hinic3vf_ethtool_ops for VF, hinic3_ethtool_ops only for PF, so VF does not issue physical-port stats/pause commands.(AI Review)
* Only initialize the supported counters in hinic3_get_base_stats(), add stats_rx->alloc_fail, and use netdev->real_num_{rx,tx}_queues as the lower bound so the base range cannot overlap the per-queue range.(AI Review)
* Bound-check the queue index in hinic3_get_queue_stats_rx/tx().(AI Review)
* Merge the 12288-16383 octet bucket into the last RMON histogram range, since ETHTOOL_RMON_HIST_MAX is 11.(AI Review)
* Use the firmware pause values whenever hinic3_get_pause_info() succeeds and fall back to the cached state only on error.(AI Review)
* Preserve the firmware auto_neg when setting pause parameters and reject an explicit change, since pause autonegotiation is not user configurable.(AI Review)
* Change (u8)pause->rx_pause to !!pause->rx_pause to avoid values 2 to 255 being passed to firmware.(AI Review)
* Initialize nic_cfg.cfg_mutex and protect the cached pause state. (AI Review)
* Skip the pause query for VF during probe, since the firmware may not support L2NIC_CMD_CFG_PAUSE_INFO for VF.(AI Review)
* The vport multicast/discard/err counters are removed from ethtool -S and will be exposed through rtnl_link_stats64 in a separate patch. PFC per-priority counters will go to the dcbnl ieee_pfc interface separately.
* TX bytes expand the repeated TCP header for TCP GSO; UDP tunnel GSO and RX LRO wire byte accounting need hardware confirmation and will be addressed separately if required.
Fan Gong (4):
hinic3: Add ethtool statistic ops part(1/2)
hinic3: Add ethtool statistic ops part(2/2)
hinic3: Add per-queue netdev-genl stats
hinic3: Add ethtool pause param ops
.../ethernet/huawei/hinic3/hinic3_ethtool.c | 536 +++++++++++++++++- .../ethernet/huawei/hinic3/hinic3_hw_intf.h | 11 + .../net/ethernet/huawei/hinic3/hinic3_main.c | 8 + .../huawei/hinic3/hinic3_mgmt_interface.h | 37 ++ .../huawei/hinic3/hinic3_netdev_ops.c | 109 +++- .../ethernet/huawei/hinic3/hinic3_nic_cfg.c | 71 +++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.h | 114 +++- .../ethernet/huawei/hinic3/hinic3_nic_dev.h | 3 + .../net/ethernet/huawei/hinic3/hinic3_rx.c | 69 ++- .../net/ethernet/huawei/hinic3/hinic3_rx.h | 10 +- .../net/ethernet/huawei/hinic3/hinic3_tx.c | 149 ++++- .../net/ethernet/huawei/hinic3/hinic3_tx.h | 9 +- 12 files changed, 1085 insertions(+), 41 deletions(-)
base-commit: ed3135d0881a926de56a7f490dea3d51698ba118
Signature · 1 line
2.43.0
Fan Gong
maintainerPATCH v19 1/4 hinic3: Add ethtool statistic ops part(1/2)
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.
TX packet/byte counters are updated from hinic3_tx_poll() when the device completes the descriptors, so in-flight and flushed skbs are not reported as sent. tx-stop is counted only when the queue is really stopped, using the return value of netif_subqueue_try_stop() and netif_subqueue_maybe_stop().
TX packets and bytes are counted as wire packets and wire bytes: GSO skbs contribute skb_shinfo(skb)->gso_segs packets, and the repeated TCP header length is added to the byte count. gso_segs is clamped to at least one to keep the wire byte arithmetic well defined.
--- .../ethernet/huawei/hinic3/hinic3_ethtool.c | 257 ++++++++++++++++++ .../ethernet/huawei/hinic3/hinic3_hw_intf.h | 11 + .../huawei/hinic3/hinic3_mgmt_interface.h | 37 +++ .../huawei/hinic3/hinic3_netdev_ops.c | 3 +- .../ethernet/huawei/hinic3/hinic3_nic_cfg.c | 64 +++++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.h | 108 ++++++++ .../net/ethernet/huawei/hinic3/hinic3_rx.c | 69 ++++- .../net/ethernet/huawei/hinic3/hinic3_rx.h | 10 +- .../net/ethernet/huawei/hinic3/hinic3_tx.c | 149 ++++++++-- .../net/ethernet/huawei/hinic3/hinic3_tx.h | 9 +- 10 files changed, 679 insertions(+), 38 deletions(-)
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +257 -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,257 @@ 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_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_broadcast_pkts_vport), +HINIC3_FUNC_STAT (rx_broadcast_bytes_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_pkts), +HINIC3_PORT_STAT (mac_tx_undersize_pkts), +HINIC3_PORT_STAT (mac_tx_undermin_pkts), +HINIC3_PORT_STAT (mac_tx_jabber_bad_pkts), +HINIC3_PORT_STAT (mac_tx_jabber_good_pkts), +HINIC3_PORT_STAT (mac_tx_oversize_pkts), +HINIC3_PORT_STAT (mac_tx_ieee_jabber_pkts), +HINIC3_PORT_STAT (mac_tx_bad_pkts), +HINIC3_PORT_STAT (mac_tx_bad_octs), +HINIC3_PORT_STAT (mac_tx_total_pkts), +HINIC3_PORT_STAT (mac_tx_uni_pkts), +HINIC3_PORT_STAT (mac_tx_err_all_pkts), +HINIC3_PORT_STAT (mac_tx_from_app_good_pkts), +HINIC3_PORT_STAT (mac_tx_from_app_bad_pkts), + +HINIC3_PORT_STAT (mac_rx_undermin_pkts), +HINIC3_PORT_STAT (mac_rx_jabber_good_pkts), +HINIC3_PORT_STAT (mac_rx_ieee_jabber_pkts), +HINIC3_PORT_STAT (mac_rx_bad_pkts), +HINIC3_PORT_STAT (mac_rx_bad_octs), +HINIC3_PORT_STAT (mac_rx_total_pkts), +HINIC3_PORT_STAT (mac_rx_uni_pkts), +HINIC3_PORT_STAT (mac_rx_send_app_good_pkts), +HINIC3_PORT_STAT (mac_rx_send_app_bad_pkts), +HINIC3_PORT_STAT (mac_rx_unfilter_pkts), +}; + +#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 (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 (other_errors), +HINIC3_RXQ_STAT (rx_buf_empty), +}; + +static u16 hinic3_get_hw_stats_strings (struct hinic3_nic_dev *nic_dev,u8 *p) +{ +u16 i, cnt =0 ; + +for (i =0 ; i <ARRAY_SIZE (hinic3_function_stats); i++) { +ethtool_puts (&p, hinic3_function_stats[i].name); + cnt++; + } + +if (!HINIC3_IS_VF (nic_dev->hwdev)) { +for (i =0 ; i <ARRAY_SIZE (hinic3_port_stats); i++) { +ethtool_puts (&p, hinic3_port_stats[i].name); + cnt++; + } + } + +return cnt; +} + +static void hinic3_get_qp_stats_strings (struct hinic3_nic_dev *nic_dev,u8 *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 (&p, + 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 (&p, + 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); +u16 offset; + +switch (stringset) { +case ETH_SS_STATS : + offset =hinic3_get_hw_stats_strings (nic_dev, data); +hinic3_get_qp_stats_strings (nic_dev, + data + 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_once (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] =le64_to_cpu (*(__le64 *)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_once (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] =le64_to_cpu (*(__le64 *)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 +671,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 { +__le64 tx_unicast_pkts_vport; +__le64 tx_unicast_bytes_vport; +__le64 tx_multicast_pkts_vport; +__le64 tx_multicast_bytes_vport; +__le64 tx_broadcast_pkts_vport; +__le64 tx_broadcast_bytes_vport; + +__le64 rx_unicast_pkts_vport; +__le64 rx_unicast_bytes_vport; +__le64 rx_multicast_pkts_vport; +__le64 rx_multicast_bytes_vport; +__le64 rx_broadcast_pkts_vport; +__le64 rx_broadcast_bytes_vport; + +__le64 tx_discard_vport; +__le64 rx_discard_vport; +__le64 tx_err_vport; +__le64 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_netdev_ops.c +1 -2
@@ -816,8 +816,7 @@ static void hinic3_get_stats64(struct net_device *netdev, start =u64_stats_fetch_begin (&rxq_stats->syncp); bytes = rxq_stats->bytes; packets = rxq_stats->packets; - errors = rxq_stats->csum_errors + - rxq_stats->other_errors; + errors = rxq_stats->other_errors; dropped = rxq_stats->dropped; }while (u64_stats_fetch_retry (&rxq_stats->syncp, start)); stats->rx_packets += packets;
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 +62 -7
127 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_rx.h +7 -3
@@ -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)
@@ -37,9 +41,7 @@ struct hinic3_rxq_stats {u64 other_errors;u64 dropped;u64 rx_buf_empty; -u64 alloc_skb_err; -u64 alloc_rx_buf_err; -u64 restore_drop_sge; +u64 alloc_fail;struct u64_stats_sync syncp; };
@@ -125,4 +127,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 +125 -24
256 lines not on this page · raw message
drivers/net/ethernet/huawei/hinic3/hinic3_tx.h +7 -2
@@ -106,11 +106,14 @@ 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; +u64 gso_wire_packets; +u64 gso_wire_bytes; +u64 gso_packets; +u64 gso_bytes; +u64 wake;struct u64_stats_sync syncp; };
@@ -160,4 +163,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
maintainerPATCH v19 2/4 hinic3: Add ethtool statistic ops part(2/2)
In reply to Fan GongThis 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.
--- .../ethernet/huawei/hinic3/hinic3_ethtool.c | 218 +++++++++++++++++- 1 file changed, 217 insertions(+), 1 deletion(-)
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +217 -1
@@ -663,6 +663,199 @@ 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; + + ps =kmalloc_obj (*ps); +if (!ps) +return ; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err_once (netdev, +"Failed to get eth phy stats from fw\n" ); +return ; + } + + phy_stats->SymbolErrorDuringCarrier = +le64_to_cpu (ps->mac_rx_sym_err_pkts); + +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_once (netdev, +"Failed to get eth mac stats from fw\n" ); +return ; + } + + mac_stats->FramesTransmittedOK = +le64_to_cpu (ps->mac_tx_good_pkts); + mac_stats->FramesReceivedOK = +le64_to_cpu (ps->mac_rx_good_pkts); + mac_stats->FrameCheckSequenceErrors = +le64_to_cpu (ps->mac_rx_fcs_err_pkts); + mac_stats->OctetsTransmittedOK = +le64_to_cpu (ps->mac_tx_good_octs); + mac_stats->OctetsReceivedOK = +le64_to_cpu (ps->mac_rx_good_octs); + mac_stats->MulticastFramesXmittedOK = +le64_to_cpu (ps->mac_tx_multi_pkts); + mac_stats->BroadcastFramesXmittedOK = +le64_to_cpu (ps->mac_tx_broad_pkts); + mac_stats->MulticastFramesReceivedOK = +le64_to_cpu (ps->mac_rx_multi_pkts); + mac_stats->BroadcastFramesReceivedOK = +le64_to_cpu (ps->mac_rx_broad_pkts); + +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_once (netdev, +"Failed to get eth ctrl stats from fw\n" ); +return ; + } + + ctrl_stats->MACControlFramesTransmitted = +le64_to_cpu (ps->mac_tx_control_pkts); + ctrl_stats->MACControlFramesReceived = +le64_to_cpu (ps->mac_rx_control_pkts); + +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 ,16383 }, + {} +}; + +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) + goto get_rmon_stats_err; + + err =hinic3_get_phy_port_stats (nic_dev->hwdev, ps); +if (err) { +kfree (ps); +netdev_err_once (netdev, +"Failed to get eth rmon stats from fw\n" ); + goto get_rmon_stats_err; + } + + rmon_stats->undersize_pkts =le64_to_cpu (ps->mac_rx_undersize_pkts); + rmon_stats->oversize_pkts =le64_to_cpu (ps->mac_rx_oversize_pkts); + rmon_stats->fragments =le64_to_cpu (ps->mac_rx_fragment_pkts); + rmon_stats->jabbers =le64_to_cpu (ps->mac_rx_jabber_bad_pkts); + + rmon_stats->hist[0 ] =le64_to_cpu (ps->mac_rx_64_oct_pkts); + rmon_stats->hist[1 ] =le64_to_cpu (ps->mac_rx_65_127_oct_pkts); + rmon_stats->hist[2 ] =le64_to_cpu (ps->mac_rx_128_255_oct_pkts); + rmon_stats->hist[3 ] =le64_to_cpu (ps->mac_rx_256_511_oct_pkts); + rmon_stats->hist[4 ] =le64_to_cpu (ps->mac_rx_512_1023_oct_pkts); + rmon_stats->hist[5 ] =le64_to_cpu (ps->mac_rx_1024_1518_oct_pkts); + rmon_stats->hist[6 ] =le64_to_cpu (ps->mac_rx_1519_2047_oct_pkts); + rmon_stats->hist[7 ] =le64_to_cpu (ps->mac_rx_2048_4095_oct_pkts); + rmon_stats->hist[8 ] =le64_to_cpu (ps->mac_rx_4096_8191_oct_pkts); + rmon_stats->hist[9 ] =le64_to_cpu (ps->mac_rx_8192_9216_oct_pkts); + rmon_stats->hist[10 ] =le64_to_cpu (ps->mac_rx_9217_12287_oct_pkts); + rmon_stats->hist[10 ] +=le64_to_cpu (ps->mac_rx_12288_16383_oct_pkts); + + rmon_stats->hist_tx[0 ] =le64_to_cpu (ps->mac_tx_64_oct_pkts); + rmon_stats->hist_tx[1 ] =le64_to_cpu (ps->mac_tx_65_127_oct_pkts); + rmon_stats->hist_tx[2 ] =le64_to_cpu (ps->mac_tx_128_255_oct_pkts); + rmon_stats->hist_tx[3 ] =le64_to_cpu (ps->mac_tx_256_511_oct_pkts); + rmon_stats->hist_tx[4 ] =le64_to_cpu (ps->mac_tx_512_1023_oct_pkts); + rmon_stats->hist_tx[5 ] =le64_to_cpu (ps->mac_tx_1024_1518_oct_pkts); + rmon_stats->hist_tx[6 ] =le64_to_cpu (ps->mac_tx_1519_2047_oct_pkts); + rmon_stats->hist_tx[7 ] =le64_to_cpu (ps->mac_tx_2048_4095_oct_pkts); + rmon_stats->hist_tx[8 ] =le64_to_cpu (ps->mac_tx_4096_8191_oct_pkts); + rmon_stats->hist_tx[9 ] =le64_to_cpu (ps->mac_tx_8192_9216_oct_pkts); + rmon_stats->hist_tx[10 ] =le64_to_cpu (ps->mac_tx_9217_12287_oct_pkts); + rmon_stats->hist_tx[10 ] +=le64_to_cpu (ps->mac_tx_12288_16383_oct_pkts); + + *ranges = hinic3_rmon_ranges; + +kfree (ps); +return ; + +get_rmon_stats_err: + *ranges =NULL ; +} + +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_once (netdev, +"Failed to get eth pause stats from fw\n" ); +return ; + } + + pause_stats->tx_pause_frames =le64_to_cpu (ps->mac_tx_pause_pkts); + pause_stats->rx_pause_frames =le64_to_cpu (ps->mac_rx_pause_pkts); + +kfree (ps); +} +static const struct ethtool_ops hinic3_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_PKT_RATE_RX_USECS ,
@@ -674,9 +867,32 @@ 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, +}; + +static const struct ethtool_ops hinic3vf_ethtool_ops = { + .supported_coalesce_params =ETHTOOL_COALESCE_USECS | +ETHTOOL_COALESCE_PKT_RATE_RX_USECS , + .get_link_ksettings = hinic3_get_link_ksettings, + .get_drvinfo = hinic3_get_drvinfo, + .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) { - netdev->ethtool_ops = &hinic3_ethtool_ops; +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); + +if (!HINIC3_IS_VF (nic_dev->hwdev)) + netdev->ethtool_ops = &hinic3_ethtool_ops; +else + netdev->ethtool_ops = &hinic3vf_ethtool_ops; }
Signature · 1 line
2.43.0
Fan Gong
maintainerPATCH v19 3/4 hinic3: Add per-queue netdev-genl stats
In reply to Fan GongThis commit adds netdev_stat_ops to the hinic3 driver. It implements get_queue_stats_rx, get_queue_stats_tx and get_base_stats, so per-queue and device-level counters are exported through the netdev-genl qstats interface. Map busy to tx-stop, csum_errors to rx-csum-bad, alloc_fail to rx-alloc-fail.
get_base_stats() sums the queues between netdev->real_num_{rx,tx}_queues and nic_dev->max_qps, matching the range the core does not sum itself.
./cli.py --spec netlink/specs/netdev.yaml\
--dump qstats-get --json '{"ifindex": 30}'
[{'ifindex': 30,
'rx-alloc-fail': 0,
'rx-bytes': 13194720024,
'rx-csum-bad': 0,
'rx-packets': 10874477,
'tx-bytes': 150086739354,
'tx-hw-gso-bytes': 143674451028,
'tx-hw-gso-packets': 2261382,
'tx-hw-gso-wire-bytes': 150067172880,
'tx-hw-gso-wire-packets': 99120804,
'tx-packets': 99315841,
'tx-stop': 0,
'tx-wake': 0}]
--- .../huawei/hinic3/hinic3_netdev_ops.c | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+)
drivers/net/ethernet/huawei/hinic3/hinic3_netdev_ops.c +106 -0
@@ -5,6 +5,7 @@#include <linux/if_vlan.h> #include <linux/netdevice.h> #include <net/vxlan.h> +#include <net/netdev_queues.h> #include "hinic3_hwif.h" #include "hinic3_nic_cfg.h"
@@ -857,7 +858,112 @@ static const struct net_device_ops hinic3_netdev_ops = { .ndo_start_xmit = hinic3_xmit_frame, }; +static void hinic3_get_queue_stats_rx (struct net_device *netdev,int i, +struct netdev_queue_stats_rx *stats_rx) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct hinic3_rxq_stats *rxq_stats; +struct hinic3_rxq *rxq; +unsigned int start; + +if (unlikely (i <0 || i >= nic_dev->max_qps)) +return ; + + rxq = &nic_dev->rxqs[i]; + rxq_stats = &rxq->rxq_stats; +do { + start =u64_stats_fetch_begin (&rxq_stats->syncp); + stats_rx->bytes = rxq_stats->bytes; + stats_rx->packets = rxq_stats->packets; + stats_rx->csum_bad = rxq_stats->csum_errors; + stats_rx->alloc_fail = rxq_stats->alloc_fail; + }while (u64_stats_fetch_retry (&rxq_stats->syncp, start)); +} + +static void hinic3_get_queue_stats_tx (struct net_device *netdev,int i, +struct netdev_queue_stats_tx *stats_tx) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct hinic3_txq_stats *txq_stats; +struct hinic3_txq *txq; +unsigned int start; + +if (unlikely (i <0 || i >= nic_dev->max_qps)) +return ; + + txq = &nic_dev->txqs[i]; + txq_stats = &txq->txq_stats; +do { + start =u64_stats_fetch_begin (&txq_stats->syncp); + stats_tx->bytes = txq_stats->bytes; + stats_tx->packets = txq_stats->packets; + stats_tx->stop = txq_stats->busy; + stats_tx->hw_gso_wire_packets = txq_stats->gso_wire_packets; + stats_tx->hw_gso_wire_bytes = txq_stats->gso_wire_bytes; + stats_tx->hw_gso_packets = txq_stats->gso_packets; + stats_tx->hw_gso_bytes = txq_stats->gso_bytes; + stats_tx->wake = txq_stats->wake; + }while (u64_stats_fetch_retry (&txq_stats->syncp, start)); +} + +static void hinic3_get_base_stats (struct net_device *netdev, +struct netdev_queue_stats_rx *stats_rx, +struct netdev_queue_stats_tx *stats_tx) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +int i; + + stats_rx->bytes =0 ; + stats_rx->packets =0 ; + stats_rx->csum_bad =0 ; + stats_rx->alloc_fail =0 ; + stats_tx->bytes =0 ; + stats_tx->packets =0 ; + stats_tx->stop =0 ; + stats_tx->hw_gso_wire_packets =0 ; + stats_tx->hw_gso_wire_bytes =0 ; + stats_tx->hw_gso_packets =0 ; + stats_tx->hw_gso_bytes =0 ; + stats_tx->wake =0 ; + +/* Match the core: the base range starts at the active queue +* count, not at q_params.num_qps, which can lag behind. +*/ +for (i = netdev->real_num_rx_queues; i < nic_dev->max_qps; i++) { +struct netdev_queue_stats_rx rx = {0 }; + +hinic3_get_queue_stats_rx (netdev, i, &rx); + + stats_rx->bytes += rx.bytes; + stats_rx->packets += rx.packets; + stats_rx->csum_bad += rx.csum_bad; + stats_rx->alloc_fail += rx.alloc_fail; + } + +for (i = netdev->real_num_tx_queues; i < nic_dev->max_qps; i++) { +struct netdev_queue_stats_tx tx = {0 }; + +hinic3_get_queue_stats_tx (netdev, i, &tx); + + stats_tx->bytes += tx.bytes; + stats_tx->packets += tx.packets; + stats_tx->stop += tx.stop; + stats_tx->hw_gso_wire_packets += tx.hw_gso_wire_packets; + stats_tx->hw_gso_wire_bytes += tx.hw_gso_wire_bytes; + stats_tx->hw_gso_packets += tx.hw_gso_packets; + stats_tx->hw_gso_bytes += tx.hw_gso_bytes; + stats_tx->wake += tx.wake; + } +} + +static const struct netdev_stat_ops hinic3_stat_ops = { + .get_queue_stats_rx = hinic3_get_queue_stats_rx, + .get_queue_stats_tx = hinic3_get_queue_stats_tx, + .get_base_stats = hinic3_get_base_stats, +}; +void hinic3_set_netdev_ops (struct net_device *netdev) { netdev->netdev_ops = &hinic3_netdev_ops; + netdev->stat_ops = &hinic3_stat_ops; }
Signature · 1 line
2.43.0
Fan Gong
maintainerPATCH v19 4/4 hinic3: Add ethtool pause param ops
In reply to Fan GongAdd .get_pauseparam and .set_pauseparam callbacks to support reading and configuring port pause parameters.
Also initialize nic_cfg.cfg_mutex and use it to protect the cached pause state, and skip the pause query for VF during probe.
The getter reports the firmware values whenever the query succeeds and falls back to the cached state on error. The setter preserves the existing auto_neg because pause autonegotiation is not user configurable.
--- .../ethernet/huawei/hinic3/hinic3_ethtool.c | 61 +++++++++++++++++++ .../net/ethernet/huawei/hinic3/hinic3_main.c | 8 +++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.c | 7 +++ .../ethernet/huawei/hinic3/hinic3_nic_cfg.h | 6 +- .../ethernet/huawei/hinic3/hinic3_nic_dev.h | 3 + 5 files changed, 83 insertions(+), 2 deletions(-)
drivers/net/ethernet/huawei/hinic3/hinic3_ethtool.c +61 -0
@@ -856,6 +856,65 @@ static void hinic3_get_pause_stats(struct net_device *netdev,kfree (ps); } +static void hinic3_get_pauseparam (struct net_device *netdev, +struct ethtool_pauseparam *pause) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct hinic3_nic_pause_config nic_pause = {}; +int err; + + err =hinic3_get_pause_info (nic_dev, &nic_pause); +if (!err) { + pause->autoneg = nic_pause.auto_neg; + pause->rx_pause = nic_pause.rx_pause; + pause->tx_pause = nic_pause.tx_pause; + }else { +mutex_lock (&nic_dev->nic_cfg.cfg_mutex); + pause->autoneg = nic_dev->nic_cfg.nic_pause.auto_neg; + pause->rx_pause = nic_dev->nic_cfg.nic_pause.rx_pause; + pause->tx_pause = nic_dev->nic_cfg.nic_pause.tx_pause; +mutex_unlock (&nic_dev->nic_cfg.cfg_mutex); + } +} + +static int hinic3_set_pauseparam (struct net_device *netdev, +struct ethtool_pauseparam *pause) +{ +struct hinic3_nic_dev *nic_dev =netdev_priv (netdev); +struct hinic3_nic_pause_config nic_pause = {}; +struct hinic3_nic_pause_config cur = {}; +int err; + + nic_pause.rx_pause = !!pause->rx_pause; + nic_pause.tx_pause = !!pause->tx_pause; + +mutex_lock (&nic_dev->nic_cfg.cfg_mutex); + +if (!hinic3_get_pause_info (nic_dev, &cur)) + nic_pause.auto_neg = cur.auto_neg; +else + nic_pause.auto_neg = nic_dev->nic_cfg.nic_pause.auto_neg; +/* Pause autoneg is not user-configurable. Reject an explicit +* change instead of silently ignoring it. +*/ +if (pause->autoneg != nic_pause.auto_neg) { +mutex_unlock (&nic_dev->nic_cfg.cfg_mutex); +return -EOPNOTSUPP ; + } + + err =hinic3_set_pause_info (nic_dev, &nic_pause); +if (err) { +netdev_err_once (netdev,"Failed to set pauseparam\n" ); + }else { + nic_dev->nic_cfg.nic_pause.auto_neg = nic_pause.auto_neg; + nic_dev->nic_cfg.nic_pause.rx_pause = nic_pause.rx_pause; + nic_dev->nic_cfg.nic_pause.tx_pause = nic_pause.tx_pause; + } +mutex_unlock (&nic_dev->nic_cfg.cfg_mutex); + +return err; +} +static const struct ethtool_ops hinic3_ethtool_ops = { .supported_coalesce_params =ETHTOOL_COALESCE_USECS |ETHTOOL_COALESCE_PKT_RATE_RX_USECS ,
@@ -872,6 +931,8 @@ static const struct ethtool_ops hinic3_ethtool_ops = { .get_eth_ctrl_stats = hinic3_get_eth_ctrl_stats, .get_rmon_stats = hinic3_get_rmon_stats, .get_pause_stats = hinic3_get_pause_stats, + .get_pauseparam = hinic3_get_pauseparam, + .set_pauseparam = hinic3_set_pauseparam, };static const struct ethtool_ops hinic3vf_ethtool_ops = {
drivers/net/ethernet/huawei/hinic3/hinic3_main.c +8 -0
@@ -240,10 +240,18 @@ static int hinic3_sw_init(struct net_device *netdev)int err;mutex_init (&nic_dev->port_state_mutex); +mutex_init (&nic_dev->nic_cfg.cfg_mutex); nic_dev->q_params.sq_depth =HINIC3_SQ_DEPTH ; nic_dev->q_params.rq_depth =HINIC3_RQ_DEPTH ; +if (!HINIC3_IS_VF (hwdev)) { + err =hinic3_get_pause_info (nic_dev, + &nic_dev->nic_cfg.nic_pause); +if (err) +return err; + } +hinic3_try_to_enable_rss (netdev);if (HINIC3_IS_VF (hwdev)) {
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.c +7 -0
@@ -739,6 +739,13 @@ int hinic3_get_pause_info(struct hinic3_nic_dev *nic_dev, nic_pause); } +int hinic3_set_pause_info (struct hinic3_nic_dev *nic_dev, +struct hinic3_nic_pause_config *nic_pause) +{ +return hinic3_cfg_hw_pause (nic_dev->hwdev,MGMT_MSG_CMD_OP_SET , + nic_pause); +} +int hinic3_get_vport_stats (struct hinic3_hwdev *hwdev,u16 func_id,struct l2nic_vport_stats *stats) {
drivers/net/ethernet/huawei/hinic3/hinic3_nic_cfg.h +4 -2
@@ -268,8 +268,8 @@ struct hinic3_nic_pause_config { };struct hinic3_nic_cfg { -/* Valid when pfc is disabled */ -bool pause_set; +/* lock for getting nic cfg */ +struct mutex cfg_mutex;struct hinic3_nic_pause_config nic_pause;u8 pfc_en;
@@ -318,6 +318,8 @@ int hinic3_del_vlan(struct hinic3_hwdev *hwdev, u16 vlan_id, u16 func_id);int hinic3_get_pause_info (struct hinic3_nic_dev *nic_dev,struct hinic3_nic_pause_config *nic_pause); +int hinic3_set_pause_info (struct hinic3_nic_dev *nic_dev, +struct hinic3_nic_pause_config *nic_pause);int hinic3_get_vport_stats (struct hinic3_hwdev *hwdev,u16 func_id,struct l2nic_vport_stats *stats);
drivers/net/ethernet/huawei/hinic3/hinic3_nic_dev.h +3 -0
@@ -10,6 +10,7 @@#include "hinic3_hw_cfg.h" #include "hinic3_hwdev.h" #include "hinic3_mgmt_interface.h" +#include "hinic3_nic_cfg.h" #define HINIC3_VLAN_BITMAP_BYTE_SIZE (nic_dev) (sizeof(*(nic_dev)->vlan_bitmap))#define HINIC3_VLAN_BITMAP_SIZE (nic_dev) \
@@ -141,6 +142,8 @@ struct hinic3_nic_dev {/* flag bits defined by hinic3_event_work_flags */ unsigned long event_flag;bool link_status_up; + +struct hinic3_nic_cfg nic_cfg; };void hinic3_set_netdev_ops (struct net_device *netdev);
Signature · 1 line
2.43.0