Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3313473iob; Mon, 16 May 2022 19:04:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz09omvl80SvjFywx6CUnlbHrPUIpn2Z0Y8togGNJzj7+K68wdvuOEgCArGFS9A5rL/uD9o X-Received: by 2002:a63:2303:0:b0:3da:eae2:583a with SMTP id j3-20020a632303000000b003daeae2583amr18145943pgj.123.1652753071841; Mon, 16 May 2022 19:04:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652753071; cv=none; d=google.com; s=arc-20160816; b=JeZJTy48qRz6HaXwYWyusdash7AVlyuZcyvZGNgSMSPCVoSXEzHey5jNlf+d9Q2+VI GcadaqVTLDBMNzBZPWcsYEgcd0fluCb3ZOC1fzsqP1K1brLr2BRRuOoim49gF4S2azxT 5dVuHtoaVX5lE4r5eIWSWfj5K1hTYk+Xn3n9b+8EvAJVrIfQun1uh/EaKeVYdaHWV+Vg kK+ewuyYAFEVTtyvSmCjK6yPLZZL5CzOdHOdu/BqNBWn5Kd6E5nmx1aL9L05ekqG2Ykv eupwS4XZQp0PcYRuqa8tSFqOVJ86Ls5aCum6jggKhdtXBDv98N3EeYMEfPnxu/HvMuwU luMw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ktg0AWR5+HqZsjn/el8Ad334oA2tWQHW4Nb5Xq8ECoQ=; b=F/ViO0foWOU2ERw/sW6wD8Hdit37OquMvIPY0HR6Jd7uV12fUwa8PtN+f3SM9GoNrE Lk+cWghK7Zjjjt+q0TMgkxgK7JkpwX+wpgqS5Zz8AWjJkEf7+KIOAR/pkPpzz0CW458f rCZnAk7up0JkxrVgNjMJNy7LK5xHLNXLDYcU386f+WgpjfzptNjf42ZOliZDrx0LbkUF YBmbQ7LtOZocptW/Js+C0e3kYBXXw8yNgBOMGap5QWNUFr3YhGwV7ehTdWblb69dpuhf r+6woUYr8FuF7IU1qlbftd3RBpLTXbXkT1UXCIsbd3uJmaYreXV58bsYmYPk+FdInID1 GafA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bitwise.fi Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z19-20020a170902ee1300b0015d0d05846dsi7914687plb.430.2022.05.16.19.04.19; Mon, 16 May 2022 19:04:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bitwise.fi Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244100AbiEPNzq (ORCPT + 99 others); Mon, 16 May 2022 09:55:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242718AbiEPNyy (ORCPT ); Mon, 16 May 2022 09:54:54 -0400 Received: from mail.bitwise.fi (mail.bitwise.fi [109.204.228.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2969F273C; Mon, 16 May 2022 06:54:35 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.bitwise.fi (Postfix) with ESMTP id 1F3AC460030; Mon, 16 May 2022 16:49:05 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at Received: from mail.bitwise.fi ([127.0.0.1]) by localhost (mustetatti.dmz.bitwise.fi [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EkXywVdTKueF; Mon, 16 May 2022 16:49:02 +0300 (EEST) Received: from localhost.net (fw1.dmz.bitwise.fi [192.168.69.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: anssiha) by mail.bitwise.fi (Postfix) with ESMTPSA id 61E6E460032; Mon, 16 May 2022 16:48:57 +0300 (EEST) From: Anssi Hannula To: Jimmy Assarsson Cc: linux-can@vger.kernel.org, Marc Kleine-Budde , linux-kernel@vger.kernel.org Subject: [PATCH 11/12] can: kvaser_usb_leaf: Ignore stale bus-off after start Date: Mon, 16 May 2022 16:47:47 +0300 Message-Id: <20220516134748.3724796-12-anssi.hannula@bitwise.fi> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220516134748.3724796-1-anssi.hannula@bitwise.fi> References: <20220516134748.3724796-1-anssi.hannula@bitwise.fi> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With 0bfd:0124 Kvaser Mini PCI Express 2xHS FW 4.18.778 it was observed that if the device was bus-off when stopped, at next start (either via interface down/up or manual bus-off restart) the initial CMD_CHIP_STATE_EVENT received just after CMD_START_CHIP_REPLY will have the M16C_STATE_BUS_OFF bit still set, causing the interface to immediately go bus-off again. The bit seems to internally clear quickly afterwards but we do not get another CMD_CHIP_STATE_EVENT. Fix the issue by ignoring any initial bus-off state until we see at least one bus-on state. Also, poll the state periodically until that occurs. It is possible we lose one actual immediately occurring bus-off event here in which case the HW will auto-recover and we see the recovery event. We will then catch the next bus-off event, if any. This issue did not reproduce with 0bfd:0017 Kvaser Memorator Professional HS/HS FW 2.0.50. Fixes: 71873a9b38d1 ("can: kvaser_usb: Add support for more Kvaser Leaf v2 devices") Signed-off-by: Anssi Hannula --- .../net/can/usb/kvaser_usb/kvaser_usb_leaf.c | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c index 742626e69dd8..4125074c7066 100644 --- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c +++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c @@ -401,6 +401,9 @@ struct kvaser_usb_net_leaf_priv { struct kvaser_cmd_busparams params_response; struct delayed_work chip_state_req_work; + + /* started but not reported as bus-on yet */ + bool joining_bus; }; static const struct can_bittiming_const kvaser_usb_leaf_bittiming_const = { @@ -800,6 +803,7 @@ kvaser_usb_leaf_rx_error_update_can_state(struct kvaser_usb_net_priv *priv, const struct kvaser_usb_err_summary *es, struct can_frame *cf) { + struct kvaser_usb_net_leaf_priv *leaf = priv->sub_priv; struct kvaser_usb *dev = priv->dev; struct net_device_stats *stats = &priv->netdev->stats; enum can_state cur_state, new_state, tx_state, rx_state; @@ -824,6 +828,22 @@ kvaser_usb_leaf_rx_error_update_can_state(struct kvaser_usb_net_priv *priv, new_state = CAN_STATE_ERROR_ACTIVE; } + /* 0bfd:0124 FW 4.18.778 was observed to send the initial + * CMD_CHIP_STATE_EVENT after CMD_START_CHIP with M16C_STATE_BUS_OFF + * bit set if the channel was bus-off when it was last stopped (even + * across chip resets). This bit will clear shortly afterwards, without + * triggering a second unsolicited chip state event. + * Ignore this initial bus-off. + */ + if (leaf->joining_bus) { + if (new_state == CAN_STATE_BUS_OFF) { + netdev_dbg(priv->netdev, "ignoring bus-off during startup"); + new_state = cur_state; + } else { + leaf->joining_bus = false; + } + } + if (new_state != cur_state) { tx_state = (es->txerr >= es->rxerr) ? new_state : 0; rx_state = (es->txerr <= es->rxerr) ? new_state : 0; @@ -899,9 +919,12 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev, /* If there are errors, request status updates periodically as we do * not get automatic notifications of improved state. + * Also request updates if we saw a stale BUS_OFF during startup + * (joining_bus). */ if (new_state < CAN_STATE_BUS_OFF && - (es->rxerr || es->txerr || new_state == CAN_STATE_ERROR_PASSIVE)) + (es->rxerr || es->txerr || new_state == CAN_STATE_ERROR_PASSIVE || + leaf->joining_bus)) schedule_delayed_work(&leaf->chip_state_req_work, msecs_to_jiffies(500)); @@ -1392,8 +1415,11 @@ static int kvaser_usb_leaf_set_opt_mode(const struct kvaser_usb_net_priv *priv) static int kvaser_usb_leaf_start_chip(struct kvaser_usb_net_priv *priv) { + struct kvaser_usb_net_leaf_priv *leaf = priv->sub_priv; int err; + leaf->joining_bus = true; + reinit_completion(&priv->start_comp); err = kvaser_usb_leaf_send_simple_cmd(priv->dev, CMD_START_CHIP, @@ -1566,6 +1592,7 @@ static int kvaser_usb_leaf_set_mode(struct net_device *netdev, enum can_mode mode) { struct kvaser_usb_net_priv *priv = netdev_priv(netdev); + struct kvaser_usb_net_leaf_priv *leaf = priv->sub_priv; int err; switch (mode) { @@ -1576,6 +1603,8 @@ static int kvaser_usb_leaf_set_mode(struct net_device *netdev, kvaser_usb_unlink_tx_urbs(priv); + leaf->joining_bus = true; + err = kvaser_usb_leaf_simple_cmd_async(priv, CMD_START_CHIP); if (err) return err; -- 2.34.1