Re: [PATCH v8 2/2] mctp pcc: Implement MCTP over PCC Transport

From: Adam Young
Date: Mon Dec 16 2024 - 17:29:34 EST


After looking in to the helper functions that Jeremy suggested, I cannot say for certain if there is a way to record the length errors using those function.

On 11/21/24 13:49, Joe Damato wrote:
+static void mctp_pcc_client_rx_callback(struct mbox_client *c, void *buffer)
+{
+ struct mctp_pcc_ndev *mctp_pcc_dev;
+ struct mctp_pcc_hdr mctp_pcc_hdr;
+ struct mctp_skb_cb *cb;
+ struct sk_buff *skb;
+ void *skb_buf;
+ u32 data_len;
+
+ mctp_pcc_dev = container_of(c, struct mctp_pcc_ndev, inbox.client);
+ memcpy_fromio(&mctp_pcc_hdr, mctp_pcc_dev->inbox.chan->shmem,
+ sizeof(struct mctp_pcc_hdr));
+ data_len = mctp_pcc_hdr.length + MCTP_HEADER_LENGTH;
+
+ if (data_len > mctp_pcc_dev->mdev.dev->mtu) {
+ mctp_pcc_dev->mdev.dev->stats.rx_dropped++;
I'm not an expert on rtnl stats, but maybe this should be
accounted for as rx_length_errors ?

And when rx_dropped is accounted in the stats callback it can add
rx_length_errors in as well as setting rtnl_link_stats64's
rx_length_errors?

You've probably read this already, but just in case:

https://docs.kernel.org/networking/statistics.html#struct-rtnl-link-stats64

The code will end up looking like this instead:

        dstats = this_cpu_ptr(mctp_pcc_ndev->mdev.dev->dstats);
        u64_stats_update_begin(&dstats->syncp);
        if (data_len > mctp_pcc_ndev->mdev.dev->mtu) {
                u64_stats_inc(&dstats->rx_drops);
                u64_stats_inc(&dstats->rx_drops);
                u64_stats_update_end(&dstats->syncp);
                return;
        }
        if (!skb) {
                u64_stats_inc(&dstats->rx_drops);
                u64_stats_update_end(&dstats->syncp);
                return;
        }
        u64_stats_inc(&dstats->rx_packets);
        u64_stats_add(&dstats->rx_bytes, data_len);
        u64_stats_update_end(&dstats->syncp);

And the stats function gets dropped from

static const struct net_device_ops mctp_pcc_netdev_ops = {
        .ndo_start_xmit = mctp_pcc_tx,
};

So I think it is either/or using the heplers or setting the length error.  I am leaning toward using the helper functions.