can: flexcan: change RX-FIFO feature at runtime
Marc Kleine-Budde
maintainerPATCH v2 1/3 can: flexcan: change RX-FIFO feature at runtime
Hello,
this picks up Dario's work.
Changes since RFC:
- move driver into subdir
- rename flexcan_main.c -> flexcan-core.c
(mcp251xfd and tcan4x5x driver have the same naming scheme)
- use copyright notice from flexcan.c in flexcan.h
- add private flag support to set rx-fifo
- remove drvinfo, the kernel will fall back to the default implementation
Show available private flags:
| $ sudo ethtool --show-priv-flags can0 | Private flags for can0: | rx-fifo: on
Change private flag:
| $ sudo ethtool --set-priv-flags can0 rx-fifo off | netlink error: Device or resource busy
...does not work if interface is up.
Shut down interface and change "rx-fifo":
| $ sudo ip link set dev can0 down | $ sudo ethtool --set-priv-flags can0 rx-fifo off | $ sudo ethtool --show-priv-flags can0 | Private flags for can0: | rx-fifo: off | | $ sudo ip link set dev can0 up | $ sudo ethtool --show-priv-flags can0 | Private flags for can0: | rx-fifo: off
Is the name "rx-fifo" acceptable? Can you think of a better name?
What about adding a new quirk to the driver, only if that quirk is that, it is allowed to change between rx-fifo and rx-mailbox mode?
What to you think?
regards,
Marc
Marc Kleine-Budde
maintainerPATCH v2 1/3 can: flexcan: move driver into separate sub directory
This patch moves the flexcan driver into a separate directory, a later patch will add more files.
---
drivers/net/can/Makefile | 2 +-
drivers/net/can/flexcan/Makefile | 6 ++++++
drivers/net/can/{flexcan.c => flexcan/flexcan-core.c} | 0
3 files changed, 7 insertions(+), 1 deletion(-)
create mode 100644 drivers/net/can/flexcan/Makefile
rename drivers/net/can/{flexcan.c => flexcan/flexcan-core.c} (100%)drivers/net/can/Makefile +1 -1
@@ -16,7 +16,7 @@ obj-y += softing/ obj-$(CONFIG_CAN_AT91) += at91_can.o obj-$(CONFIG_CAN_CC770) += cc770/ obj-$(CONFIG_CAN_C_CAN) += c_can/ -obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o +obj-$(CONFIG_CAN_FLEXCAN) += flexcan/ obj-$(CONFIG_CAN_GRCAN) += grcan.o obj-$(CONFIG_CAN_IFI_CANFD) += ifi_canfd/ obj-$(CONFIG_CAN_JANZ_ICAN3) += janz-ican3.o
drivers/net/can/flexcan/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o + +flexcan-objs := +flexcan-objs += flexcan-core.o
drivers/net/can/flexcan/flexcan-core.c renamed from drivers/net/can/flexcan.c +0 -0
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH v2 2/3 can: flexcan: allow to change quirks at runtime
In reply to Marc Kleine-BuddeFrom: Dario Binacchi <[email protected]>
This is a preliminary patch for the upcoming support to ethtool api.
--- drivers/net/can/flexcan/flexcan-core.c | 54 +++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-)
drivers/net/can/flexcan/flexcan-core.c +27 -27
@@ -369,7 +369,7 @@ struct flexcan_priv {struct clk *clk_ipg;struct clk *clk_per; -const struct flexcan_devtype_data *devtype_data; +struct flexcan_devtype_data devtype_data;struct regulator *reg_xceiver;struct flexcan_stop_mode stm;
@@ -600,7 +600,7 @@ static inline int flexcan_enter_stop_mode(struct flexcan_priv *priv) priv->write (reg_mcr, ®s->mcr);/* enable stop request */ -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW ) { ret =flexcan_stop_mode_enable_scfw (priv, true);if (ret <0 )return ret;
@@ -619,7 +619,7 @@ static inline int flexcan_exit_stop_mode(struct flexcan_priv *priv)int ret;/* remove stop request */ -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW ) { ret =flexcan_stop_mode_enable_scfw (priv, false);if (ret <0 )return ret;
@@ -1022,7 +1022,7 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload, mb =flexcan_get_mb (priv, n); -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) {u32 code; do {
@@ -1087,7 +1087,7 @@ static struct sk_buff *flexcan_mailbox_read(struct can_rx_offload *offload, } mark_as_read: -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP )flexcan_write64 (priv,FLEXCAN_IFLAG_MB (n), ®s->iflag1);else priv->write (FLEXCAN_IFLAG_RX_FIFO_AVAILABLE , ®s->iflag1);
@@ -1113,7 +1113,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)enum can_state last_state = priv->can.state;/* reception interrupt */ -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) {u64 reg_iflag_rx;int ret;
@@ -1173,7 +1173,7 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)/* state change interrupt or broken error state quirk fix is enabled */ if ((reg_esr &FLEXCAN_ESR_ERR_STATE ) || - (priv->devtype_data->quirks & (FLEXCAN_QUIRK_BROKEN_WERR_STATE | + (priv->devtype_data.quirks & (FLEXCAN_QUIRK_BROKEN_WERR_STATE |FLEXCAN_QUIRK_BROKEN_PERR_STATE )))flexcan_irq_state (dev, reg_esr);
@@ -1195,11 +1195,11 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)* (1): enabled if FLEXCAN_QUIRK_BROKEN_WERR_STATE is enabled */ if ((last_state != priv->can.state) && - (priv->devtype_data->quirks &FLEXCAN_QUIRK_BROKEN_PERR_STATE ) && + (priv->devtype_data.quirks &FLEXCAN_QUIRK_BROKEN_PERR_STATE ) && !(priv->can.ctrlmode &CAN_CTRLMODE_BERR_REPORTING )) {switch (priv->can.state) {case CAN_STATE_ERROR_ACTIVE : -if (priv->devtype_data->quirks & +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_BROKEN_WERR_STATE )flexcan_error_irq_enable (priv);else
@@ -1423,13 +1423,13 @@ static int flexcan_rx_offload_setup(struct net_device *dev)else priv->mb_size =sizeof (struct flexcan_mb ) +CAN_MAX_DLEN ; -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_NR_MB_16 ) +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_NR_MB_16 ) priv->mb_count =16 ;else priv->mb_count = (sizeof (priv->regs->mb[0 ]) / priv->mb_size) + (sizeof (priv->regs->mb[1 ]) / priv->mb_size); -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) priv->tx_mb_reserved =flexcan_get_mb (priv,FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP );else
@@ -1441,7 +1441,7 @@ static int flexcan_rx_offload_setup(struct net_device *dev) priv->offload.mailbox_read = flexcan_mailbox_read; -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) { priv->offload.mb_first =FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST ; priv->offload.mb_last = priv->mb_count -2 ;
@@ -1506,7 +1506,7 @@ static int flexcan_chip_start(struct net_device *dev)if (err) goto out_chip_disable; -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SUPPORT_ECC ) +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_SUPPORT_ECC )flexcan_ram_init (dev);flexcan_set_bittiming (dev);
@@ -1535,7 +1535,7 @@ static int flexcan_chip_start(struct net_device *dev)* - disable for timestamp mode * - enable for FIFO mode */ -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) reg_mcr &= ~FLEXCAN_MCR_FEN ;else reg_mcr |=FLEXCAN_MCR_FEN ;
@@ -1586,7 +1586,7 @@ static int flexcan_chip_start(struct net_device *dev)* on most Flexcan cores, too. Otherwise we don't get * any error warning or passive interrupts. */ -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_BROKEN_WERR_STATE || +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_BROKEN_WERR_STATE || priv->can.ctrlmode &CAN_CTRLMODE_BERR_REPORTING ) reg_ctrl |=FLEXCAN_CTRL_ERR_MSK ;else
@@ -1599,7 +1599,7 @@ static int flexcan_chip_start(struct net_device *dev)netdev_dbg (dev,"%s: writing ctrl=0x%08x" , __func__, reg_ctrl); priv->write (reg_ctrl, ®s->ctrl); -if ((priv->devtype_data->quirks &FLEXCAN_QUIRK_ENABLE_EACEN_RRS )) { +if ((priv->devtype_data.quirks &FLEXCAN_QUIRK_ENABLE_EACEN_RRS )) { reg_ctrl2 = priv->read (®s->ctrl2); reg_ctrl2 |=FLEXCAN_CTRL2_EACEN |FLEXCAN_CTRL2_RRS ; priv->write (reg_ctrl2, ®s->ctrl2);
@@ -1631,7 +1631,7 @@ static int flexcan_chip_start(struct net_device *dev) priv->write (reg_fdctrl, ®s->fdctrl); } -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ) {for (i = priv->offload.mb_first; i <= priv->offload.mb_last; i++) { mb =flexcan_get_mb (priv, i); priv->write(FLEXCAN_MB_CODE_RX_EMPTY,
@@ -1659,7 +1659,7 @@ static int flexcan_chip_start(struct net_device *dev) priv->write (0x0 , ®s->rx14mask); priv->write (0x0 , ®s->rx15mask); -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_DISABLE_RXFG ) +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_DISABLE_RXFG ) priv->write (0x0 , ®s->rxfgmask);/* clear acceptance filters */
@@ -1673,7 +1673,7 @@ static int flexcan_chip_start(struct net_device *dev)* This also works around errata e5295 which generates false * positive memory errors and put the device in freeze mode. */ -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_DISABLE_MECR ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_DISABLE_MECR ) {/* Follow the protocol as described in "Detection * and Correction of Memory Errors" to write to * MECR register (step 1 - 5)
@@ -1799,7 +1799,7 @@ static int flexcan_open(struct net_device *dev)if (err) goto out_can_rx_offload_disable; -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_NR_IRQ_3 ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_NR_IRQ_3 ) { err =request_irq (priv->irq_boff, flexcan_irq,IRQF_SHARED , dev->name, dev);if (err)
@@ -1845,7 +1845,7 @@ static int flexcan_close(struct net_device *dev)netif_stop_queue (dev);flexcan_chip_interrupts_disable (dev); -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_NR_IRQ_3 ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_NR_IRQ_3 ) {free_irq (priv->irq_err, dev);free_irq (priv->irq_boff, dev); }
@@ -2051,9 +2051,9 @@ static int flexcan_setup_stop_mode(struct platform_device *pdev) priv =netdev_priv (dev); -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW ) +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW ) ret =flexcan_setup_stop_mode_scfw (pdev); -else if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR ) +else if (priv->devtype_data.quirks &FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR ) ret =flexcan_setup_stop_mode_gpr (pdev);else /* return 0 directly if doesn't support stop mode feature */
@@ -2181,9 +2181,10 @@ static int flexcan_probe(struct platform_device *pdev) dev->flags |=IFF_ECHO ; priv =netdev_priv (dev); + priv->devtype_data = *devtype_data;if (of_property_read_bool (pdev->dev.of_node,"big-endian" ) || - devtype_data->quirks &FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN ) { + priv->devtype_data.quirks &FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN ) { priv->read = flexcan_read_be; priv->write = flexcan_write_be; }else {
@@ -2202,10 +2203,9 @@ static int flexcan_probe(struct platform_device *pdev) priv->clk_ipg = clk_ipg; priv->clk_per = clk_per; priv->clk_src = clk_src; - priv->devtype_data = devtype_data; priv->reg_xceiver = reg_xceiver; -if (devtype_data->quirks &FLEXCAN_QUIRK_NR_IRQ_3 ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_NR_IRQ_3 ) { priv->irq_boff =platform_get_irq (pdev,1 );if (priv->irq_boff <=0 ) { err = -ENODEV ;
@@ -2218,7 +2218,7 @@ static int flexcan_probe(struct platform_device *pdev) } } -if (priv->devtype_data->quirks &FLEXCAN_QUIRK_SUPPORT_FD ) { +if (priv->devtype_data.quirks &FLEXCAN_QUIRK_SUPPORT_FD ) { priv->can.ctrlmode_supported |=CAN_CTRLMODE_FD |CAN_CTRLMODE_FD_NON_ISO ; priv->can.bittiming_const = &flexcan_fd_bittiming_const;
Signature · 1 line
2.34.1
Marc Kleine-Budde
maintainerPATCH v2 3/3 can: flexcan: add ethtool support to change rx-fifo setting during runtime
In reply to Marc Kleine-BuddeThis patch adds a private flag to the flexcan driver to switch the "rx-fifo" setting on and off.
"rx-fifo" on - the RX FIFO with a depth of 6 CAN frames is used for RX "rx-fifo" off - the mailboxes are used for RX, the number of mailboxes
depends on the actual flexcan IP core revision and if CAN-FD mode is active or not.
--- drivers/net/can/flexcan/Makefile | 1 + drivers/net/can/flexcan/flexcan-core.c | 96 +----------------- drivers/net/can/flexcan/flexcan-ethtool.c | 81 ++++++++++++++++ drivers/net/can/flexcan/flexcan.h | 113 ++++++++++++++++++++++ 4 files changed, 198 insertions(+), 93 deletions(-) create mode 100644 drivers/net/can/flexcan/flexcan-ethtool.c create mode 100644 drivers/net/can/flexcan/flexcan.h
drivers/net/can/flexcan/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o flexcan-objs := flexcan-objs += flexcan-core.o +flexcan-objs += flexcan-ethtool.o
drivers/net/can/flexcan/flexcan-core.c +3 -93
126 lines not on this page · raw message
drivers/net/can/flexcan/flexcan-ethtool.c new file +81 -0
81 lines not on this page · raw message
drivers/net/can/flexcan/flexcan.h new file +113 -0
113 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 3/3] can: flexcan: add ethtool support to change rx-fifo setting during runtime
Hi Marc,
reply all and in plain-text,
Quoted 205 lines · Marc Kleine-Budde
This patch adds a private flag to the flexcan driver to switch the "rx-fifo" setting on and off.
"rx-fifo" on - the RX FIFO with a depth of 6 CAN frames is used for RX "rx-fifo" off - the mailboxes are used for RX, the number of mailboxes
depends on the actual flexcan IP core revision and if CAN-FD mode is active or not.Signed-off-by Dario Binacchi <[email protected]>Co-developed-by Dario Binacchi <[email protected]>Signed-off-by Marc Kleine-Budde <[email protected]>--- drivers/net/can/flexcan/Makefile | 1 + drivers/net/can/flexcan/flexcan-core.c | 96 +----------------- drivers/net/can/flexcan/flexcan-ethtool.c | 81 ++++++++++++++++ drivers/net/can/flexcan/flexcan.h | 113 ++++++++++++++++++++++ 4 files changed, 198 insertions(+), 93 deletions(-) create mode 100644 drivers/net/can/flexcan/flexcan-ethtool.c create mode 100644 drivers/net/can/flexcan/flexcan.hdrivers/net/can/flexcan/Makefile +1
-0@@ -4,3 +4,4 @@ obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o flexcan-objs := flexcan-objs += flexcan-core.o +flexcan-objs += flexcan-ethtool.odrivers/net/can/flexcan/flexcan-core.c +3
-93@@ -15,7 +15,6 @@#include <linux/can/dev.h> #include <linux/can/error.h> #include <linux/can/led.h> -#include <linux/can/rx-offload.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/firmware/imx/sci.h> @@ -33,6 +32,8 @@#include <linux/regmap.h> #include <linux/regulator/consumer.h> +#include "flexcan.h" +#define DRV_NAME "flexcan"/* 8 for RX fifo and 2 error handling */ @@ -206,53 +207,6 @@#define FLEXCAN_TIMEOUT_US (250) -/* FLEXCAN hardware feature flags -* -* Below is some version info we got: -* SOC Version IP-Version Glitch- [TR]WRN_INT IRQ Err Memory err RTR rece- FD Mode MB -* Filter? connected? Passive detection ption in MB Supported? -* MCF5441X FlexCAN2 ? no yes no no yes no 16 -* MX25 FlexCAN2 03.00.00.00 no no no no no no 64 -* MX28 FlexCAN2 03.00.04.00 yes yes no no no no 64 -* MX35 FlexCAN2 03.00.00.00 no no no no no no 64 -* MX53 FlexCAN2 03.00.00.00 yes no no no no no 64 -* MX6s FlexCAN3 10.00.12.00 yes yes no no yes no 64 -* MX8QM FlexCAN3 03.00.23.00 yes yes no no yes yes 64 -* MX8MP FlexCAN3 03.00.17.01 yes yes no yes yes yes 64 -* VF610 FlexCAN3 ? no yes no yes yes? no 64 -* LS1021A FlexCAN2 03.00.04.00 no yes no no yes no 64 -* LX2160A FlexCAN3 03.00.23.00 no yes no yes yes yes 64 -* -* Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected. -*/ - -/* [TR]WRN_INT not connected */ -#define FLEXCAN_QUIRK_BROKEN_WERR_STATE BIT(1) -/* Disable RX FIFO Global mask */ -#define FLEXCAN_QUIRK_DISABLE_RXFG BIT(2) -/* Enable EACEN and RRS bit in ctrl2 */ -#define FLEXCAN_QUIRK_ENABLE_EACEN_RRS BIT(3) -/* Disable non-correctable errors interrupt and freeze mode */ -#define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) -/* Use timestamp based offloading */ -#define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP BIT(5) -/* No interrupt for error passive */ -#define FLEXCAN_QUIRK_BROKEN_PERR_STATE BIT(6) -/* default to BE register access */ -#define FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN BIT(7) -/* Setup stop mode with GPR to support wakeup */ -#define FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR BIT(8) -/* Support CAN-FD mode */ -#define FLEXCAN_QUIRK_SUPPORT_FD BIT(9) -/* support memory detection and correction */ -#define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10) -/* Setup stop mode with SCU firmware to support wakeup */ -#define FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW BIT(11) -/* Setup 3 separate interrupts, main, boff and err */ -#define FLEXCAN_QUIRK_NR_IRQ_3 BIT(12) -/* Setup 16 mailboxes */ -#define FLEXCAN_QUIRK_NR_MB_16 BIT(13) -/* Structure of the message buffer */ struct flexcan_mb {u32 can_ctrl;@@ -339,51 +293,6 @@ struct flexcan_regs {static_assert (sizeof (struct flexcan_regs ) ==0x4 *18 +0xfb8 ); -struct flexcan_devtype_data { -u32 quirks;/* quirks needed for different IP cores */ -}; - -struct flexcan_stop_mode { -struct regmap *gpr; -u8 req_gpr; -u8 req_bit; -}; - -struct flexcan_priv { -struct can_priv can; -struct can_rx_offload offload; -struct device *dev; - -struct flexcan_regs __iomem *regs; -struct flexcan_mb __iomem *tx_mb; -struct flexcan_mb __iomem *tx_mb_reserved; -u8 tx_mb_idx; -u8 mb_count; -u8 mb_size; -u8 clk_src;/* clock source of CAN Protocol Engine */ -u8 scu_idx; - -u64 rx_mask; -u64 tx_mask; -u32 reg_ctrl_default; - -struct clk *clk_ipg; -struct clk *clk_per; -struct flexcan_devtype_data devtype_data; -struct regulator *reg_xceiver; -struct flexcan_stop_mode stm; - -int irq_boff; -int irq_err; - -/* IPC handle when setup stop mode by System Controller firmware(scfw) */ -struct imx_sc_ipc *sc_ipc_handle; - -/* Read and Write APIs */ -u32 (*read)(void __iomem *addr); -void (*write)(u32 val,void __iomem *addr); -}; -static const struct flexcan_devtype_data fsl_mcf5441x_devtype_data = { .quirks =FLEXCAN_QUIRK_BROKEN_PERR_STATE |FLEXCAN_QUIRK_NR_IRQ_3 |FLEXCAN_QUIRK_NR_MB_16 ,@@ -2177,6 +2086,7 @@ static int flexcan_probe(struct platform_device *pdev)SET_NETDEV_DEV (dev, &pdev->dev); dev->netdev_ops = &flexcan_netdev_ops; +flexcan_set_ethtool_ops (dev); dev->irq = irq; dev->flags |=IFF_ECHO ;drivers/net/can/flexcan/flexcan-ethtool.c new file +34
-0@@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (c) 2022 Amarula Solutions, Dario Binacchi <[email protected]> +* Copyright (c) 2022 Pengutronix, Marc Kleine-Budde <[email protected]> +* +*/ + +#include <linux/ethtool.h> +#include <linux/kernel.h> +#include <linux/platform_device.h> +#include <linux/netdevice.h> +#include <linux/can/dev.h> + +#include "flexcan.h" + +static const char flexcan_priv_flags_strings[][ETH_GSTRING_LEN ] = { +#define FLEXCAN_PRIV_FLAGS_RX_FIFO BIT(0) +"rx-fifo" , +}; + +static void +flexcan_get_strings (struct net_device *ndev,u32 stringset,u8 *data) +{ +switch (stringset) { +case ETH_SS_PRIV_FLAGS : +memcpy (data, flexcan_priv_flags_strings, +sizeof (flexcan_priv_flags_strings)); + } +} + +static int flexcan_get_sset_count (struct net_device *netdev,int sset) +{ +switch (sset) { +case ETH_SS_PRIV_FLAGS : +return ARRAY_SIZE (flexcan_priv_flags_strings);
drivers/net/can/flexcan/flexcan-ethtool.c line 44
Quoted 10 lines
drivers/net/can/flexcan/flexcan-ethtool.c new file +10
-0+default : +return -EOPNOTSUPP ; + } +} + +static u32 flexcan_get_priv_flags (struct net_device *ndev) +{ +const struct flexcan_priv *priv =netdev_priv (ndev); +const u32 quirks = priv->devtype_data.quirks; +u32 priv_flags;
u32 priv_flags = 0;
regards,
Dario
Quoted 160 lines
drivers/net/can/flexcan/flexcan-ethtool.c new file +37
-0+ +if (!(quirks &FLEXCAN_QUIRK_USE_OFF_TIMESTAMP )) + priv_flags |=FLEXCAN_PRIV_FLAGS_RX_FIFO ; + +return priv_flags; +} + +static int flexcan_set_priv_flags (struct net_device *ndev,u32 priv_flags) +{ +struct flexcan_priv *priv =netdev_priv (ndev); +u32 quirks = priv->devtype_data.quirks; + + quirks &= ~FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ; +if (!(priv_flags &FLEXCAN_PRIV_FLAGS_RX_FIFO )) + quirks |=FLEXCAN_QUIRK_USE_OFF_TIMESTAMP ; + +if (quirks != priv->devtype_data.quirks && +netif_running (ndev)) { +return -EBUSY ; + } + + priv->devtype_data.quirks = quirks; + +return 0 ; +} + +static const struct ethtool_ops flexcan_ethtool_ops = { + .get_sset_count = flexcan_get_sset_count, + .get_strings = flexcan_get_strings, + .get_priv_flags = flexcan_get_priv_flags, + .set_priv_flags = flexcan_set_priv_flags, +}; + +void flexcan_set_ethtool_ops (struct net_device *netdev) +{ + netdev->ethtool_ops = &flexcan_ethtool_ops; +}drivers/net/can/flexcan/flexcan.h new file +113
-1@@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0 +* flexcan.c - FLEXCAN CAN controller driver +* +* Copyright (c) 2005-2006 Varma Electronics Oy +* Copyright (c) 2009 Sascha Hauer, Pengutronix +* Copyright (c) 2010-2017 Pengutronix, Marc Kleine-Budde <[email protected]> +* Copyright (c) 2014 David Jander, Protonic Holland +* Copyright (C) 2022 Amarula Solutions, Dario Binacchi <[email protected]> +* +* Based on code originally by Andrey Volkov <[email protected]> +* +*/ + +#ifndef _FLEXCAN_H +#define _FLEXCAN_H + +#include <linux/can/rx-offload.h> + +/* FLEXCAN hardware feature flags +* +* Below is some version info we got: +* SOC Version IP-Version Glitch- [TR]WRN_INT IRQ Err Memory err RTR rece- FD Mode MB +* Filter? connected? Passive detection ption in MB Supported? +* MCF5441X FlexCAN2 ? no yes no no yes no 16 +* MX25 FlexCAN2 03.00.00.00 no no no no no no 64 +* MX28 FlexCAN2 03.00.04.00 yes yes no no no no 64 +* MX35 FlexCAN2 03.00.00.00 no no no no no no 64 +* MX53 FlexCAN2 03.00.00.00 yes no no no no no 64 +* MX6s FlexCAN3 10.00.12.00 yes yes no no yes no 64 +* MX8QM FlexCAN3 03.00.23.00 yes yes no no yes yes 64 +* MX8MP FlexCAN3 03.00.17.01 yes yes no yes yes yes 64 +* VF610 FlexCAN3 ? no yes no yes yes? no 64 +* LS1021A FlexCAN2 03.00.04.00 no yes no no yes no 64 +* LX2160A FlexCAN3 03.00.23.00 no yes no yes yes yes 64 +* +* Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected. +*/ + +/* [TR]WRN_INT not connected */ +#define FLEXCAN_QUIRK_BROKEN_WERR_STATE BIT(1) +/* Disable RX FIFO Global mask */ +#define FLEXCAN_QUIRK_DISABLE_RXFG BIT(2) +/* Enable EACEN and RRS bit in ctrl2 */ +#define FLEXCAN_QUIRK_ENABLE_EACEN_RRS BIT(3) +/* Disable non-correctable errors interrupt and freeze mode */ +#define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) +/* Use timestamp based offloading */ +#define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP BIT(5) +/* No interrupt for error passive */ +#define FLEXCAN_QUIRK_BROKEN_PERR_STATE BIT(6) +/* default to BE register access */ +#define FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN BIT(7) +/* Setup stop mode with GPR to support wakeup */ +#define FLEXCAN_QUIRK_SETUP_STOP_MODE_GPR BIT(8) +/* Support CAN-FD mode */ +#define FLEXCAN_QUIRK_SUPPORT_FD BIT(9) +/* support memory detection and correction */ +#define FLEXCAN_QUIRK_SUPPORT_ECC BIT(10) +/* Setup stop mode with SCU firmware to support wakeup */ +#define FLEXCAN_QUIRK_SETUP_STOP_MODE_SCFW BIT(11) +/* Setup 3 separate interrupts, main, boff and err */ +#define FLEXCAN_QUIRK_NR_IRQ_3 BIT(12) +/* Setup 16 mailboxes */ +#define FLEXCAN_QUIRK_NR_MB_16 BIT(13) + +struct flexcan_devtype_data { +u32 quirks;/* quirks needed for different IP cores */ +}; + +struct flexcan_stop_mode { +struct regmap *gpr; +u8 req_gpr; +u8 req_bit; +}; + +struct flexcan_priv { +struct can_priv can; +struct can_rx_offload offload; +struct device *dev; + +struct flexcan_regs __iomem *regs; +struct flexcan_mb __iomem *tx_mb; +struct flexcan_mb __iomem *tx_mb_reserved; +u8 tx_mb_idx; +u8 mb_count; +u8 mb_size; +u8 clk_src;/* clock source of CAN Protocol Engine */ +u8 scu_idx; + +u64 rx_mask; +u64 tx_mask; +u32 reg_ctrl_default; + +struct clk *clk_ipg; +struct clk *clk_per; +struct flexcan_devtype_data devtype_data; +struct regulator *reg_xceiver; +struct flexcan_stop_mode stm; + +int irq_boff; +int irq_err; + +/* IPC handle when setup stop mode by System Controller firmware(scfw) */ +struct imx_sc_ipc *sc_ipc_handle; + +/* Read and Write APIs */ +u32 (*read)(void __iomem *addr); +void (*write)(u32 val,void __iomem *addr); +}; + +void flexcan_set_ethtool_ops (struct net_device *dev); + +#endif /* _FLEXCAN_H */ --2.34.1
Signature · 17 lines
Dario Binacchi Embedded Linux Developer [email protected] __________________________________ Amarula Solutions SRL Via Le Canevare 30, 31100 Treviso, Veneto, IT T. +39 042 243 5310 [email protected] www.amarulasolutions.com
Marc Kleine-Budde
maintainerRe: [PATCH v2 3/3] can: flexcan: add ethtool support to change rx-fifo setting during runtime
Quoted 7 lines · Dario Binacchi
drivers/net/can/flexcan/flexcan-ethtool.c line 44
Quoted 5 lines
drivers/net/can/flexcan/flexcan-ethtool.c new file +5
-0+static u32 flexcan_get_priv_flags (struct net_device *ndev) +{ +const struct flexcan_priv *priv =netdev_priv (ndev); +const u32 quirks = priv->devtype_data.quirks; +u32 priv_flags;u32
priv_flags= 0;
Fixed.
Thanks,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerOn 04.01.2022 16:41:30, Marc Kleine-Budde wrote:
Forgot to list some changes:
Quoted 2 lines
Changes since RFC:
- move driver into subdir
- replaced memcpy() by direct assignment, do this earlier
- use priv->devtype_data.quirks where possible
Quoted 5 lines
- rename
flexcan_main.c->flexcan-core.c
(mcp251xfd and tcan4x5x driver have the same naming scheme)
- use copyright notice fromflexcan.cinflexcan.h
- add private flag support to set rx-fifo
- remove drvinfo, the kernel will fall back to the default implementation
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Marc,
resend in plain text
Quoted 39 lines · Marc Kleine-Budde
Hello,
this picks up Dario's work.
Changes since RFC:
- move driver into subdir
- renameflexcan_main.c->flexcan-core.c
(mcp251xfd and tcan4x5x driver have the same naming scheme)
- use copyright notice fromflexcan.cinflexcan.h
- add private flag support to set rx-fifo
- remove drvinfo, the kernel will fall back to the default implementationShow available private flags:
| $ sudo ethtool --show-priv-flags can0 | Private flags for can0: | rx-fifo: onChange private flag:
| $ sudo ethtool --set-priv-flags can0 rx-fifo off | netlink error: Device or resource busy
...does not work if interface is up.
Shut down interface and change "rx-fifo":
| $ sudo ip link set dev can0 down | $ sudo ethtool --set-priv-flags can0 rx-fifo off | $ sudo ethtool --show-priv-flags can0 | Private flags for can0: | rx-fifo: off | | $ sudo ip link set dev can0 up | $ sudo ethtool --show-priv-flags can0 | Private flags for can0: | rx-fifo: off
Quoted 1 line
Is the name "rx-fifo" acceptable? Can you think of a better name?
If I am not mistaken this series arises from the need to deactivate the RxFIFO only if it is
acceptable not to receive the notification of RTR messages. I wonder if this can be made
explicit to the user.
Do you think it makes sense to explicitly RTR ("rtr-notify") instead of RxFIFO (rx-fifo) ?
And if it makes sense to make it clear that it occurs at the expense of a smaller number
of messages allocated for reception?
Quoted 4 lines
What about adding a new quirk to the driver, only if that quirk is that, it is allowed to change between rx-fifo and rx-mailbox mode?
What platforms are you thinking of for this type of quirk to add?
regards,
Dario
Quoted 9 lines
What to you think?
regards,
Marc
Signature · 17 lines
Dario Binacchi Embedded Linux Developer [email protected] __________________________________ Amarula Solutions SRL Via Le Canevare 30, 31100 Treviso, Veneto, IT T. +39 042 243 5310 [email protected] www.amarulasolutions.com
Marc Kleine-Budde
maintainerQuoted 13 lines · Dario Binacchi
Quoted 1 line
Is the name "rx-fifo" acceptable? Can you think of a better name?
If I am not mistaken this series arises from the need to deactivate the RxFIFO only if it is acceptable not to receive the notification of RTR messages. I wonder if this can be made explicit to the user.
Do you think it makes sense to explicitly RTR ("rtr-notify") instead of RxFIFO (rx-fifo) ?
And if it makes sense to make it clear that it occurs at the expense of a smaller number of messages allocated for reception?
Quoted 1 line
Quoted 5 lines
Quoted 3 lines
What about adding a new quirk to the driver, only if that quirk is that, it is allowed to change between rx-fifo and rx-mailbox mode?
What platforms are you thinking of for this type of quirk to add?
Add this quirk for all platforms that currently don't use FLEXCAN_QUIRK_USE_OFF_TIMESTAMP.
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerQuoted 5 lines · Dario Binacchi
Quoted 1 line
Is the name "rx-fifo" acceptable? Can you think of a better name?
If I am not mistaken this series arises from the need to deactivate the RxFIFO only if it is acceptable not to receive the notification of RTR messages.
ACK
Quoted 1 line
I wonder if this can be made explicit to the user.
I was hoping that we can find a better string that better represents what this option does.
Quoted 4 lines
Do you think it makes sense to explicitly RTR ("rtr-notify") instead of RxFIFO (rx-fifo)? And if it makes sense to make it clear that it occurs at the expense of a smaller number of messages allocated for reception?
I see it the other way round, probably biased by the existing driver :) The user wants to use more buffers at the expense of loosing the ability to receive RTR messages.
I've talked to one of my colleges and we came to the conclusion that the driver should present the user the option to opt out from RTR reception.
If the user has opted out from RTR reception the driver can do internal optimization, such as switching from FIFO to mailbox mode.
What about "rtr-rx" or "rx-rtr"?
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Marc,
Quoted 15 lines · Marc Kleine-Budde
Quoted 5 lines · Dario Binacchi
Quoted 1 line
Is the name "rx-fifo" acceptable? Can you think of a better name?
If I am not mistaken this series arises from the need to deactivate the RxFIFO only if it is acceptable not to receive the notification of RTR messages.
ACK
Quoted 1 line
I wonder if this can be made explicit to the user.
I was hoping that we can find a better string that better represents what this option does.
Quoted 6 lines
Quoted 4 lines
Do you think it makes sense to explicitly RTR ("rtr-notify") instead of RxFIFO (rx-fifo)? And if it makes sense to make it clear that it occurs at the expense of a smaller number of messages allocated for reception?
I see it the other way round, probably biased by the existing driver :)
Could this change of perspective then not require the addition of a new quirk that allows to change between rx-fifo and rx-mailbox mode?
Quoted 2 lines
The user wants to use more buffers at the expense of loosing the ability to receive RTR messages.
Can / should it be documented in some way other than the commit message?
Quoted 6 lines
I've talked to one of my colleges and we came to the conclusion that the driver should present the user the option to opt out from RTR reception.
If the user has opted out from RTR reception the driver can do internal optimization, such as switching from FIFO to mailbox mode.
Is it really always true? In the case of imx6 can we still remain in mailbox mode
and enable / disable RTR reception through Remote Request Storing (CTRL2 [RRS]) bit?
Quoted 2 lines
What about "rtr-rx" or "rx-rtr"?
I prefer "rx-rtr"
Thanks and regards,
Dario
Quoted 9 lines
regards,
Marc--
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Signature · 17 lines
Dario Binacchi Embedded Linux Developer [email protected] __________________________________ Amarula Solutions SRL Via Le Canevare 30, 31100 Treviso, Veneto, IT T. +39 042 243 5310 [email protected] www.amarulasolutions.com
Marc Kleine-Budde
maintainerQuoted 8 lines · Dario Binacchi
Quoted 8 lines
I was hoping that we can find a better string that better represents what this option does.
Quoted 4 lines
Do you think it makes sense to explicitly RTR ("rtr-notify") instead of RxFIFO (rx-fifo)? And if it makes sense to make it clear that it occurs at the expense of a smaller number of messages allocated for reception?
Quoted 4 lines
Quoted 1 line
I see it the other way round, probably biased by the existing driver :)
Could this change of perspective then not require the addition of a new quirk that allows to change between rx-fifo and rx-mailbox mode?
ACK - I only want to enable switching between rx-fifo and rx-mailbox mode for the devices that currently use rx-fifo mode. It makes no sense to switch from rx-mailbox to rx-fifo mode if your flexcan IP core can receive RTR messages in rx-mailbox mode.
There even is the limitation that rx-fifo mode doesn't support CAN-FD mode....but the driver checks for this.
Quoted 4 lines
Quoted 2 lines
The user wants to use more buffers at the expense of loosing the ability to receive RTR messages.
Can / should it be documented in some way other than the commit message?
Yes - Documentation/networking/device_drivers/can/ looks like a good place.
Quoted 6 lines
Quoted 5 lines
I've talked to one of my colleges and we came to the conclusion that the driver should present the user the option to opt out from RTR reception.
If the user has opted out from RTR reception the driver can do internal optimization, such as switching from FIFO to mailbox mode.
Quoted 8 lines
Is it really always true? In the case of imx6 can we still remain in mailbox mode
and enable / disable RTR reception through Remote Request Storing (CTRL2 [RRS]) bit?Quoted 1 line
What about "rtr-rx" or "rx-rtr"?
I prefer "rx-rtr"
Ok, I'll change the patch. Can you write send a doc RFC patch. Place it in the path mentioned above, please use rst format.
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |