Commit a6375fd7 authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

Merge patch series "can: gs_usb: new features: GS_CAN_FEATURE_GET_STATE,...

Merge patch series "can: gs_usb: new features: GS_CAN_FEATURE_GET_STATE, GS_CAN_FEATURE_BERR_REPORTING"

Marc Kleine-Budde <mkl@pengutronix.de> says:

this series targets the gs_us driver. First there are some cleanup
patches by me, followed by now 4 patches by Jeroen Hofstee's. These
patches are based on the venus-5.19.4-gsusb branch of his Linux
repository and add 2 new features (GS_CAN_FEATURE_GET_STATE,
GS_CAN_FEATURE_BERR_REPORTING) to the driver.

Changes since v2: https://lore.kernel.org/all/20221019213035.1607752-1-mkl@pengutronix.de
- 7/7: add missing endianness conversion

Changes since v1: https://lore.kernel.org/all/20221006162452.200322-1-mkl@pengutronix.de
- added Jeroen's S-o-b to patches 4...7
- split former "[PATCH 4/6] can: gs_usb: add ability to enable / disable berr rerporting"
  into 2 patches, fix subject, update patch description

Changes since venus-5.19.4-gsusb: https://github.com/jhofstee/linux/tree/venus-5.19.4-gsusb
- fixed 2nd parameter of usb_control_msg_recv()
- rebased to current net-next/main
- renumbered the FEATURE, MODE and BREQ bits, as termination support
  landed mainline first
- split GS_CAN_FEATURE_GET_STATE patch into documentation and
  implementation part
- added Not-Signed-off-by: tag, as these patches are not Signed-off yet

Link: https://lore.kernel.org/all/20221019221016.1659260-1-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parents acff76fa 0c9f92a4
...@@ -66,6 +66,7 @@ enum gs_usb_breq { ...@@ -66,6 +66,7 @@ enum gs_usb_breq {
GS_USB_BREQ_BT_CONST_EXT, GS_USB_BREQ_BT_CONST_EXT,
GS_USB_BREQ_SET_TERMINATION, GS_USB_BREQ_SET_TERMINATION,
GS_USB_BREQ_GET_TERMINATION, GS_USB_BREQ_GET_TERMINATION,
GS_USB_BREQ_GET_STATE,
}; };
enum gs_can_mode { enum gs_can_mode {
...@@ -134,6 +135,8 @@ struct gs_device_config { ...@@ -134,6 +135,8 @@ struct gs_device_config {
/* GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX BIT(9) */ /* GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX BIT(9) */
/* GS_CAN_FEATURE_BT_CONST_EXT BIT(10) */ /* GS_CAN_FEATURE_BT_CONST_EXT BIT(10) */
/* GS_CAN_FEATURE_TERMINATION BIT(11) */ /* GS_CAN_FEATURE_TERMINATION BIT(11) */
#define GS_CAN_MODE_BERR_REPORTING BIT(12)
/* GS_CAN_FEATURE_GET_STATE BIT(13) */
struct gs_device_mode { struct gs_device_mode {
__le32 mode; __le32 mode;
...@@ -174,7 +177,9 @@ struct gs_device_termination_state { ...@@ -174,7 +177,9 @@ struct gs_device_termination_state {
#define GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX BIT(9) #define GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX BIT(9)
#define GS_CAN_FEATURE_BT_CONST_EXT BIT(10) #define GS_CAN_FEATURE_BT_CONST_EXT BIT(10)
#define GS_CAN_FEATURE_TERMINATION BIT(11) #define GS_CAN_FEATURE_TERMINATION BIT(11)
#define GS_CAN_FEATURE_MASK GENMASK(11, 0) #define GS_CAN_FEATURE_BERR_REPORTING BIT(12)
#define GS_CAN_FEATURE_GET_STATE BIT(13)
#define GS_CAN_FEATURE_MASK GENMASK(13, 0)
/* internal quirks - keep in GS_CAN_FEATURE space for now */ /* internal quirks - keep in GS_CAN_FEATURE space for now */
...@@ -843,8 +848,6 @@ static int gs_can_open(struct net_device *netdev) ...@@ -843,8 +848,6 @@ static int gs_can_open(struct net_device *netdev)
ctrlmode = dev->can.ctrlmode; ctrlmode = dev->can.ctrlmode;
if (ctrlmode & CAN_CTRLMODE_FD) { if (ctrlmode & CAN_CTRLMODE_FD) {
flags |= GS_CAN_MODE_FD;
if (dev->feature & GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX) if (dev->feature & GS_CAN_FEATURE_REQ_USB_QUIRK_LPC546XX)
dev->hf_size_tx = struct_size(hf, canfd_quirk, 1); dev->hf_size_tx = struct_size(hf, canfd_quirk, 1);
else else
...@@ -911,25 +914,29 @@ static int gs_can_open(struct net_device *netdev) ...@@ -911,25 +914,29 @@ static int gs_can_open(struct net_device *netdev)
/* flags */ /* flags */
if (ctrlmode & CAN_CTRLMODE_LOOPBACK) if (ctrlmode & CAN_CTRLMODE_LOOPBACK)
flags |= GS_CAN_MODE_LOOP_BACK; flags |= GS_CAN_MODE_LOOP_BACK;
else if (ctrlmode & CAN_CTRLMODE_LISTENONLY)
if (ctrlmode & CAN_CTRLMODE_LISTENONLY)
flags |= GS_CAN_MODE_LISTEN_ONLY; flags |= GS_CAN_MODE_LISTEN_ONLY;
/* Controller is not allowed to retry TX if (ctrlmode & CAN_CTRLMODE_3_SAMPLES)
* this mode is unavailable on atmels uc3c hardware flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
*/
if (ctrlmode & CAN_CTRLMODE_ONE_SHOT) if (ctrlmode & CAN_CTRLMODE_ONE_SHOT)
flags |= GS_CAN_MODE_ONE_SHOT; flags |= GS_CAN_MODE_ONE_SHOT;
if (ctrlmode & CAN_CTRLMODE_3_SAMPLES) if (ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
flags |= GS_CAN_MODE_TRIPLE_SAMPLE; flags |= GS_CAN_MODE_BERR_REPORTING;
if (ctrlmode & CAN_CTRLMODE_FD)
flags |= GS_CAN_MODE_FD;
/* if hardware supports timestamps, enable it */ /* if hardware supports timestamps, enable it */
if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP) {
flags |= GS_CAN_MODE_HW_TIMESTAMP; flags |= GS_CAN_MODE_HW_TIMESTAMP;
/* start polling timestamp */ /* start polling timestamp */
if (dev->feature & GS_CAN_FEATURE_HW_TIMESTAMP)
gs_usb_timestamp_init(dev); gs_usb_timestamp_init(dev);
}
/* finally start device */ /* finally start device */
dev->can.state = CAN_STATE_ERROR_ACTIVE; dev->can.state = CAN_STATE_ERROR_ACTIVE;
...@@ -954,6 +961,42 @@ static int gs_can_open(struct net_device *netdev) ...@@ -954,6 +961,42 @@ static int gs_can_open(struct net_device *netdev)
return 0; 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 (le32_to_cpu(ds.state) >= CAN_STATE_MAX)
return -EOPNOTSUPP;
*state = le32_to_cpu(ds.state);
bec->txerr = le32_to_cpu(ds.txerr);
bec->rxerr = le32_to_cpu(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) static int gs_can_close(struct net_device *netdev)
{ {
int rc; int rc;
...@@ -1225,6 +1268,12 @@ static struct gs_can *gs_make_candev(unsigned int channel, ...@@ -1225,6 +1268,12 @@ 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_usb_can_get_berr_counter;
/* The CANtact Pro from LinkLayer Labs is based on the /* The CANtact Pro from LinkLayer Labs is based on the
* LPC54616 µC, which is affected by the NXP LPC USB transfer * LPC54616 µC, which is affected by the NXP LPC USB transfer
* erratum. However, the current firmware (version 2) doesn't * erratum. However, the current firmware (version 2) doesn't
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment