From patchwork Fri Nov 22 22:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3655 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id E56BF3F9F7 for ; Fri, 22 Nov 2024 23:17:08 +0100 (CET) Received: by mail-lf1-f72.google.com with SMTP id 2adb3069b0e04-539ebb5a10csf2225151e87.3 for ; Fri, 22 Nov 2024 14:17:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732313828; cv=pass; d=google.com; s=arc-20240605; b=QRX4GefBWc9D46XAeyWR4W+5Rx1rrNEQMlYR41MF3euITjhEiL9ZH879t9wgdayrWD AsWmxvDzVc1r1bdaSaBzVjLv4l9GH1Kr4p/IVPXilciN4Jmy0sKcjuu0Atmp8DCS+y3y bfZrlfDn1iG1SUS1mdr7qwT5mpXqfOL8tdfEvf498jPnVaFu868tfaDOE8fuZXUXEl3b S4sBNwlRaoQBcCwOOnjFS11LVr/531yeJUQjzri1VbUSQDVfu9CNGGVkhmMR5J7xtsEq 8NFO63jYNZXkZv/GPznZy4x+h3cFZwpt+iX1jxB2KLXIhD2FIGXSJgf92Yd2jm1SXKO1 c22Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=sR2WRnwgOVMBGcSPHrF4Zc8vaEiLhCWd2PYNK22GMzg=; fh=GXrkmLz+8c4TXtg418/4zvjdIHCWoOWCUDo4XPplcG8=; b=UwI48sbWC48K7LIHYtPQreAwTQlzASL1r/IKtdFRT3gCCtjzQ/OZ7YO1wuvNYEH/Vl ZwZYwPpaEpzBxDxkqNBjVWwxVn1iNBJ9GM2aOHZmOP4ksofwbKwjUahX4MXEu0a7plNF K3BJnEIduAkYAkDEGOd44At/gvp+9cuhDQDuemsLQZcH8nNxQrwYyVfEs+17KZBezNdw HtDZJp5EMrYZzuBiQAO6jyN2+XunE1NEle2ObloafKNMWGcPJy4viPLXJRWXrQtXhPzN /lWT3fJU3AiK9rL2H+GGzStUXIwTTDCA0hc8NfchPuzqS9WBe1XzincrrLgh2wsFRQRx jr8g==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cdRYU3HN; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1732313828; x=1732918628; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=sR2WRnwgOVMBGcSPHrF4Zc8vaEiLhCWd2PYNK22GMzg=; b=mF1GqKdyRrjnerFGqFU4hIvM+W1CyTS2nm+TVbc+of+AUxiT8EJHFKQ9G5uKpHcA4L 4cUFmZImp9kbO+cXCx+1bmm3b2xULCutIyWSjsn3oD7zQvgWsLr1t/22/9GEiuCTYXMq Ouk+A4OE7LOpRCxHkmQWWwQfCJGCUr1BaD8fw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732313828; x=1732918628; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sR2WRnwgOVMBGcSPHrF4Zc8vaEiLhCWd2PYNK22GMzg=; b=sEUsYVv/dxvMvVZMzCyqpemcYnB/QNGNFkNF+EX8k/wCkzBfAA1OWD7FNUFj6wDZqW fnYLWufK4w+ZScxWVXPpViWp0F9XLDE0mXYL6pzSk/76qu+KgZfYftxrWfu93IZxwVT7 eDzNLgIZwz6DrGIIc1jdbji7Pui1R1+HAZ4mDTZqCTM0TkyOIHXawme0LaWzj/3NL1vS POHpkA87EHARVUOZ+erCG9yYrvePfmYssJpycT8E3KGlw4xukoPCpxZ2rQJG8zkG9J6v zDNr7wpPwyra8zXn8dBQKnLBGsBRoCUx5QJXBfnAURLHNUMjfLFG50u23NZOvxlMV5a5 Jm6Q== X-Forwarded-Encrypted: i=2; AJvYcCWvh85eNLJXSxKjFZwK/SqRbYBV1ss+//LtiqROoXhhK26z3Ezu7QJcDpxIt1fcKHl7d5k4DFbzQFsmdpw1@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YxaXF5EydZAK0Wfk55rO65cKiqTxyvqkewK2ouw32/HdDzqNpeg veUY+dha2t5fbQgB6+1hFZSGLICkpA9JoI0d+cpfzToZ+DVNWORAeZDsDrrRun0kkg== X-Google-Smtp-Source: AGHT+IGPUouRKtBN8fsi9CFOh3JzLl9zp3xSwrp2yfB5GC7VIU3SXZBQ9/2HI/SEl8ygM3T27MVFhQ== X-Received: by 2002:a05:6512:b05:b0:53d:d246:5aca with SMTP id 2adb3069b0e04-53dd369f636mr3938074e87.24.1732313827698; Fri, 22 Nov 2024 14:17:07 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a19:9118:0:b0:53d:d0a4:8845 with SMTP id 2adb3069b0e04-53dd0a48994ls245686e87.0.-pod-prod-05-eu; Fri, 22 Nov 2024 14:17:06 -0800 (PST) X-Received: by 2002:a05:6512:281c:b0:53d:d58a:cb66 with SMTP id 2adb3069b0e04-53dd58acb88mr3540935e87.51.1732313825672; Fri, 22 Nov 2024 14:17:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732313825; cv=none; d=google.com; s=arc-20240605; b=MKCYjTj+FM8beD2Dt3ZwlnglvJZhMJw/3/k7ns8VadbaAt+UXK0uwUtjOgCGrY9iDS cRdFDdz0ydIIPcohw68M3CtkvI755I2wKmq6W0wMkRWCVc2CcM3qwPOtv85uwtKT2uTx 9jooCvpyKXu9UQI21O1VynIDQtLkEf18OvDLg6vFUtg7SHr43yMM05GjvJKb/YDq6q1+ yAB30epTvzGwuQ0eP9X2Ql/0h+ArW7h2jXMRydy5Gn7CVD3M8na3WEK53/hTcNomEM02 hjK2kU1UxNlZYAVQ6s+bPtTGA4uI/EPZu9q6J148avwDW88SZ4rJ65gtIkLADrsSSZBc rzaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=RlpDyiJR/k7vKSJ97gJNXRm8erHzYQsibasSD5BWwAI=; fh=syCFqySSLxxt8gSwWXSblJI0rPP3W7ajAR6N37oixS0=; b=JMnHxf4EIHBLxEFGJFlyD1ifx+Xa1W87pWvNDSsKi3KYUR4NGnxjYznRmMkog90mji 6gIXsn9o/8w+dWJmdbFMKMeEV9jlyZxNeqGcfXraIn5lYZmBoa15TJQylOncvwBKSZk4 aafw08gjriERc7Wa07R0RTwtZtdtN7te/tWbP5SMMi2pbgNhAlCLN2eGHW2lMS6r2qLc 73Z+uGyBD38Kyvl+DwICEfFAG+kv8Sv1+PWW6UrvodCk0hpFC+zmaUaeV0cORGdLSPIQ 8JouZ/OJzPpaFBJUb5Td1+DZXC5AkZB5DvL/wCHpd/O2qkZwhJr9f9z1OgtConGqJ5Sn ur5Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cdRYU3HN; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 2adb3069b0e04-53dd5793b2fsor776024e87.16.2024.11.22.14.17.05 for (Google Transport Security); Fri, 22 Nov 2024 14:17:05 -0800 (PST) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Gm-Gg: ASbGnctkLnN1huNlY6ljICNNc8UZMhTf3boruXOTOyGMIGi66EoGOQHfl8vTHqztcGX jTmVwEmqYB3gctmg3CuyLA7oN5PteGwx7UFFRC29LR8vM0/YyPUsj4p3twbzmO3627gRu01x4Z3 O6Fb/e4lYYeXAphkkqXp5KxG+IxHf5WAQyzmm7v2JhxrjLcX29RPBymuv2x5v5g1VIYx24rFgye LDUEe2iqbiFAPJ5ILHzkBQlx0s2S1RXNcLVlckOfzcB2S3SDNQhn2x28S2a+l9ml3XtRZtcysuv GqfMecogp/gggMttD9ldxYlX68ACH72NFHfW+x7uYbUkBgx1N8NGjApg5ct5EQwbJ5HTIPSVYzo 5pWU3wnJJUdejp/jZ X-Received: by 2002:a05:6512:304c:b0:53d:da89:a491 with SMTP id 2adb3069b0e04-53dda89a8abmr1706753e87.10.1732313825233; Fri, 22 Nov 2024 14:17:05 -0800 (PST) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-82-54-94-193.retail.telecomitalia.it. [82.54.94.193]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa50b52fcebsm148226466b.127.2024.11.22.14.17.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2024 14:17:04 -0800 (PST) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , "David S. Miller" , Marc Kleine-Budde , Oliver Hartkopp , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org Subject: [PATCH v2 09/12] can: sja1000: fix {rx,tx}_errors statistics Date: Fri, 22 Nov 2024 23:15:50 +0100 Message-ID: <20241122221650.633981-10-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122221650.633981-1-dario.binacchi@amarulasolutions.com> References: <20241122221650.633981-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=cdRYU3HN; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The sja1000_err() function only incremented the receive error counter and never the transmit error counter, even if the ECC_DIR flag reported that an error had occurred during transmission. Increment the receive/transmit error counter based on the value of the ECC_DIR flag. Fixes: 429da1cc841b ("can: Driver for the SJA1000 CAN controller") Signed-off-by: Dario Binacchi --- Changes in v2: - Update statistics even if skb allocation fails drivers/net/can/sja1000/sja1000.c | 67 ++++++++++++++++++------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c index ddb3247948ad..4d245857ef1c 100644 --- a/drivers/net/can/sja1000/sja1000.c +++ b/drivers/net/can/sja1000/sja1000.c @@ -416,8 +416,6 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) int ret = 0; skb = alloc_can_err_skb(dev, &cf); - if (skb == NULL) - return -ENOMEM; txerr = priv->read_reg(priv, SJA1000_TXERR); rxerr = priv->read_reg(priv, SJA1000_RXERR); @@ -425,8 +423,11 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) if (isrc & IRQ_DOI) { /* data overrun interrupt */ netdev_dbg(dev, "data overrun interrupt\n"); - cf->can_id |= CAN_ERR_CRTL; - cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + if (skb) { + cf->can_id |= CAN_ERR_CRTL; + cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + } + stats->rx_over_errors++; stats->rx_errors++; sja1000_write_cmdreg(priv, CMD_CDO); /* clear bit */ @@ -452,7 +453,7 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) else state = CAN_STATE_ERROR_ACTIVE; } - if (state != CAN_STATE_BUS_OFF) { + if (state != CAN_STATE_BUS_OFF && skb) { cf->can_id |= CAN_ERR_CNT; cf->data[6] = txerr; cf->data[7] = rxerr; @@ -460,33 +461,38 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) if (isrc & IRQ_BEI) { /* bus error interrupt */ priv->can.can_stats.bus_error++; - stats->rx_errors++; ecc = priv->read_reg(priv, SJA1000_ECC); + if (skb) { + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; - cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; - - /* set error type */ - switch (ecc & ECC_MASK) { - case ECC_BIT: - cf->data[2] |= CAN_ERR_PROT_BIT; - break; - case ECC_FORM: - cf->data[2] |= CAN_ERR_PROT_FORM; - break; - case ECC_STUFF: - cf->data[2] |= CAN_ERR_PROT_STUFF; - break; - default: - break; - } + /* set error type */ + switch (ecc & ECC_MASK) { + case ECC_BIT: + cf->data[2] |= CAN_ERR_PROT_BIT; + break; + case ECC_FORM: + cf->data[2] |= CAN_ERR_PROT_FORM; + break; + case ECC_STUFF: + cf->data[2] |= CAN_ERR_PROT_STUFF; + break; + default: + break; + } - /* set error location */ - cf->data[3] = ecc & ECC_SEG; + /* set error location */ + cf->data[3] = ecc & ECC_SEG; + } /* Error occurred during transmission? */ - if ((ecc & ECC_DIR) == 0) - cf->data[2] |= CAN_ERR_PROT_TX; + if ((ecc & ECC_DIR) == 0) { + stats->tx_errors++; + if (skb) + cf->data[2] |= CAN_ERR_PROT_TX; + } else { + stats->rx_errors++; + } } if (isrc & IRQ_EPI) { /* error passive interrupt */ @@ -502,8 +508,10 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) netdev_dbg(dev, "arbitration lost interrupt\n"); alc = priv->read_reg(priv, SJA1000_ALC); priv->can.can_stats.arbitration_lost++; - cf->can_id |= CAN_ERR_LOSTARB; - cf->data[0] = alc & 0x1f; + if (skb) { + cf->can_id |= CAN_ERR_LOSTARB; + cf->data[0] = alc & 0x1f; + } } if (state != priv->can.state) { @@ -516,6 +524,9 @@ static int sja1000_err(struct net_device *dev, uint8_t isrc, uint8_t status) can_bus_off(dev); } + if (!skb) + return -ENOMEM; + netif_rx(skb); return ret;