linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed
@ 2023-02-17 14:10 Marc Kleine-Budde
  2023-02-17 14:10 ` [PATCH net-next 1/4] can: ctucanfd: ctucan_platform_probe(): use devm_platform_ioremap_resource() Marc Kleine-Budde
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2023-02-17 14:10 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel

Hello netdev-team,

this is a pull request of 4 patches for net-next/master.

The first patch is by Yang Li and converts the ctucanfd driver to
devm_platform_ioremap_resource().

The last 3 patches are by Frank Jungclaus, target the esd_usb driver
and contains preparations for the upcoming support of the esd
CAN-USB/3 hardware.

regards,
Marc

---

The following changes since commit 40967f77dfa9fa728b7f36a5d2eb432f39de185c:

  Merge branch 'seg6-add-psp-flavor-support-for-srv6-end-behavior' (2023-02-16 13:30:06 +0100)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git tags/linux-can-next-for-6.3-20230217

for you to fetch changes up to 6ad172748db49deef0da9038d29019aedf991a7e:

  Merge patch series "can: esd_usb: Some more preparation for supporting esd CAN-USB/3" (2023-02-16 20:59:53 +0100)

----------------------------------------------------------------
linux-can-next-for-6.3-20230217

----------------------------------------------------------------
Frank Jungclaus (3):
      can: esd_usb: Move mislocated storage of SJA1000_ECC_SEG bits in case of a bus error
      can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL
      can: esd_usb: Improve readability on decoding ESD_EV_CAN_ERROR_EXT messages

Marc Kleine-Budde (1):
      Merge patch series "can: esd_usb: Some more preparation for supporting esd CAN-USB/3"

Yang Li (1):
      can: ctucanfd: ctucan_platform_probe(): use devm_platform_ioremap_resource()

 drivers/net/can/ctucanfd/ctucanfd_platform.c |  4 +-
 drivers/net/can/usb/esd_usb.c                | 70 ++++++++++++++++------------
 2 files changed, 41 insertions(+), 33 deletions(-)



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/4] can: ctucanfd: ctucan_platform_probe(): use devm_platform_ioremap_resource()
  2023-02-17 14:10 [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Marc Kleine-Budde
@ 2023-02-17 14:10 ` Marc Kleine-Budde
  2023-02-17 14:10 ` [PATCH net-next 2/4] can: esd_usb: Move mislocated storage of SJA1000_ECC_SEG bits in case of a bus error Marc Kleine-Budde
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2023-02-17 14:10 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Yang Li, Alexander Lobakin,
	Pavel Pisa, Marc Kleine-Budde

From: Yang Li <yang.lee@linux.alibaba.com>

Convert platform_get_resource(), devm_ioremap_resource() to a single
call to Use devm_platform_ioremap_resource(), as this is exactly what
this function does.

Signed-off-by: Yang Li <yang.lee@linux.alibaba.com>
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Acked-by: Pavel Pisa <pisa@cmp.felk.cvut.cz>
Link: https://lore.kernel.org/all/20230216090610.130860-1-yang.lee@linux.alibaba.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/ctucanfd/ctucanfd_platform.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/can/ctucanfd/ctucanfd_platform.c b/drivers/net/can/ctucanfd/ctucanfd_platform.c
index f83684f006ea..a17561d97192 100644
--- a/drivers/net/can/ctucanfd/ctucanfd_platform.c
+++ b/drivers/net/can/ctucanfd/ctucanfd_platform.c
@@ -47,7 +47,6 @@ static void ctucan_platform_set_drvdata(struct device *dev,
  */
 static int ctucan_platform_probe(struct platform_device *pdev)
 {
-	struct resource *res; /* IO mem resources */
 	struct device	*dev = &pdev->dev;
 	void __iomem *addr;
 	int ret;
@@ -55,8 +54,7 @@ static int ctucan_platform_probe(struct platform_device *pdev)
 	int irq;
 
 	/* Get the virtual base address for the device */
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	addr = devm_ioremap_resource(dev, res);
+	addr = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(addr)) {
 		ret = PTR_ERR(addr);
 		goto err;

base-commit: 40967f77dfa9fa728b7f36a5d2eb432f39de185c
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/4] can: esd_usb: Move mislocated storage of SJA1000_ECC_SEG bits in case of a bus error
  2023-02-17 14:10 [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Marc Kleine-Budde
  2023-02-17 14:10 ` [PATCH net-next 1/4] can: ctucanfd: ctucan_platform_probe(): use devm_platform_ioremap_resource() Marc Kleine-Budde
@ 2023-02-17 14:10 ` Marc Kleine-Budde
  2023-02-17 14:10 ` [PATCH net-next 3/4] can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL Marc Kleine-Budde
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2023-02-17 14:10 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Frank Jungclaus,
	Marc Kleine-Budde

From: Frank Jungclaus <frank.jungclaus@esd.eu>

Move the supply for cf->data[3] (bit stream position of CAN error), in
case of a bus- or protocol-error, outside of the "switch (ecc &
SJA1000_ECC_MASK){}"-statement, because this bit stream position is
independent of the error type.

Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
Link: https://lore.kernel.org/all/20230216190450.3901254-2-frank.jungclaus@esd.eu
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/esd_usb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
index 42323f5e6f3a..5e182fadd875 100644
--- a/drivers/net/can/usb/esd_usb.c
+++ b/drivers/net/can/usb/esd_usb.c
@@ -286,7 +286,6 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
 				cf->data[2] |= CAN_ERR_PROT_STUFF;
 				break;
 			default:
-				cf->data[3] = ecc & SJA1000_ECC_SEG;
 				break;
 			}
 
@@ -294,6 +293,9 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
 			if (!(ecc & SJA1000_ECC_DIR))
 				cf->data[2] |= CAN_ERR_PROT_TX;
 
