From: Marc Kleine-Budde <mkl@pengutronix.de>
To: linux-can@vger.kernel.org
Cc: Jeroen Hofstee <jhofstee@victronenergy.com>,
Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH 6/6] can: gs_usb: support reading error counters
Date: Thu, 6 Oct 2022 18:24:52 +0200 [thread overview]
Message-ID: <20221006162452.200322-7-mkl@pengutronix.de> (raw)
In-Reply-To: <20221006162452.200322-1-mkl@pengutronix.de>
From: Jeroen Hofstee <jhofstee@victronenergy.com>
the format of this message is a bit weird, single bytes would be
sufficient. At the moment it uses the existing struct gs_device_state.
Not-Signed-off-by: Jeroen Hofstee <jhofstee@victronenergy.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
drivers/net/can/usb/gs_usb.c | 40 ++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index fc5e8d08eb4d..dfabd9cec19b 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -961,6 +961,43 @@ static int gs_can_open(struct net_device *netdev)
return 0;
}
+static int gs_usb_get_state(const struct net_device *netdev,
+ struct can_berr_counter *bec,
+ enum can_state *state)
+{
+ struct gs_can *dev = netdev_priv(netdev);
+ struct gs_device_state ds;
+ int rc;
+
+ rc = usb_control_msg_recv(interface_to_usbdev(dev->iface), 0,
+ GS_USB_BREQ_GET_STATE,
+ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
+ dev->channel, 0,
+ &ds, sizeof(ds),
+ USB_CTRL_GET_TIMEOUT,
+ GFP_KERNEL);
+
+ if (rc)
+ return rc;
+
+ if (ds.state >= CAN_STATE_MAX)
+ return -EOPNOTSUPP;
+
+ *state = ds.state;
+ bec->txerr = ds.txerr;
+ bec->rxerr = ds.rxerr;
+
+ return 0;
+}
+
+static int gs_usb_can_get_berr_counter(const struct net_device *netdev,
+ struct can_berr_counter *bec)
+{
+ enum can_state state;
+
+ return gs_usb_get_state(netdev, bec, &state);
+}
+
static int gs_can_close(struct net_device *netdev)
{
int rc;
@@ -1234,6 +1271,9 @@ static struct gs_can *gs_make_candev(unsigned int channel,
if (feature & GS_CAN_FEATURE_BERR_REPORTING)
dev->can.ctrlmode_supported |= CAN_CTRLMODE_BERR_REPORTING;
+ if (feature & GS_CAN_FEATURE_GET_STATE)
+ dev->can.do_get_berr_counter = gs_can_get_berr_counter;
+
/* The CANtact Pro from LinkLayer Labs is based on the
* LPC54616 µC, which is affected by the NXP LPC USB transfer
* erratum. However, the current firmware (version 2) doesn't
--
2.35.1
next prev parent reply other threads:[~2022-10-06 16:25 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-06 16:24 [PATCH 0/6] can: gs_usb: new features: GS_CAN_FEATURE_GET_STATE, GS_CAN_FEATURE_BERR_REPORTING Marc Kleine-Budde
2022-10-06 16:24 ` [PATCH 1/6] can: gs_usb: gs_can_open(): allow loopback and listen only at the same time Marc Kleine-Budde
2022-10-06 16:24 ` [PATCH 2/6] can: gs_usb: gs_can_open(): sort checks for ctrlmode Marc Kleine-Budde
2022-10-06 16:24 ` [PATCH 3/6] can: gs_usb: gs_can_open(): merge setting of timestamp flags and init Marc Kleine-Budde
2022-10-06 16:24 ` [PATCH 4/6] can: gs_usb: add ability to enable / disable berr rerporting Marc Kleine-Budde
2022-10-06 16:36 ` Marc Kleine-Budde
2022-10-07 18:30 ` Jeroen Hofstee
2022-10-08 15:39 ` Jeroen Hofstee
2022-10-10 7:00 ` Marc Kleine-Budde
2022-10-08 22:11 ` Jeroen Hofstee
2022-10-10 7:03 ` Marc Kleine-Budde
2022-10-06 16:24 ` [PATCH 5/6] can: gs_usb: document GS_CAN_FEATURE_GET_STATE Marc Kleine-Budde
2022-10-06 16:24 ` Marc Kleine-Budde [this message]
2022-10-06 16:37 ` [PATCH 6/6] can: gs_usb: support reading error counters Marc Kleine-Budde
2022-10-06 16:28 ` [PATCH 0/6] can: gs_usb: new features: GS_CAN_FEATURE_GET_STATE, GS_CAN_FEATURE_BERR_REPORTING Marc Kleine-Budde
2022-10-07 18:59 ` Jeroen Hofstee
2022-10-10 6:30 ` Marc Kleine-Budde
2022-10-07 18:46 ` Jeroen Hofstee
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221006162452.200322-7-mkl@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=jhofstee@victronenergy.com \
--cc=linux-can@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox