Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3849288pxb; Tue, 17 Nov 2020 05:20:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPANTeoxBTXhgZcDb+nkkiQOu7ck7lMA5gkheNGy7swQQGYnYXk5/9tcVLJ/qHnSji9dKH X-Received: by 2002:a17:906:e254:: with SMTP id gq20mr19545319ejb.520.1605619226316; Tue, 17 Nov 2020 05:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619226; cv=none; d=google.com; s=arc-20160816; b=udFz+nV8XOhGFIvYU0x3enYSqrKktaRj2fv/ZoLb6kfyAXVJuJ5LIZsGRDJut/AeQR p310BqQaoaZDDzqg46oyCuT7qGa7kXVT4XHmWBaxGtuuWQCUp7icWczunQmQX36lJsrl NOsy9MmZc1bRcr1XdmIuouvDyqkz6d/LHaanYUFWn3WamRM5D9w9FcmneVrIz1gSTDCz cA+LCSdSTrNFDec7yXU/5EDJbzWxCoDCkhGd1PBL9WFMujFwJ37QCtRLdTOB+v5iJ/4M 1QgJEjtAuU0ma6htFzc2EQk8z/ub+DEP/R8bJqhTgQ3nH+z4z0PJAU3hXe+FvFdEDRm/ nlAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4GQLC6qvAe+YSzFizQWqhyiwa3lGNiSl7fglPNouRQY=; b=nlYzgEXfBHGciXCCUCHzxsqXufAhhcqZyCwnpC/Ub+Ic5bVv6YzcCCqIGOWn+jDVFz EAB3FT99RsXgwH6ilnCEXbQS8HUCL9X3N4mxjoOMBWDAx+N1uknxXGeX/zkrraZ7TUvF 9TalRc+Nv9B/MN8kaH5Rh9XYBObSBtXgUjj2+qo3tJ9rcyydi7qXKDye2+/STkxpMVQO EoIPAzphaO5FX9Srelwt7GZCn2hCDD+CDagLvJsVvIpMfOJTZcVVvx2YXjDBbAxy5Scg 6zwOFf3XDWdngfyGRZZI5rbtH2IGsHwl1Vpn/58ceYu6yjMQ54z+BL4Jq1XHO+hVQBI1 cKNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="cI/EQ86s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si12731308ejk.374.2020.11.17.05.20.02; Tue, 17 Nov 2020 05:20:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="cI/EQ86s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730634AbgKQNSC (ORCPT + 99 others); Tue, 17 Nov 2020 08:18:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:50406 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730610AbgKQNR6 (ORCPT ); Tue, 17 Nov 2020 08:17:58 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 9FCCA21734; Tue, 17 Nov 2020 13:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619078; bh=vULpN+x4HhoxU6S42zsb0UNEQRFdyXy4G6S7tYm7b68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cI/EQ86sAzaWuNcssymTnoeuoERo2iCt3Svk03tJHS4BGj0PBVkMdOA0IDo0YVLc7 ypmqo4GFdEZqgpFhh29qFsb+gxmxrypSQiNRtVptLJOSxNKo7jvZ89wXALTUGYk/OE mVHFhX7JhkYSqKxH/AOUoMFylgv3gwHDSj2Ez9eE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Grosjean , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 4.19 021/101] can: peak_canfd: pucan_handle_can_rx(): fix echo management when loopback is on Date: Tue, 17 Nov 2020 14:04:48 +0100 Message-Id: <20201117122114.124606115@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stephane Grosjean [ Upstream commit 93ef65e5a6357cc7381f85fcec9283fe29970045 ] Echo management is driven by PUCAN_MSG_LOOPED_BACK bit, while loopback frames are identified with PUCAN_MSG_SELF_RECEIVE bit. Those bits are set for each outgoing frame written to the IP core so that a copy of each one will be placed into the rx path. Thus, - when PUCAN_MSG_LOOPED_BACK is set then the rx frame is an echo of a previously sent frame, - when PUCAN_MSG_LOOPED_BACK+PUCAN_MSG_SELF_RECEIVE are set, then the rx frame is an echo AND a loopback frame. Therefore, this frame must be put into the socket rx path too. This patch fixes how CAN frames are handled when these are sent while the can interface is configured in "loopback on" mode. Signed-off-by: Stephane Grosjean Link: https://lore.kernel.org/r/20201013153947.28012-1-s.grosjean@peak-system.com Fixes: 8ac8321e4a79 ("can: peak: add support for PEAK PCAN-PCIe FD CAN-FD boards") Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/peak_canfd/peak_canfd.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/peak_canfd/peak_canfd.c b/drivers/net/can/peak_canfd/peak_canfd.c index 5696d7e807513..4bc5d522c74bb 100644 --- a/drivers/net/can/peak_canfd/peak_canfd.c +++ b/drivers/net/can/peak_canfd/peak_canfd.c @@ -256,8 +256,7 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv, cf_len = get_can_dlc(pucan_msg_get_dlc(msg)); /* if this frame is an echo, */ - if ((rx_msg_flags & PUCAN_MSG_LOOPED_BACK) && - !(rx_msg_flags & PUCAN_MSG_SELF_RECEIVE)) { + if (rx_msg_flags & PUCAN_MSG_LOOPED_BACK) { unsigned long flags; spin_lock_irqsave(&priv->echo_lock, flags); @@ -271,7 +270,13 @@ static int pucan_handle_can_rx(struct peak_canfd_priv *priv, netif_wake_queue(priv->ndev); spin_unlock_irqrestore(&priv->echo_lock, flags); - return 0; + + /* if this frame is only an echo, stop here. Otherwise, + * continue to push this application self-received frame into + * its own rx queue. + */ + if (!(rx_msg_flags & PUCAN_MSG_SELF_RECEIVE)) + return 0; } /* otherwise, it should be pushed into rx fifo */ -- 2.27.0