+			/* Bit stream position in CAN frame as the error was detected */
+			cf->data[3] = ecc & SJA1000_ECC_SEG;
+
 			if (priv->can.state == CAN_STATE_ERROR_WARNING ||
 			    priv->can.state == CAN_STATE_ERROR_PASSIVE) {
 				cf->data[1] = (txerr > rxerr) ?
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 3/4] can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL
  2023-02-17 14:10 [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Marc Kleine-Budde
  2023-02-17 14:10 ` [PATCH net-next 1/4] can: ctucanfd: ctucan_platform_probe(): use devm_platform_ioremap_resource() Marc Kleine-Budde
  2023-02-17 14:10 ` [PATCH net-next 2/4] can: esd_usb: Move mislocated storage of SJA1000_ECC_SEG bits in case of a bus error Marc Kleine-Budde
@ 2023-02-17 14:10 ` Marc Kleine-Budde
  2023-02-17 14:10 ` [PATCH net-next 4/4] can: esd_usb: Improve readability on decoding ESD_EV_CAN_ERROR_EXT messages Marc Kleine-Budde
  2023-02-20 23:32 ` [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Jakub Kicinski
  4 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2023-02-17 14:10 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Frank Jungclaus,
	Marc Kleine-Budde

From: Frank Jungclaus <frank.jungclaus@esd.eu>

Start a rework initiated by Vincents remarks "You should not report
the greatest of txerr and rxerr but the one which actually increased."
[1] and "As far as I understand, those flags should be set only when
the threshold is reached" [2] .

Therefore make use of can_change_state() to (among others) set the
flags CAN_ERR_CRTL_[RT]X_WARNING and CAN_ERR_CRTL_[RT]X_PASSIVE,
maintain CAN statistic counters for error_warning, error_passive and
bus_off.

Relocate testing alloc_can_err_skb() for NULL to the end of
esd_usb_rx_event(), to have things like can_bus_off(),
can_change_state() working even in out of memory conditions.

Fixes: 96d8e90382dc ("can: Add driver for esd CAN-USB/2 device")
Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
Link: [1] https://lore.kernel.org/all/CAMZ6RqKGBWe15aMkf8-QLf-cOQg99GQBebSm+1wEzTqHgvmNuw@mail.gmail.com/
Link: [2] https://lore.kernel.org/all/CAMZ6Rq+QBO1yTX_o6GV0yhdBj-RzZSRGWDZBS0fs7zbSTy4hmA@mail.gmail.com/
Link: https://lore.kernel.org/all/20230216190450.3901254-3-frank.jungclaus@esd.eu
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/esd_usb.c | 50 +++++++++++++++++------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
index 5e182fadd875..578b25f873e5 100644
--- a/drivers/net/can/usb/esd_usb.c
+++ b/drivers/net/can/usb/esd_usb.c
@@ -239,41 +239,42 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
 			   msg->msg.rx.dlc, state, ecc, rxerr, txerr);
 
 		skb = alloc_can_err_skb(priv->netdev, &cf);
-		if (skb == NULL) {
-			stats->rx_dropped++;
-			return;
-		}
 
 		if (state != priv->old_state) {
+			enum can_state tx_state, rx_state;
+			enum can_state new_state = CAN_STATE_ERROR_ACTIVE;
+
 			priv->old_state = state;
 
 			switch (state & ESD_BUSSTATE_MASK) {
 			case ESD_BUSSTATE_BUSOFF:
-				priv->can.state = CAN_STATE_BUS_OFF;
-				cf->can_id |= CAN_ERR_BUSOFF;
-				priv->can.can_stats.bus_off++;
+				new_state = CAN_STATE_BUS_OFF;
 				can_bus_off(priv->netdev);
 				break;
 			case ESD_BUSSTATE_WARN:
-				priv->can.state = CAN_STATE_ERROR_WARNING;
-				priv->can.can_stats.error_warning++;
+				new_state = CAN_STATE_ERROR_WARNING;
 				break;
 			case ESD_BUSSTATE_ERRPASSIVE:
-				priv->can.state = CAN_STATE_ERROR_PASSIVE;
-				priv->can.can_stats.error_passive++;
+				new_state = CAN_STATE_ERROR_PASSIVE;
 				break;
 			default:
-				priv->can.state = CAN_STATE_ERROR_ACTIVE;
+				new_state = CAN_STATE_ERROR_ACTIVE;
 				txerr = 0;
 				rxerr = 0;
 				break;
 			}
-		} else {
+
+			if (new_state != priv->can.state) {
+				tx_state = (txerr >= rxerr) ? new_state : 0;
+				rx_state = (txerr <= rxerr) ? new_state : 0;
+				can_change_state(priv->netdev, cf,
+						 tx_state, rx_state);
+			}
+		} else if (skb) {
 			priv->can.can_stats.bus_error++;
 			stats->rx_errors++;
 
-			cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR |
-				      CAN_ERR_CNT;
+			cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
 
 			switch (ecc & SJA1000_ECC_MASK) {
 			case SJA1000_ECC_BIT:
@@ -295,21 +296,20 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
 
 			/* Bit stream position in CAN frame as the error was detected */
 			cf->data[3] = ecc & SJA1000_ECC_SEG;
-
-			if (priv->can.state == CAN_STATE_ERROR_WARNING ||
-			    priv->can.state == CAN_STATE_ERROR_PASSIVE) {
-				cf->data[1] = (txerr > rxerr) ?
-					CAN_ERR_CRTL_TX_PASSIVE :
-					CAN_ERR_CRTL_RX_PASSIVE;
-			}
-			cf->data[6] = txerr;
-			cf->data[7] = rxerr;
 		}
 
 		priv->bec.txerr = txerr;
 		priv->bec.rxerr = rxerr;
 
-		netif_rx(skb);
+		if (skb) {
+			cf->can_id |= CAN_ERR_CNT;
+			cf->data[6] = txerr;
+			cf->data[7] = rxerr;
+
+			netif_rx(skb);
+		} else {
+			stats->rx_dropped++;
+		}
 	}
 }
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 4/4] can: esd_usb: Improve readability on decoding ESD_EV_CAN_ERROR_EXT messages
  2023-02-17 14:10 [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Marc Kleine-Budde
                   ` (2 preceding siblings ...)
  2023-02-17 14:10 ` [PATCH net-next 3/4] can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL Marc Kleine-Budde
@ 2023-02-17 14:10 ` Marc Kleine-Budde
  2023-02-20 23:32 ` [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Jakub Kicinski
  4 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2023-02-17 14:10 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, linux-can, kernel, Frank Jungclaus,
	Marc Kleine-Budde

From: Frank Jungclaus <frank.jungclaus@esd.eu>

As suggested by Marc introduce a union plus a struct ev_can_err_ext
for easier decoding of an ESD_EV_CAN_ERROR_EXT event message (which
simply is a rx_msg with some dedicated data).

Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de>
Link: https://lore.kernel.org/linux-can/20220621071152.ggyhrr5sbzvwpkpx@pengutronix.de/
Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
Link: https://lore.kernel.org/all/20230216190450.3901254-4-frank.jungclaus@esd.eu
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/usb/esd_usb.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
index 578b25f873e5..55b36973952d 100644
--- a/drivers/net/can/usb/esd_usb.c
+++ b/drivers/net/can/usb/esd_usb.c
@@ -127,7 +127,15 @@ struct rx_msg {
 	u8 dlc;
 	__le32 ts;
 	__le32 id; /* upper 3 bits contain flags */
-	u8 data[8];
+	union {
+		u8 data[8];
+		struct {
+			u8 status; /* CAN Controller Status */
+			u8 ecc;    /* Error Capture Register */
+			u8 rec;    /* RX Error Counter */
+			u8 tec;    /* TX Error Counter */
+		} ev_can_err_ext;  /* For ESD_EV_CAN_ERROR_EXT */
+	};
 };
 
 struct tx_msg {
@@ -229,10 +237,10 @@ static void esd_usb_rx_event(struct esd_usb_net_priv *priv,
 	u32 id = le32_to_cpu(msg->msg.rx.id) & ESD_IDMASK;
 
 	if (id == ESD_EV_CAN_ERROR_EXT) {
-		u8 state = msg->msg.rx.data[0];
-		u8 ecc = msg->msg.rx.data[1];
-		u8 rxerr = msg->msg.rx.data[2];
-		u8 txerr = msg->msg.rx.data[3];
+		u8 state = msg->msg.rx.ev_can_err_ext.status;
+		u8 ecc = msg->msg.rx.ev_can_err_ext.ecc;
+		u8 rxerr = msg->msg.rx.ev_can_err_ext.rec;
+		u8 txerr = msg->msg.rx.ev_can_err_ext.tec;
 
 		netdev_dbg(priv->netdev,
 			   "CAN_ERR_EV_EXT: dlc=%#02x state=%02x ecc=%02x rec=%02x tec=%02x\n",
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed
  2023-02-17 14:10 [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Marc Kleine-Budde
                   ` (3 preceding siblings ...)
  2023-02-17 14:10 ` [PATCH net-next 4/4] can: esd_usb: Improve readability on decoding ESD_EV_CAN_ERROR_EXT messages Marc Kleine-Budde
@ 2023-02-20 23:32 ` Jakub Kicinski
  4 siblings, 0 replies; 6+ messages in thread
From: Jakub Kicinski @ 2023-02-20 23:32 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, davem, linux-can, kernel

On Fri, 17 Feb 2023 15:10:25 +0100 Marc Kleine-Budde wrote:
> this is a pull request of 4 patches for net-next/master.
> 
> The first patch is by Yang Li and converts the ctucanfd driver to
> devm_platform_ioremap_resource().
> 
> The last 3 patches are by Frank Jungclaus, target the esd_usb driver
> and contains preparations for the upcoming support of the esd
> CAN-USB/3 hardware.

Appears pulled, thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-02-20 23:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-17 14:10 [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Marc Kleine-Budde
2023-02-17 14:10 ` [PATCH net-next 1/4] can: ctucanfd: ctucan_platform_probe(): use devm_platform_ioremap_resource() Marc Kleine-Budde
2023-02-17 14:10 ` [PATCH net-next 2/4] can: esd_usb: Move mislocated storage of SJA1000_ECC_SEG bits in case of a bus error Marc Kleine-Budde
2023-02-17 14:10 ` [PATCH net-next 3/4] can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL Marc Kleine-Budde
2023-02-17 14:10 ` [PATCH net-next 4/4] can: esd_usb: Improve readability on decoding ESD_EV_CAN_ERROR_EXT messages Marc Kleine-Budde
2023-02-20 23:32 ` [PATCH net-next 0/4] pull-request: can-next 2023-02-17 - fixed Jakub Kicinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).