Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp6140450imb; Fri, 8 Mar 2019 10:08:04 -0800 (PST) X-Google-Smtp-Source: APXvYqw79AZmBcSw4ySXVd1MFSWZc3Dn5Ydeffg+SGDO2PHms/MLd6zHA5zLAXe2ouqSQjxHKjrw X-Received: by 2002:a63:c80c:: with SMTP id z12mr17952252pgg.397.1552068484341; Fri, 08 Mar 2019 10:08:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1552068484; cv=none; d=google.com; s=arc-20160816; b=PmR0fPEEKztuPQNUbNK1UdCvsgep04OAvNaIeoTybvrUz41hGXbZpT1AiGbaBPZsPF S1aoAF5/ZhG5FjGl7KT3QpN/1U78iN0nLLP5SttU46H75ERUX49c9k+DsLs4qR019tAU zhGDcHxNi8ilETNzDv72eFmp4pnqYbFW1kMEUNlTDciU65XaDE/f/0w9dcidlgH9fIEX RAaOhkhq0s6sFZ/bTVo24NBoGqd37yB2p+hpAYYAxuNn/f20/UgatnPEKgRlimFsBnHh x7HRecp02pcWPKIrb989zJTHwsRENDhby6SCDm2JL/4OTUop/zzUkImnaD0T9xkmY9MI 0r/g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=Oo3NiIvCJirLJ7a8sje16cg2hku+k9Eii7jIsbZDGZQ=; b=rJI79nFe0vb0BkIz6kwa4N3Komh+jT3ZCI22fRpu68I9CkjvK0KnZbcwyaeV2INjg4 CMPjcuMy+C9jGmp29N1WluHcLEheYbPXG7NlHjEqA8pIbGjsum8UWVPJMuAVF3sz5HmZ 2hc4VwGR2r5xo/zq0aBjeb1d7Yuk6rBEVI5ukYJki7Mc0vV7DFCYK81YTQQY/jW2WNo9 Hv2VGrjb4acIw70shXerYdEsd3BNt5xvw+Tpv+m1y9o7GbID6Qb84qJZYW+bdAdvk6G1 MVy5Dhhl1slqGkgPSI7mzOU38sLzADO9B45NZfbMN/Y6SdZHZBiczHGgAepYAmfC7q8c aOVw== ARC-Authentication-Results: i=1; mx.google.com; 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 b79si7485410pfj.205.2019.03.08.10.07.48; Fri, 08 Mar 2019 10:08:04 -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; 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 S1727061AbfCHSGD (ORCPT + 99 others); Fri, 8 Mar 2019 13:06:03 -0500 Received: from mailproxy06.manitu.net ([217.11.48.70]:41638 "EHLO mailproxy06.manitu.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727015AbfCHSGD (ORCPT ); Fri, 8 Mar 2019 13:06:03 -0500 Received: from [10.219.4.148] (x2f7f494.dyn.telefonica.de [2.247.244.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: wg@grandegger.com) by mailproxy06.manitu.net (Postfix) with ESMTPSA id 52901582796; Fri, 8 Mar 2019 19:08:46 +0100 (CET) Subject: Re: [PATCH v7 1/4] can: m_can: Create a m_can platform framework To: Dan Murphy , mkl@pengutronix.de, davem@davemloft.net Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20190305155220.14037-1-dmurphy@ti.com> <5065d6ba-f195-a695-77b1-b837cac1a199@grandegger.com> <6016c8aa-01b6-38d5-0e1f-3a999aae6a13@ti.com> <1f6f77c6-dcf2-6212-5d4e-1eb699e603f1@grandegger.com> <1e9acd4e-97ad-1d9c-44b6-1b2d1bbe8c0e@ti.com> <2026f4ff-31de-3040-0872-5e9d01cc5aa5@grandegger.com> From: Wolfgang Grandegger Openpgp: preference=signencrypt Autocrypt: addr=wg@grandegger.com; prefer-encrypt=mutual; keydata= mQINBFtEb5MBEAC5aRjs5jLwjbOaEE6rczZSqck7B3iGK8ldrV8HGSjxb1MAf4VbvDWrzXfA phEgX3e54AnYhnKcf6BA3J9TlSDdUAW7r/ijOFl+TehMz7holgjhlDK41acJ/klwXJotIqby bWqFgFw6o7b8hfbVzPi8Pz/+WOIKaDOb1Keb989mn253RF1yFakgvoQfCyAeVcnO5kcByW17 zbTEHsSduYi0Zir26Oedb2Vtas4SovrEXVh4e2dRdbEbHlI8po3Ih117CuGIPAe2RSfZKY88 8c9m+WsJKtrIDIMY+f5kcHG5mib++u1oTg7wjfFgTr925g2WjzT63YRibW8Vazot9yXquMo2 HYQStmnN9MuAkL/jslnxhGKNwTzpXv6FD2g/9hcLfSjaaCwGzj2j2ucJglJnO1n+ibVB14l2 JLVe+IKJaE1gvm2v9HPsE+o1P4O8I9iCiAbQ6BGUszHADOg7r8CeTQ+AOCypfEZ5l1Hwa3gw V+TtqyCU70U9LA0AKaDZ02vf0hFRWeXV/ErFq878GOXbbVMZu8G5aO0EcCBC75/KQnyi0WEl KVIcyTyxKel/Ext7vUFIkiA16JNWRpS85YDfe9CoEZcZK+nUU268j6Bp5a7MYaF/dZaLT+Du hLA82ry8IkPQvyV5yV+B0PwDM/w7de8zIzMy9YBXU8KGGDmgYQARAQABtCdXb2xmZ2FuZyBH cmFuZGVnZ2VyIDx3Z0BncmFuZGVnZ2VyLmNvbT6JAj8EEwECACkFAltEb5MCGyMFCQlmAYAH CwkIBwMCAQYVCAIJCgsEFgIDAQIeAQIXgAAKCRDwuz7LbZzIUhvED/4vTUqS0c/V5a4hc5Md u/8q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agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 08.03.19 um 18:52 schrieb Dan Murphy: > On 3/8/19 11:40 AM, Wolfgang Grandegger wrote: >> Hello Dan, >> >> Am 08.03.19 um 18:25 schrieb Dan Murphy: >>> On 3/8/19 11:08 AM, Wolfgang Grandegger wrote: >>>> Hello, >>>> >>>> Am 08.03.19 um 16:48 schrieb Dan Murphy: >>>>> Wolfgang >>>>> >>>>> On 3/8/19 8:41 AM, Wolfgang Grandegger wrote: >>>>>> Hello Dan, >>>>>> >>>>>> thinking more about it... >>>>>> >>>>>> Am 08.03.19 um 14:29 schrieb Wolfgang Grandegger: >>>>>>> Hello Dan, >>>>>>> >>>>>>> Am 08.03.19 um 13:44 schrieb Dan Murphy: >>>>>>>> Wolfgang >>>>>>>> >>>>>>>> On 3/8/19 4:10 AM, Wolfgang Grandegger wrote: >>>>>>>>> Hallo Dan, >>>>>>>>> >>>>>>>>> Am 05.03.19 um 16:52 schrieb Dan Murphy: >>>>>>>>>> Create a m_can platform framework that peripherial >>>>>>>>>> devices can register to and use common code and register sets. >>>>>>>>>> The peripherial devices may provide read/write and configuration >>>>>>>>>> support of the IP. >>>>>>>>>> >>>>>>>>>> Signed-off-by: Dan Murphy >>>>>>>>>> --- >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> v7 - Fixed remaining new checkpatch issues, removed CSR setting, fixed tx hard >>>>>>>>>> start function to return tx_busy, and renamed device callbacks - https://lore.kernel.org/patchwork/patch/1047220/ >>>>>>>>>> >>>>>>>>>> v6 - Squashed platform patch to this patch for bissectablity, fixed coding style >>>>>>>>>> issues, updated Kconfig help, placed mcan reg offsets back into c file, renamed >>>>>>>>>> priv->skb to priv->tx_skb and cleared perp interrupts at ISR start - >>>>>>>>>> Patch 1 comments - https://lore.kernel.org/patchwork/patch/1042446/ >>>>>>>>>> Patch 2 comments - https://lore.kernel.org/patchwork/patch/1042442/ >>>>>>>>>> >>>>>>>>>> drivers/net/can/m_can/Kconfig | 13 +- >>>>>>>>>> drivers/net/can/m_can/Makefile | 1 + >>>>>>>>>> drivers/net/can/m_can/m_can.c | 700 +++++++++++++------------ >>>>>>>>>> drivers/net/can/m_can/m_can.h | 110 ++++ >>>>>>>>>> drivers/net/can/m_can/m_can_platform.c | 202 +++++++ >>>>>>>>>> 5 files changed, 682 insertions(+), 344 deletions(-) >>>>>>>>>> create mode 100644 drivers/net/can/m_can/m_can.h >>>>>>>>>> create mode 100644 drivers/net/can/m_can/m_can_platform.c >>>>>>>>>> >>>>>>>>>> diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig >>>>>>>>>> index 04f20dd39007..f7119fd72df4 100644 >>>>>>>>>> --- a/drivers/net/can/m_can/Kconfig >>>>>>>>>> +++ b/drivers/net/can/m_can/Kconfig >>>>>>>>>> @@ -1,5 +1,14 @@ >>>>>>>>>> config CAN_M_CAN >>>>>>>>>> + tristate "Bosch M_CAN support" >>>>>>>>>> + ---help--- >>>>>>>>>> + Say Y here if you want support for Bosch M_CAN controller framework. >>>>>>>>>> + This is common support for devices that embed the Bosch M_CAN IP. >>>>>>>>>> + >>>>>>>>>> +config CAN_M_CAN_PLATFORM >>>>>>>>>> + tristate "Bosch M_CAN support for io-mapped devices" >>>>>>>>>> depends on HAS_IOMEM >>>>>>>>>> - tristate "Bosch M_CAN devices" >>>>>>>>>> + depends on CAN_M_CAN >>>>>>>>>> ---help--- >>>>>>>>>> - Say Y here if you want to support for Bosch M_CAN controller. >>>>>>>>>> + Say Y here if you want support for IO Mapped Bosch M_CAN controller. >>>>>>>>>> + This support is for devices that have the Bosch M_CAN controller >>>>>>>>>> + IP embedded into the device and the IP is IO Mapped to the processor. >>>>>>>>>> diff --git a/drivers/net/can/m_can/Makefile b/drivers/net/can/m_can/Makefile >>>>>>>>>> index 8bbd7f24f5be..057bbcdb3c74 100644 >>>>>>>>>> --- a/drivers/net/can/m_can/Makefile >>>>>>>>>> +++ b/drivers/net/can/m_can/Makefile >>>>>>>>>> @@ -3,3 +3,4 @@ >>>>>>>>>> # >>>>>>>>>> >>>>>>>>>> obj-$(CONFIG_CAN_M_CAN) += m_can.o >>>>>>>>>> +obj-$(CONFIG_CAN_M_CAN_PLATFORM) += m_can_platform.o >>>>>>>>>> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c >>>>>>>>>> index 9b449400376b..a60278d94126 100644 >>>>>>>>>> --- a/drivers/net/can/m_can/m_can.c >>>>>>>>>> +++ b/drivers/net/can/m_can/m_can.c >>>>>>>>> >>>>>>>>> ... snip... >>>>>>>>> >>>>>>>>>> +static netdev_tx_t m_can_start_xmit(struct sk_buff *skb, >>>>>>>>>> + struct net_device *dev) >>>>>>>>>> +{ >>>>>>>>>> + struct m_can_priv *priv = netdev_priv(dev); >>>>>>>>>> + >>>>>>>>>> + if (can_dropped_invalid_skb(dev, skb)) >>>>>>>>>> + return NETDEV_TX_OK; >>>>>>>>>> + >>>>>>>>>> + if (priv->is_peripherial) { >>>>>>>>>> + if (priv->tx_skb) { >>>>>>>>>> + netdev_err(dev, "hard_xmit called while tx busy\n"); >>>>>>>>>> + return NETDEV_TX_BUSY; >>>>>>>>>> + } >>>>>>>>> >>>>>>>>> The problem with that approach is, that the upper layer will try to >>>>>>>>> resubmit the current "skb" but not the previous "tx_skb". And the >>>>>>>>> previous "tx_skb" has not been freed yet. I would just drop and free the >>>>>>>>> skb and return NETDEV_TX_OK in m_can_tx_handler() for peripheral devices >>>>>>>>> (like can_dropped_invalid_skb() does). >>>>>>>>> >>>>>>>> >>>>>>>> OK. >>>>>>>> >>>>>>>> So would this also be a bug in the hi3110 and mcp251x drivers (line 521) as well because besides checking tx_length >>>>>>>> this is how these drivers are written. >>>>>>> >>>>>>> This is different. When entering the "start_xmit" routine, the previous >>>>>>> TX is still in progress. It will (hopefully) complete soon. Therefore >>>>>>> returning NETDEV_TX_BUSY is OK. The "start_xmit" routine will be >>>>>>> recalled soon with the same "skb". That scenario should/could also not >>>>>>> happen. >>>>>> >>>>>> In principle, this also applies to the m_can peripheral devices. If >>>>>> tx_skb is not NULL, the TX is still in progress and returning >>>>>> NETDEV_TX_BUSY is just fine. >>>>>> >>>>>>> >>>>>>> In contrast, in "m_can_tx_handler()", the skb could not be handled >>>>>>> because the FIFO is full. The "start_xmit" routine for peripheral >>>>>>> devices for that skb already returned NETDEV_TX_OK. Therefore the only >>>>>>> meaningful action is to drop the skb. Also this error should not happen >>>>>>> and if, something is going really wrong. Therefore I think, a >>>>>>> WARN_ONCE() would be even more appropriate. But that should be a >>>>>>> separate patch. >>>>>> >>>>>> But that's a different issue/error. The tx_skb cannot be processed in >>>>>> "m_can_tx_handler()". Either we drop it or we re-queue it (retry later). >>>>>> >>>>> >>>>> OK I am a bit confused on this. Are you saying this is not an issue? >>>>> Or are you saying I need to check for tx_len like the other code? >>>> >>>> If you check for tx_skb in the "start_xmit" routine like the hi3110 and >>>> mcp251x, it will work the same way. But only, if the "tx_handler()" has >>>> fully processed the message. It simple means, the TX is still in >>>> progress and will complete soon. But in "m_can_tx_handler()" we return >>>> without handling the message! It will never be sent and freed. Or will >>>> the "m_can_tx_handler()" retry? >>>> >>> >>> I am not seeing where we are not handling the message in the m_can_tx_handler() >> >> static void m_can_tx_handler(struct m_can_classdev *priv) >> { >> ... >> /* Check if FIFO full */ >> if (m_can_tx_fifo_full(priv)) { >> /* This shouldn't happen */ >> netif_stop_queue(dev); >> netdev_warn(dev, >> "TX queue active although FIFO is full."); >> return; >> } >> >> We simply return here. When is the message (tx_skb) processed (sent or freed)? >> What happens with tx_skb? >> > > Are you sure you are looking at the right code? > > For patch version v7 I have the following > > /* Check if FIFO full */ > if (m_can_tx_fifo_full(cdev)) { > /* This shouldn't happen */ > netif_stop_queue(dev); > netdev_warn(dev, > "TX queue active although FIFO is full."); > return NETDEV_TX_BUSY; > } > > Which is no change from the original source code. I know, but for the peripheral devices you have: static void m_can_tx_work_queue(struct work_struct *ws) { struct m_can_priv *priv = container_of(ws, struct m_can_priv, tx_work); netdev_tx_t ret; ret = m_can_tx_handler(priv); if (ret == NETDEV_TX_OK) priv->tx_skb = NULL; } What will happen with tx_skb if NETDEV_TX_BUSY? It has not been dropped/freed yet? Wolfgang.