Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2543096imu; Thu, 29 Nov 2018 06:39:14 -0800 (PST) X-Google-Smtp-Source: AFSGD/XhuBLk+/LMyWdCAIrBENFWdn0pporZMNFJsiMrPCJhKvkq2WfbjYfI2WbFQ78bWzqU0Ewb X-Received: by 2002:a63:2744:: with SMTP id n65mr1452989pgn.65.1543502354898; Thu, 29 Nov 2018 06:39:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543502354; cv=none; d=google.com; s=arc-20160816; b=FQx9ntkR9axmzNHthdrWdjy7g+2+T5S0EYq76fji2pFnt6mijrgJ85GdWyI85v72hP fx9pS5rALHCOZJ4E263q0EKOc0NGdXTYoewNALbGqZTtHA2XXWT9IsvKfl4UnyTuK4k6 QFBnazaTAOQStERq0b80x8Dr3YvcZ2m4VVjLzzmVdQjO+NbgqB9Hif5MCTC6MJmKhhv6 aGkbOL1LJj/tB3hX7eJXtz6Q6j6NAx3H7oo8sXwdYN0dly1O1Lnaluo2SIS2N+jbEOSo 4WG+2lUMtyvudnLL70o/4yUM/T0Bhj44eHgMH9+OGRXEbCvcqxZ4IhaqmuVgCC16nJ6N G3ng== 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=hqU7h6ORJ4ckUt2tfCQH4lTJoMTd/ki2qv/VihOMjZk=; b=Zcxg/1mQCWmISG/B9rbdoqTCue0Y9p4gSFYv9U0hz7ewoU+M5ARLUtbLn+q29DF9MS YMA6Jpt5kmB8VyZlcAhaAAw3ZRVOCfajbLXmiceorB8h4HQjzxhpYAos6pdLi72uZZQA DuqMHevkoS8ZARdjuLjc+bDD9vyyr1wpakCfiOBLjuEoiMYeeo8vbS04aeiQbngzi/w6 zxP6W9ymuQmYhtDsXmV6o3YwMd8OYb/Cohmio3LCcR3Rc4o7cH3361KtOpLdvQIHJy+1 QEpyj2OLFbv5iRVP0v61dcphs6V7UT4NufE+9t3ijjrSc/cu79xwU4p6R/J72KOmFa4H aEUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YGx0vxVS; 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 a2si2202648pgm.154.2018.11.29.06.38.59; Thu, 29 Nov 2018 06:39:14 -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=YGx0vxVS; 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 S2388746AbeK3Bfy (ORCPT + 99 others); Thu, 29 Nov 2018 20:35:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:37956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728991AbeK3Bfx (ORCPT ); Thu, 29 Nov 2018 20:35:53 -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 B7FA42145D; Thu, 29 Nov 2018 14:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501820; bh=RheXuBgCQoLV5PH1S2X4k5fRz9tjIWgnwrIrdB+lRkI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YGx0vxVSnrZbVbc2pc92yBQ1gDq4r1/3mVxJIJ6gO+AHfxyAKDDayG6jgtOY0M8pO ox+sjJYvwnKXULXZZBLxqtoIiNIELOmtsXdJbV8ljYrU+xzsSj0D/YXCZVjlVT6jEO Y7E9UhB1iwVRLmd68pR9puW2vbNS/DBfLRaRwHuA= 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.19 053/110] can: rx-offload: introduce can_rx_offload_get_echo_skb() and can_rx_offload_queue_sorted() functions Date: Thu, 29 Nov 2018 15:12:24 +0100 Message-Id: <20181129135923.412164060@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129135921.231283053@linuxfoundation.org> References: <20181129135921.231283053@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.19-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);