Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2554036imu; Thu, 29 Nov 2018 06:49:18 -0800 (PST) X-Google-Smtp-Source: AFSGD/WbwWZ1q9jkYkrXnZu3zqeG+LAXsR2d2YIoGJlLLDCVCMUqnBl6uvT3P3932C9JMC4XrpmI X-Received: by 2002:a63:a84a:: with SMTP id i10mr1491737pgp.263.1543502958521; Thu, 29 Nov 2018 06:49:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543502958; cv=none; d=google.com; s=arc-20160816; b=w9gKMXeq9ydYIwE4LdQkGSYjxQg/UaVFqGP3dub3q9bkfwS4j2qJuZGpMqdMCImMff 8rwqizX95A33B2votUTRqmjvHYJp6gNE7OYoy4wP+Cn4fG6C9K6kJK2uStwqeECiY6xY G7yfjjERMOYIidmgr0y4pfsRnmt3/GfBW5V58AyChCQvX5ZfsOtaNFk2kf2NVPOitELX atD6Nt9I6hb6N4DGcVASA3dbH1P3SG5mmtHT89EWYcKjRnAF2LQRrHPMRCKuSa3hHxNl wxUI38ZhRNCgUTuOvSU77vwbeBHo8SME9FUlaMHiK+khdgLf35Bxl0DqW4m/VpkN1vIx XmHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=om99E7pSTnTFVuk6OkEY0azqKznz9rWhMH+9oJKIqI8=; b=Cro2VCKn8CO7pA4wco0/U7hsRSD+6clE2PywewihpnDZyq7H3zu7YkIjFdL0W71/lM a3zdrmELm/8U2H8NtGwcE/PR63ojVvV243dSLqt2efhLuK2Y6XT8W7gDY9JYq3XjprqI AeKyR/w+gNkH53IBvLMg33uJRbn/ouJlOu4olpF/Dp5Pqqc3a6Yeqq7749ZfW3Cptfmr MQEF/TqwdWjmXxGzcCH8mdfV2zPSdYnDC6T8wfORbeYIgsj5PlsVbOkQWE3kei0urqxK BHc3aJPDO5SDBxDRlfd4mG0LP0k5CUg7TGsYbPJDX4g8jIjx0BaNOTC7GV+OXDmAGNsQ MBUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eycuF41d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a34si2048163pgb.458.2018.11.29.06.49.03; Thu, 29 Nov 2018 06:49:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eycuF41d; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733090AbeK3BbS (ORCPT + 99 others); Thu, 29 Nov 2018 20:31:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:58758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731628AbeK3BbR (ORCPT ); Thu, 29 Nov 2018 20:31:17 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9A9EE21104; Thu, 29 Nov 2018 14:25:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501545; bh=TuuS1UnbPU+SonALgnP1IVwbAIoQaFl8zCkKTmH5LOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eycuF41dG0Qz4NrQdx3/LKV8i+vqHU8jiQ/NSbgRqZGoB0Rh0bMsIgN2mJOo4RdS+ ZAJTd0PuWTr4maibFo9551QaHwdVcFmdj94oZgz5og3MO0jxARALWF/GzDQAFReoxY lQD5cNK1s9rUrufHfUreFdpmgU9yORRZZurk0ORA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksij Rempel , Marc Kleine-Budde Subject: [PATCH 4.14 040/100] can: rx-offload: introduce can_rx_offload_get_echo_skb() and can_rx_offload_queue_sorted() functions Date: Thu, 29 Nov 2018 15:12:10 +0100 Message-Id: <20181129140102.251873089@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140058.768942700@linuxfoundation.org> References: <20181129140058.768942700@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oleksij Rempel commit 55059f2b7f868cd43b3ad30e28e18347e1b46ace upstream. Current CAN framework can't guarantee proper/chronological order of RX and TX-ECHO messages. To make this possible, drivers should use this functions instead of can_get_echo_skb(). Signed-off-by: Oleksij Rempel Cc: linux-stable Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/rx-offload.c | 46 +++++++++++++++++++++++++++++++++++++++++ include/linux/can/rx-offload.h | 4 +++ 2 files changed, 50 insertions(+) --- a/drivers/net/can/rx-offload.c +++ b/drivers/net/can/rx-offload.c @@ -209,6 +209,52 @@ int can_rx_offload_irq_offload_fifo(stru } EXPORT_SYMBOL_GPL(can_rx_offload_irq_offload_fifo); +int can_rx_offload_queue_sorted(struct can_rx_offload *offload, + struct sk_buff *skb, u32 timestamp) +{ + struct can_rx_offload_cb *cb; + unsigned long flags; + + if (skb_queue_len(&offload->skb_queue) > + offload->skb_queue_len_max) + return -ENOMEM; + + cb = can_rx_offload_get_cb(skb); + cb->timestamp = timestamp; + + spin_lock_irqsave(&offload->skb_queue.lock, flags); + __skb_queue_add_sort(&offload->skb_queue, skb, can_rx_offload_compare); + spin_unlock_irqrestore(&offload->skb_queue.lock, flags); + + can_rx_offload_schedule(offload); + + return 0; +} +EXPORT_SYMBOL_GPL(can_rx_offload_queue_sorted); + +unsigned int can_rx_offload_get_echo_skb(struct can_rx_offload *offload, + unsigned int idx, u32 timestamp) +{ + struct net_device *dev = offload->dev; + struct net_device_stats *stats = &dev->stats; + struct sk_buff *skb; + u8 len; + int err; + + skb = __can_get_echo_skb(dev, idx, &len); + if (!skb) + return 0; + + err = can_rx_offload_queue_sorted(offload, skb, timestamp); + if (err) { + stats->rx_errors++; + stats->tx_fifo_errors++; + } + + return len; +} +EXPORT_SYMBOL_GPL(can_rx_offload_get_echo_skb); + int can_rx_offload_irq_queue_err_skb(struct can_rx_offload *offload, struct sk_buff *skb) { if (skb_queue_len(&offload->skb_queue) > --- a/include/linux/can/rx-offload.h +++ b/include/linux/can/rx-offload.h @@ -41,6 +41,10 @@ int can_rx_offload_add_timestamp(struct int can_rx_offload_add_fifo(struct net_device *dev, struct can_rx_offload *offload, unsigned int weight); int can_rx_offload_irq_offload_timestamp(struct can_rx_offload *offload, u64 reg); int can_rx_offload_irq_offload_fifo(struct can_rx_offload *offload); +int can_rx_offload_queue_sorted(struct can_rx_offload *offload, + struct sk_buff *skb, u32 timestamp); +unsigned int can_rx_offload_get_echo_skb(struct can_rx_offload *offload, + unsigned int idx, u32 timestamp); int can_rx_offload_irq_queue_err_skb(struct can_rx_offload *offload, struct sk_buff *skb); void can_rx_offload_reset(struct can_rx_offload *offload); void can_rx_offload_del(struct can_rx_offload *offload);