From patchwork Sun May 9 12:43:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 12246415 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67A35C43461 for ; Sun, 9 May 2021 12:51:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 45D80610A0 for ; Sun, 9 May 2021 12:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229753AbhEIMwg (ORCPT ); Sun, 9 May 2021 08:52:36 -0400 Received: from smtp-35.italiaonline.it ([213.209.10.35]:53149 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229675AbhEIMwd (ORCPT ); Sun, 9 May 2021 08:52:33 -0400 Received: from passgat-Modern-14-A10M.homenet.telecomitalia.it ([95.244.94.151]) by smtp-35.iol.local with ESMTPA id fim8lvyCKpK9wfimFlntVO; Sun, 09 May 2021 14:43:19 +0200 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2021; t=1620564199; bh=UhV8rqTENwuZ3s7Sy5Xkw0YwPYTFwDkCVFGaL/kQI2w=; h=From; b=rLXtuXfu3CHd35KAlnf20j/SOodPwume18srm3/j7/FvFVY0jyewEtb7i1I7WGtKB ctLrAaHBobtfeuAcZFGt2b1fAGCMZjodYTIuE+1vvgqx0M/eP5zCx6PFWz4dlB8r41 z38mpWn7gTpmlLW3YxDIwZ9z5lzRyttrdDBLKizLbqHrJWPSRLsM622tmvz1ZhGP9A qnn7xxmX7bKRdR9yIUXMQ3g66SUmtNXlR/2PzfOYShDDm8zIHwnvj9SuZ2vAGc/ji1 obNMADzk3q86yyl9EU0l4ceHD5IsQrch60myJBRWnvKiYe/d3OA2RoHsEKJZJQ34eQ +CRhgbvnpUBWA== X-CNFS-Analysis: v=2.4 cv=A9ipg4aG c=1 sm=1 tr=0 ts=6097d8e7 cx=a_exe a=ugxisoNCKEotYwafST++Mw==:117 a=ugxisoNCKEotYwafST++Mw==:17 a=G6fnrvWBiLgj45YZLGUA:9 From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Dario Binacchi , "David S. Miller" , Jakub Kicinski , Marc Kleine-Budde , Oliver Hartkopp , Tong Zhang , Vincent Mailhol , Wolfgang Grandegger , YueHaibing , Zhang Qilong , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 1/3] can: c_can: remove the rxmasked unused variable Date: Sun, 9 May 2021 14:43:07 +0200 Message-Id: <20210509124309.30024-2-dariobin@libero.it> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210509124309.30024-1-dariobin@libero.it> References: <20210509124309.30024-1-dariobin@libero.it> X-CMAE-Envelope: MS4xfLeBA7YIlgML9uS/zWAM3EWuzlbsvrGWpYBRNVYTJ50C8o7V9ZZ4dMUF17CEq4I58qOG2IvRufI7QOXChXGq67RpBO2xJ5Vf2W8ZpxPGd0v7ITpAaZAy TW5QKyzIU2+H40Oh/q6I0DAYxee3Q/w12skB+vTgsEJE6lb1btjpENqkc2tpzBPuvyM4vSqROCgJO9iS957lX+kCpCQ78SjflV0+P9KJbU/o6PrLRQGa4BRh A86S98mXDj0UytUXIeLY4VSmLc0bIW4kcRzBbC63/2l6oZ/skBqVYJwcOL67rt6kqBL20R7UqXiA7SUaQxuBMurTh5C9y6ueb/LtZa8KkDVtNHDgR4ujLvWZ 45wML/E159Buxwvl5gPzqvJnpmdxjjuqMW5kTZEg7LB8NgYnZpfdObXmCRwzgiioQP24/vuePbKTGIt6XSMH9ZFlqtXpLO50n8Td+SGRzk14S7YZe2znNZ0A zkIwFxaM/6osqJYHtexOMqAH0ibF46APal3Uv8HluNrHmy4yhIcHF0YWyvN5r6Yo6EeH55BQAHZgvAkdV4UnkJblzHFYxZc4yhfYN6WeHwYa5rgD0tv1NWyo eYtakmw/9+xFG7O+SVcFQJmQD0yLbvZ7kCG2LiXvTUzkhQ== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Initialized by c_can_chip_config() it's never used. Signed-off-by: Dario Binacchi --- drivers/net/can/c_can/c_can.c | 1 - drivers/net/can/c_can/c_can.h | 1 - 2 files changed, 2 deletions(-) diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can.c index 313793f6922d..1fa47968c2ec 100644 --- a/drivers/net/can/c_can/c_can.c +++ b/drivers/net/can/c_can/c_can.c @@ -599,7 +599,6 @@ static int c_can_chip_config(struct net_device *dev) /* Clear all internal status */ atomic_set(&priv->tx_active, 0); - priv->rxmasked = 0; priv->tx_dir = 0; /* set bittiming params */ diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h index 06045f610f0e..517845c4571e 100644 --- a/drivers/net/can/c_can/c_can.h +++ b/drivers/net/can/c_can/c_can.h @@ -205,7 +205,6 @@ struct c_can_priv { struct c_can_raminit raminit_sys; /* RAMINIT via syscon regmap */ void (*raminit)(const struct c_can_priv *priv, bool enable); u32 comm_rcv_high; - u32 rxmasked; u32 dlc[]; }; From patchwork Sun May 9 12:43:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 12246413 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D9A2C433ED for ; Sun, 9 May 2021 12:51:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2CFB36140B for ; Sun, 9 May 2021 12:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbhEIMwf (ORCPT ); Sun, 9 May 2021 08:52:35 -0400 Received: from smtp-35.italiaonline.it ([213.209.10.35]:52124 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229661AbhEIMwc (ORCPT ); Sun, 9 May 2021 08:52:32 -0400 Received: from passgat-Modern-14-A10M.homenet.telecomitalia.it ([95.244.94.151]) by smtp-35.iol.local with ESMTPA id fim8lvyCKpK9wfimGlntVh; Sun, 09 May 2021 14:43:20 +0200 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2021; t=1620564200; bh=MIC+8AvIQ/VJx/FyZwe6EZOxmjOe7sYnk6eOS8E7LDY=; h=From; b=CNn4GzKPtu6KZi8fwNyVrOz3HfJ6WlW4R2+D5ZTWG1y8ImhtsfCCfa0diJjAdc2xH zEN/hh1kNOielZeSmAjb4v4IXMN0xtZvW+R/ajezOtBxk9KWRqjnD2pvY7dmhn1Kx3 vSzizbMgRWRkJzJu5gpYjBxKN7jeLvkc9LUdXx+PhySUMg9uaUiR/JdIJdBfMOYBvQ 78EZ7G/xYV1yVlE6abEnLePNVqlhu0PjllMhOLPPQU2AxsIqHYqDGqn+Hti5Apuj2E E6/l2+b1j9wOPSXJ9T8w+gWTK8jaHbIdC/BrdoKoslXWlt82pXe/+vGcI6MwMHqiKI tdH3H/nCqVo7w== X-CNFS-Analysis: v=2.4 cv=A9ipg4aG c=1 sm=1 tr=0 ts=6097d8e8 cx=a_exe a=ugxisoNCKEotYwafST++Mw==:117 a=ugxisoNCKEotYwafST++Mw==:17 a=SGOFpciEqo9vyzegYnIA:9 a=-4wPlLVnJ--VLaRH:21 a=zBB0C0jdxDwOhFAb:21 From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Dario Binacchi , "David S. Miller" , Jakub Kicinski , Marc Kleine-Budde , Oliver Hartkopp , Tong Zhang , Vincent Mailhol , Wolfgang Grandegger , Zhang Qilong , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 2/3] can: c_can: add ethtool support Date: Sun, 9 May 2021 14:43:08 +0200 Message-Id: <20210509124309.30024-3-dariobin@libero.it> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210509124309.30024-1-dariobin@libero.it> References: <20210509124309.30024-1-dariobin@libero.it> X-CMAE-Envelope: MS4xfA0qDsJjNLWgnIKNi26fKGnMaxj6u1Cz9OWj2YYk6ar4WfzymnKgl0hOBUivPBQYf0LDW3FE995pKfX4pFi2yDXvkRmyzc/nkeoeczogcsFeubOt6ikb hF2rDcIQScqX+MHXgQYuCds51aLZ1y6kNLWuZmHi7ZrghMqnz4gW5RUd5TCQv/x8enSPnj5h7cq5p+N/ij16Rc2urTjpzrOeKXq2MkVTkqPpVyZ8iJdGYVYE 61YrJPNFGLyYmI1NSB4hOTfBcDGiIXCPAJUqCV+rtQVnu4pZYPDaPCYMMB+T3Ft54Vdpq7NlAiCv+Mhz9TMpwVnr/sE/nTDnunALbVhKFU+8pUfiGvw7OH9P 1d5Dy/mQbnVZxie6Bs2+q7vYw4KDcOuZwNiD2JNC1Vs91qDOFyDqteeFlj0DmcD1yq7+4vUqahKvU9+2yl53aRp0mcAQVUbvv4MO3pVRXtAd3bFeKAC8gUZN Cvg6udyvHRadYRKBgUOdQv5WaXzVkbzBouzo5AfCS7BDL8/StscmdSuX3d6sILIiTzdruZi7ytw4o4aaH7uGz93D6I56VcH1qMsHrcwT+ZY+7a/Pqg5lBN6h xyuCGn08RRcCJv35edJB1cZb Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org With commit 132f2d45fb23 ("can: c_can: add support to 64 message objects") the number of message objects used for reception / transmission depends on FIFO size. The ethtools API support allows you to retrieve this info. Driver info has been added too. Signed-off-by: Dario Binacchi --- drivers/net/can/c_can/Makefile | 3 ++ drivers/net/can/c_can/c_can.h | 2 + drivers/net/can/c_can/c_can_ethtool.c | 46 +++++++++++++++++++ .../net/can/c_can/{c_can.c => c_can_main.c} | 1 + 4 files changed, 52 insertions(+) create mode 100644 drivers/net/can/c_can/c_can_ethtool.c rename drivers/net/can/c_can/{c_can.c => c_can_main.c} (99%) diff --git a/drivers/net/can/c_can/Makefile b/drivers/net/can/c_can/Makefile index e6a94c948531..ac2bca39d6ff 100644 --- a/drivers/net/can/c_can/Makefile +++ b/drivers/net/can/c_can/Makefile @@ -4,5 +4,8 @@ # obj-$(CONFIG_CAN_C_CAN) += c_can.o + +c_can-objs := c_can_main.o c_can_ethtool.o + obj-$(CONFIG_CAN_C_CAN_PLATFORM) += c_can_platform.o obj-$(CONFIG_CAN_C_CAN_PCI) += c_can_pci.o diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h index 517845c4571e..4247ff80a29c 100644 --- a/drivers/net/can/c_can/c_can.h +++ b/drivers/net/can/c_can/c_can.h @@ -218,4 +218,6 @@ int c_can_power_up(struct net_device *dev); int c_can_power_down(struct net_device *dev); #endif +void c_can_set_ethtool_ops(struct net_device *dev); + #endif /* C_CAN_H */ diff --git a/drivers/net/can/c_can/c_can_ethtool.c b/drivers/net/can/c_can/c_can_ethtool.c new file mode 100644 index 000000000000..1987c78b9647 --- /dev/null +++ b/drivers/net/can/c_can/c_can_ethtool.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2021, Dario Binacchi + */ + +#include +#include +#include +#include +#include + +#include "c_can.h" + +static void c_can_get_drvinfo(struct net_device *netdev, + struct ethtool_drvinfo *info) +{ + struct c_can_priv *priv = netdev_priv(netdev); + struct platform_device *pdev = to_platform_device(priv->device); + + strscpy(info->driver, "c_can", sizeof(info->driver)); + strscpy(info->version, "1.0", sizeof(info->version)); + strscpy(info->bus_info, pdev->name, sizeof(info->bus_info)); +} + +static void c_can_get_channels(struct net_device *netdev, + struct ethtool_channels *ch) +{ + struct c_can_priv *priv = netdev_priv(netdev); + + ch->max_rx = priv->msg_obj_num; + ch->max_tx = priv->msg_obj_num; + ch->max_combined = priv->msg_obj_num; + ch->rx_count = priv->msg_obj_rx_num; + ch->tx_count = priv->msg_obj_tx_num; + ch->combined_count = priv->msg_obj_rx_num + priv->msg_obj_tx_num; +} + +static const struct ethtool_ops c_can_ethtool_ops = { + .get_drvinfo = c_can_get_drvinfo, + .get_channels = c_can_get_channels, +}; + +void c_can_set_ethtool_ops(struct net_device *netdev) +{ + netdev->ethtool_ops = &c_can_ethtool_ops; +} diff --git a/drivers/net/can/c_can/c_can.c b/drivers/net/can/c_can/c_can_main.c similarity index 99% rename from drivers/net/can/c_can/c_can.c rename to drivers/net/can/c_can/c_can_main.c index 1fa47968c2ec..7588f70ca0fe 100644 --- a/drivers/net/can/c_can/c_can.c +++ b/drivers/net/can/c_can/c_can_main.c @@ -1334,6 +1334,7 @@ int register_c_can_dev(struct net_device *dev) dev->flags |= IFF_ECHO; /* we support local echo */ dev->netdev_ops = &c_can_netdev_ops; + c_can_set_ethtool_ops(dev); err = register_candev(dev); if (!err) From patchwork Sun May 9 12:43:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 12246411 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6802EC433B4 for ; Sun, 9 May 2021 12:51:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4928A6052B for ; Sun, 9 May 2021 12:51:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbhEIMwe (ORCPT ); Sun, 9 May 2021 08:52:34 -0400 Received: from smtp-35.italiaonline.it ([213.209.10.35]:43284 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229602AbhEIMwc (ORCPT ); Sun, 9 May 2021 08:52:32 -0400 X-Greylist: delayed 489 seconds by postgrey-1.27 at vger.kernel.org; Sun, 09 May 2021 08:52:32 EDT Received: from passgat-Modern-14-A10M.homenet.telecomitalia.it ([95.244.94.151]) by smtp-35.iol.local with ESMTPA id fim8lvyCKpK9wfimGlntW1; Sun, 09 May 2021 14:43:21 +0200 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2021; t=1620564201; bh=Pe3TgqXzxqmUBar/+JHlhg4oqUjFu6tJPUM0b51ffMA=; h=From; b=nDkxPtlOUXzGH9lOpDYrIESQuuukxrTt5xnlCEG1Ftn2y1RzvmcpHyyNtiqGSjNq0 NzNiYjTc5qJZ+dqI0pKfDUxGuNUgBJKPsv1aeIRFnwB++9XzvL7UV6y0fzLs6KrVTm GnG7SGtvwshDnWsv/sjf7WhsiTAj2FpZU9T0IYE+Bpd71F6PArCSKAzKQKbbPqZX6N tEEFxnyI1WpKHA5p/c0YYMds4tNNYMB/Z/Z+/WMJDQn/7dlDJQpWVlDCvpKPqlB07m jJEFddzOUPVmcLKi4zP5TnViVkcaynqDCNcuppWZl7YDk5m9b8XkgO7DqaeWaUI+ia /vmEaoOhy2Qbw== X-CNFS-Analysis: v=2.4 cv=A9ipg4aG c=1 sm=1 tr=0 ts=6097d8e9 cx=a_exe a=ugxisoNCKEotYwafST++Mw==:117 a=ugxisoNCKEotYwafST++Mw==:17 a=WWJUMVe1kfpik6qHO5oA:9 a=ZP5WlcJ4jzxDASHk:21 a=SUjYj0xwZ59NHmbF:21 From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: Dario Binacchi , "David S. Miller" , Gianluca Falavigna , Jakub Kicinski , Marc Kleine-Budde , Oliver Hartkopp , Vincent Mailhol , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 3/3] can: c_can: cache frames to operate as a true FIFO Date: Sun, 9 May 2021 14:43:09 +0200 Message-Id: <20210509124309.30024-4-dariobin@libero.it> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210509124309.30024-1-dariobin@libero.it> References: <20210509124309.30024-1-dariobin@libero.it> X-CMAE-Envelope: MS4xfATF04/oA+Sbd+UoXu1WkXY1vwV/HmAVh2khRbjkgYUb/xv+7ye93yTImcDuBV0/rBk+ieLzMzs4Edzlv32i29GBxm8F22xTIiOoTvd4xARyske5api1 bk7h5OE/s7JP4t58QxzX/oH0+Y6FvgzB2GZk0vXbw4pGz2ghw9E4wIg+v2n2biKdJG0vSOIuNLYNB6Y98qxmtg/KULjhnUfistnytUBXcveoQo2mte18CBzP 35zJDfzAZm+XI/ZTSxM6QRfsKBBrXa/l72DEenOJFAFXqW6lv68A5xGN7wkdgnuqjPR6MGk8pQpJp+LIqVaQeAI04VD5riluKKCWrDvJwPfqpe31FmU6vImC sZirxsRaMvB27zXq2lbV4k31iIp1cWsSD7aO/+cqpdo7dDHWfXMNrZ0VV4Lsr++V2RaPotf15lgq4HiSaJh1rHDOUREIh/BTSU945NtCk5dnx1ViHtfYgdCc 1/DvQgKIKoyBqhRx98NRfFenk61s8iAkf2vM56ObS+/y3AljE//jTl0TFeraGJaObcIwtNfypsDecpIT8VCUsaaLYQ9tyKJqFwHNSw== Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org As reported by a comment in the c_can_start_xmit() this was not a FIFO. C/D_CAN controller sends out the buffers prioritized so that the lowest buffer number wins. What did c_can_start_xmit() do if it found tx_active = 0x80000000 ? It waited until the only frame of the FIFO was actually transmitted by the controller. Only one message in the FIFO but we had to wait for it to empty completely to ensure that the messages were transmitted in the order in which they were loaded. By storing the frames in the FIFO without requiring its transmission, we will be able to use the full size of the FIFO even in cases such as the one described above. The transmission interrupt will trigger their transmission only when all the messages previously loaded but stored in less priority positions of the buffers have been transmitted. Suggested-by: Gianluca Falavigna Signed-off-by: Dario Binacchi --- drivers/net/can/c_can/c_can.h | 3 ++ drivers/net/can/c_can/c_can_main.c | 63 ++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/drivers/net/can/c_can/c_can.h b/drivers/net/can/c_can/c_can.h index 4247ff80a29c..6abde6cbc0b1 100644 --- a/drivers/net/can/c_can/c_can.h +++ b/drivers/net/can/c_can/c_can.h @@ -191,6 +191,9 @@ struct c_can_priv { unsigned int msg_obj_tx_last; u32 msg_obj_rx_mask; atomic_t tx_active; + atomic_t tx_cached; + spinlock_t tx_cached_lock; + atomic_t tx_avail; atomic_t sie_pending; unsigned long tx_dir; int last_status; diff --git a/drivers/net/can/c_can/c_can_main.c b/drivers/net/can/c_can/c_can_main.c index 7588f70ca0fe..d2f44c07d47f 100644 --- a/drivers/net/can/c_can/c_can_main.c +++ b/drivers/net/can/c_can/c_can_main.c @@ -124,6 +124,9 @@ IF_COMM_TXRQST | \ IF_COMM_DATAA | IF_COMM_DATAB) +#define IF_COMM_TX_FRAME (IF_COMM_ARB | IF_COMM_CONTROL | \ + IF_COMM_DATAA | IF_COMM_DATAB) + /* For the low buffers we clear the interrupt bit, but keep newdat */ #define IF_COMM_RCV_LOW (IF_COMM_MASK | IF_COMM_ARB | \ IF_COMM_CONTROL | IF_COMM_CLR_INT_PND | \ @@ -432,19 +435,36 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb, { struct can_frame *frame = (struct can_frame *)skb->data; struct c_can_priv *priv = netdev_priv(dev); - u32 idx, obj; + u32 idx, obj, tx_active, tx_cached; if (can_dropped_invalid_skb(dev, skb)) return NETDEV_TX_OK; - /* This is not a FIFO. C/D_CAN sends out the buffers - * prioritized. The lowest buffer number wins. - */ - idx = fls(atomic_read(&priv->tx_active)); - obj = idx + priv->msg_obj_tx_first; - /* If this is the last buffer, stop the xmit queue */ - if (idx == priv->msg_obj_tx_num - 1) + if (atomic_read(&priv->tx_avail) == 0) netif_stop_queue(dev); + + tx_active = atomic_read(&priv->tx_active); + tx_cached = atomic_read(&priv->tx_cached); + idx = fls(tx_active); + if (idx > priv->msg_obj_tx_num - 1) { + idx = fls(tx_cached); + + obj = idx + priv->msg_obj_tx_first; + spin_lock_bh(&priv->tx_cached_lock); + /* prepare message object for transmission */ + c_can_setup_tx_object(dev, IF_TX, frame, idx); + /* Store the message but don't ask for its transmission */ + c_can_object_put(dev, IF_TX, obj, IF_COMM_TX_FRAME); + spin_unlock_bh(&priv->tx_cached_lock); + priv->dlc[idx] = frame->len; + can_put_echo_skb(skb, dev, idx, 0); + atomic_dec(&priv->tx_avail); + atomic_add(BIT(idx), &priv->tx_cached); + return NETDEV_TX_OK; + } + + obj = idx + priv->msg_obj_tx_first; + /* Store the message in the interface so we can call * can_put_echo_skb(). We must do this before we enable * transmit as we might race against do_tx(). @@ -453,6 +473,7 @@ static netdev_tx_t c_can_start_xmit(struct sk_buff *skb, priv->dlc[idx] = frame->len; can_put_echo_skb(skb, dev, idx, 0); + atomic_dec(&priv->tx_avail); /* Update the active bits */ atomic_add(BIT(idx), &priv->tx_active); /* Start transmission */ @@ -599,6 +620,8 @@ static int c_can_chip_config(struct net_device *dev) /* Clear all internal status */ atomic_set(&priv->tx_active, 0); + atomic_set(&priv->tx_cached, 0); + atomic_set(&priv->tx_avail, priv->msg_obj_tx_num); priv->tx_dir = 0; /* set bittiming params */ @@ -723,14 +746,31 @@ static void c_can_do_tx(struct net_device *dev) /* Clear the bits in the tx_active mask */ atomic_sub(clr, &priv->tx_active); - if (clr & BIT(priv->msg_obj_tx_num - 1)) - netif_wake_queue(dev); - if (pkts) { + atomic_add(pkts, &priv->tx_avail); + + if (netif_queue_stopped(dev)) + netif_wake_queue(dev); + stats->tx_bytes += bytes; stats->tx_packets += pkts; can_led_event(dev, CAN_LED_EVENT_TX); } + + if (atomic_read(&priv->tx_active) == 0) { + pend = atomic_read(&priv->tx_cached); + + clr = pend; + while ((idx = ffs(pend))) { + idx--; + pend &= ~(1 << idx); + + obj = idx + priv->msg_obj_tx_first; + c_can_object_put(dev, IF_TX, obj, IF_COMM_TXRQST); + } + atomic_sub(clr, &priv->tx_cached); + atomic_add(clr, &priv->tx_active); + } } /* If we have a gap in the pending bits, that means we either @@ -1193,6 +1233,7 @@ struct net_device *alloc_c_can_dev(int msg_obj_num) return NULL; priv = netdev_priv(dev); + spin_lock_init(&priv->tx_cached_lock); priv->msg_obj_num = msg_obj_num; priv->msg_obj_rx_num = msg_obj_num - msg_obj_tx_num; priv->msg_obj_rx_first = 1;