Message ID | 20201109153657.17897-9-socketcan@hartkopp.net (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Introduce optional DLC element for Classic CAN | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Guessed tree name to be net-next |
netdev/subject_prefix | success | Link |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 0 this patch: 0 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 139 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 0 this patch: 0 |
netdev/header_inline | success | Link |
netdev/stable | success | Stable not CCed |
On 11/9/20 4:36 PM, Oliver Hartkopp wrote: > Support the Classical CAN raw DLC functionality to send and receive DLC > values from 9 .. 15 on various Classical CAN capable USB network drivers: > > - gs_usb > - pcan_usb > - pcan_usb_fd > - usb_8dev > > Tested-by: Oliver Hartkopp <socketcan@hartkopp.net> > Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> > --- > drivers/net/can/usb/gs_usb.c | 8 ++++++-- > drivers/net/can/usb/peak_usb/pcan_usb.c | 8 ++++++-- > drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 17 ++++++++++++----- > drivers/net/can/usb/usb_8dev.c | 9 ++++++--- > 4 files changed, 30 insertions(+), 12 deletions(-) > > diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c > index 940589667a7f..cc0c30a33335 100644 > --- a/drivers/net/can/usb/gs_usb.c > +++ b/drivers/net/can/usb/gs_usb.c > @@ -330,10 +330,13 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) > return; > > cf->can_id = hf->can_id; > > cf->len = can_cc_dlc2len(hf->len); > + cf->len8_dlc = can_get_len8_dlc(dev->can.ctrlmode, cf->len, > + hf->len); What about introducing a function that sets len and len8_dlc at the same time: void can_frame_set_length(const struct can_priv *can, struct can_frame *cfd, u8 dlc); And maybe a function that takes a canfd_frame, so that we don't need to cast.... > + > memcpy(cf->data, hf->data, 8); > > /* ERROR frames tell us information about the controller */ > if (hf->can_id & CAN_ERR_FLAG) > gs_update_state(dev, cf); > @@ -502,11 +505,12 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, > hf->channel = dev->channel; > > cf = (struct can_frame *)skb->data; > > hf->can_id = cf->can_id; > - hf->len = cf->len; > + hf->len = can_get_cc_dlc(dev->can.ctrlmode, cf->len, cf->len8_dlc); > + > memcpy(hf->data, cf->data, cf->len); > > usb_fill_bulk_urb(urb, dev->udev, > usb_sndbulkpipe(dev->udev, GSUSB_ENDPOINT_OUT), > hf, > @@ -856,11 +860,11 @@ static struct gs_can *gs_make_candev(unsigned int channel, > dev->can.state = CAN_STATE_STOPPED; > dev->can.clock.freq = bt_const->fclk_can; > dev->can.bittiming_const = &dev->bt_const; > dev->can.do_set_bittiming = gs_usb_set_bittiming; > > - dev->can.ctrlmode_supported = 0; > + dev->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC; > > if (bt_const->feature & GS_CAN_FEATURE_LISTEN_ONLY) > dev->can.ctrlmode_supported |= CAN_CTRLMODE_LISTENONLY; > > if (bt_const->feature & GS_CAN_FEATURE_LOOP_BACK) > diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c > index ec34f87cc02c..5a8dffacc24e 100644 > --- a/drivers/net/can/usb/peak_usb/pcan_usb.c > +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c > @@ -733,10 +733,12 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) > > cf->can_id = le16_to_cpu(tmp16) >> 5; > } > > cf->len = can_cc_dlc2len(rec_len); > + cf->len8_dlc = can_get_len8_dlc(mc->pdev->dev.can.ctrlmode, cf->len, > + rec_len); > > /* Only first packet timestamp is a word */ > if (pcan_usb_decode_ts(mc, !mc->rec_ts_idx)) > goto decode_failed; > > @@ -836,11 +838,12 @@ static int pcan_usb_encode_msg(struct peak_usb_device *dev, struct sk_buff *skb, > obuf[1] = 1; > > pc = obuf + PCAN_USB_MSG_HEADER_LEN; > > /* status/len byte */ > - *pc = cf->len; > + *pc = can_get_cc_dlc(dev->can.ctrlmode, cf->len, cf->len8_dlc); > + > if (cf->can_id & CAN_RTR_FLAG) > *pc |= PCAN_USB_STATUSLEN_RTR; > > /* can id */ > if (cf->can_id & CAN_EFF_FLAG) { > @@ -990,11 +993,12 @@ static const struct can_bittiming_const pcan_usb_const = { > const struct peak_usb_adapter pcan_usb = { > .name = "PCAN-USB", > .device_id = PCAN_USB_PRODUCT_ID, > .ctrl_count = 1, > .ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY | > - CAN_CTRLMODE_BERR_REPORTING, > + CAN_CTRLMODE_BERR_REPORTING | > + CAN_CTRLMODE_CC_LEN8_DLC, > .clock = { > .freq = PCAN_USB_CRYSTAL_HZ / 2 , > }, > .bittiming_const = &pcan_usb_const, > > diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c > index 761e78d8e647..8020071c9067 100644 > --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c > +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c > @@ -492,16 +492,21 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if, > if (rx_msg_flags & PUCAN_MSG_ERROR_STATE_IND) > cfd->flags |= CANFD_ESI; > > cfd->len = can_fd_dlc2len(pucan_msg_get_dlc(rm)); > } else { > + struct can_frame *cf; > + > /* CAN 2.0 frame case */ > skb = alloc_can_skb(netdev, (struct can_frame **)&cfd); > if (!skb) > return -ENOMEM; > > cfd->len = can_cc_dlc2len(pucan_msg_get_dlc(rm)); > + cf = (struct can_frame *)cfd; > + cf->len8_dlc = can_get_len8_dlc(dev->can.ctrlmode, cf->len, > + pucan_msg_get_dlc(rm)); > } > > cfd->can_id = le32_to_cpu(rm->can_id); > > if (rx_msg_flags & PUCAN_MSG_EXT_ID) > @@ -764,12 +769,14 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev, > tx_msg_flags |= PUCAN_MSG_BITRATE_SWITCH; > > if (cfd->flags & CANFD_ESI) > tx_msg_flags |= PUCAN_MSG_ERROR_STATE_IND; > } else { > + struct can_frame *cf = (struct can_frame *)cfd; > + > /* CAND 2.0 frames */ > - len = cfd->len; > + len = can_get_cc_dlc(dev->can.ctrlmode, cf->len, cf->len8_dlc); > > if (cfd->can_id & CAN_RTR_FLAG) > tx_msg_flags |= PUCAN_MSG_RTR; > } > > @@ -1033,11 +1040,11 @@ static const struct can_bittiming_const pcan_usb_fd_data_const = { > > const struct peak_usb_adapter pcan_usb_fd = { > .name = "PCAN-USB FD", > .device_id = PCAN_USBFD_PRODUCT_ID, > .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, > - .ctrlmode_supported = CAN_CTRLMODE_FD | > + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | > CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, Please add the new CTRLMODE at the end, so that the list ist sorted. I don't mind if the diff is a bit larger. > .clock = { > .freq = PCAN_UFD_CRYSTAL_HZ, > }, > .bittiming_const = &pcan_usb_fd_const, > @@ -1105,11 +1112,11 @@ static const struct can_bittiming_const pcan_usb_chip_data_const = { > > const struct peak_usb_adapter pcan_usb_chip = { > .name = "PCAN-Chip USB", > .device_id = PCAN_USBCHIP_PRODUCT_ID, > .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, > - .ctrlmode_supported = CAN_CTRLMODE_FD | > + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | > CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, same here > .clock = { > .freq = PCAN_UFD_CRYSTAL_HZ, > }, > .bittiming_const = &pcan_usb_chip_const, > @@ -1177,11 +1184,11 @@ static const struct can_bittiming_const pcan_usb_pro_fd_data_const = { > > const struct peak_usb_adapter pcan_usb_pro_fd = { > .name = "PCAN-USB Pro FD", > .device_id = PCAN_USBPROFD_PRODUCT_ID, > .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, > - .ctrlmode_supported = CAN_CTRLMODE_FD | > + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | > CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, same here > .clock = { > .freq = PCAN_UFD_CRYSTAL_HZ, > }, > .bittiming_const = &pcan_usb_pro_fd_const, > @@ -1249,11 +1256,11 @@ static const struct can_bittiming_const pcan_usb_x6_data_const = { > > const struct peak_usb_adapter pcan_usb_x6 = { > .name = "PCAN-USB X6", > .device_id = PCAN_USBX6_PRODUCT_ID, > .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, > - .ctrlmode_supported = CAN_CTRLMODE_FD | > + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | > CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, same here > .clock = { > .freq = PCAN_UFD_CRYSTAL_HZ, > }, > .bittiming_const = &pcan_usb_x6_const, > diff --git a/drivers/net/can/usb/usb_8dev.c b/drivers/net/can/usb/usb_8dev.c > index 6517aaeb4bc0..57e689cb87c9 100644 > --- a/drivers/net/can/usb/usb_8dev.c > +++ b/drivers/net/can/usb/usb_8dev.c > @@ -469,10 +469,12 @@ static void usb_8dev_rx_can_msg(struct usb_8dev_priv *priv, > if (!skb) > return; > > cf->can_id = be32_to_cpu(msg->id); > cf->len = can_cc_dlc2len(msg->dlc & 0xF); > + cf->len8_dlc = can_get_len8_dlc(priv->can.ctrlmode, cf->len, > + msg->dlc & 0xF); > > if (msg->flags & USB_8DEV_EXTID) > cf->can_id |= CAN_EFF_FLAG; > > if (msg->flags & USB_8DEV_RTR) > @@ -635,11 +637,11 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb, > > if (cf->can_id & CAN_EFF_FLAG) > msg->flags |= USB_8DEV_EXTID; > > msg->id = cpu_to_be32(cf->can_id & CAN_ERR_MASK); > - msg->dlc = cf->len; > + msg->dlc = can_get_cc_dlc(priv->can.ctrlmode, cf->len, cf->len8_dlc); > memcpy(msg->data, cf->data, cf->len); > msg->end = USB_8DEV_DATA_END; > > for (i = 0; i < MAX_TX_URBS; i++) { > if (priv->tx_contexts[i].echo_index == MAX_TX_URBS) { > @@ -925,12 +927,13 @@ static int usb_8dev_probe(struct usb_interface *intf, > priv->can.clock.freq = USB_8DEV_ABP_CLOCK; > priv->can.bittiming_const = &usb_8dev_bittiming_const; > priv->can.do_set_mode = usb_8dev_set_mode; > priv->can.do_get_berr_counter = usb_8dev_get_berr_counter; > priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | > - CAN_CTRLMODE_LISTENONLY | > - CAN_CTRLMODE_ONE_SHOT; > + CAN_CTRLMODE_LISTENONLY | > + CAN_CTRLMODE_ONE_SHOT | > + CAN_CTRLMODE_CC_LEN8_DLC; > > netdev->netdev_ops = &usb_8dev_netdev_ops; > > netdev->flags |= IFF_ECHO; /* we support local echo */ > > Marc
On 09.11.20 21:12, Marc Kleine-Budde wrote: > On 11/9/20 4:36 PM, Oliver Hartkopp wrote: >> Support the Classical CAN raw DLC functionality to send and receive DLC >> values from 9 .. 15 on various Classical CAN capable USB network drivers: >> >> - gs_usb >> - pcan_usb >> - pcan_usb_fd >> - usb_8dev >> >> Tested-by: Oliver Hartkopp <socketcan@hartkopp.net> >> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> >> --- >> drivers/net/can/usb/gs_usb.c | 8 ++++++-- >> drivers/net/can/usb/peak_usb/pcan_usb.c | 8 ++++++-- >> drivers/net/can/usb/peak_usb/pcan_usb_fd.c | 17 ++++++++++++----- >> drivers/net/can/usb/usb_8dev.c | 9 ++++++--- >> 4 files changed, 30 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c >> index 940589667a7f..cc0c30a33335 100644 >> --- a/drivers/net/can/usb/gs_usb.c >> +++ b/drivers/net/can/usb/gs_usb.c >> @@ -330,10 +330,13 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) >> return; >> >> cf->can_id = hf->can_id; >> >> cf->len = can_cc_dlc2len(hf->len); >> + cf->len8_dlc = can_get_len8_dlc(dev->can.ctrlmode, cf->len, >> + hf->len); > > What about introducing a function that sets len and len8_dlc at the same time: > > void can_frame_set_length(const struct can_priv *can, struct can_frame *cfd, u8 > dlc); Good idea. I would suggest something like u8 can_get_cc_len(const u32 ctrlmode, struct can_frame *cf, u8 dlc) that still returns the 'len' element, so that we can replace can_cc_dlc2len() with can_get_cc_len() for CAN drivers that add support for len8_dlc. The assignment cf->len = can_get_cc_len() fits better into the code which assigns cf->can_id too. And I would stay on 'u32 ctrlmode' as ctrlmode is the parameter which is namely needed here. A pointer to can_priv can mean anything. > > And maybe a function that takes a canfd_frame, so that we don't need to cast.... No. The len8_dlc element is from struct can_frame. When people use the struct canfd_frame in their driver this might have some benefits for them. But when it comes to access the len8_dlc element this has to be casted IMO. But with the suggested can_get_cc_len() function a needed cast could be put into the parameter list without adding extra code somewhere else in the driver. (..) >> @@ -1033,11 +1040,11 @@ static const struct can_bittiming_const pcan_usb_fd_data_const = { >> >> const struct peak_usb_adapter pcan_usb_fd = { >> .name = "PCAN-USB FD", >> .device_id = PCAN_USBFD_PRODUCT_ID, >> .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, >> - .ctrlmode_supported = CAN_CTRLMODE_FD | >> + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | >> CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, > > Please add the new CTRLMODE at the end, so that the list ist sorted. I don't > mind if the diff is a bit larger. > I had to decide between "make the patch looking good" and "make the result looking good" ;-) But I'm fine with "make the patch looking good" too. Will change that in v6. Best regards, Oliver
On 11/10/20 7:55 AM, Oliver Hartkopp wrote: >>> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c >>> index 940589667a7f..cc0c30a33335 100644 >>> --- a/drivers/net/can/usb/gs_usb.c >>> +++ b/drivers/net/can/usb/gs_usb.c >>> @@ -330,10 +330,13 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) >>> return; >>> >>> cf->can_id = hf->can_id; >>> >>> cf->len = can_cc_dlc2len(hf->len); >>> + cf->len8_dlc = can_get_len8_dlc(dev->can.ctrlmode, cf->len, >>> + hf->len); >> >> What about introducing a function that sets len and len8_dlc at the same time: >> >> void can_frame_set_length(const struct can_priv *can, struct can_frame *cfd, u8 >> dlc); > > Good idea. > > I would suggest something like > > u8 can_get_cc_len(const u32 ctrlmode, struct can_frame *cf, u8 dlc) > > that still returns the 'len' element, so that we can replace > can_cc_dlc2len() with can_get_cc_len() for CAN drivers that add support > for len8_dlc. The regex to replace can_cc_dlc2len() with can_get_cc_len() might be simpler, but passing the cf by reference _and_ assigning the return value to a member of cf looks strange. > The assignment cf->len = can_get_cc_len() fits better into the code > which assigns cf->can_id too. > > And I would stay on 'u32 ctrlmode' as ctrlmode is the parameter which is > namely needed here. A pointer to can_priv can mean anything. OK >> And maybe a function that takes a canfd_frame, so that we don't need to cast.... > > No. The len8_dlc element is from struct can_frame. When people use the > struct canfd_frame in their driver this might have some benefits for them. > But when it comes to access the len8_dlc element this has to be casted IMO. > > But with the suggested can_get_cc_len() function a needed cast could be > put into the parameter list without adding extra code somewhere else in > the driver. OK Marc
On 10.11.20 08:46, Marc Kleine-Budde wrote: > On 11/10/20 7:55 AM, Oliver Hartkopp wrote: >> I would suggest something like >> >> u8 can_get_cc_len(const u32 ctrlmode, struct can_frame *cf, u8 dlc) >> >> that still returns the 'len' element, so that we can replace >> can_cc_dlc2len() with can_get_cc_len() for CAN drivers that add support >> for len8_dlc. > > The regex to replace can_cc_dlc2len() with can_get_cc_len() might be simpler, > but passing the cf by reference _and_ assigning the return value to a member of > cf looks strange. This might be a "make the patch looking good" thing too :-D The code is now implemented even simpler and easy to follow when we migrate the other CAN drivers too. But take a look on yourself. v6 is sent out. Thanks, Oliver
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c index 940589667a7f..cc0c30a33335 100644 --- a/drivers/net/can/usb/gs_usb.c +++ b/drivers/net/can/usb/gs_usb.c @@ -330,10 +330,13 @@ static void gs_usb_receive_bulk_callback(struct urb *urb) return; cf->can_id = hf->can_id; cf->len = can_cc_dlc2len(hf->len); + cf->len8_dlc = can_get_len8_dlc(dev->can.ctrlmode, cf->len, + hf->len); + memcpy(cf->data, hf->data, 8); /* ERROR frames tell us information about the controller */ if (hf->can_id & CAN_ERR_FLAG) gs_update_state(dev, cf); @@ -502,11 +505,12 @@ static netdev_tx_t gs_can_start_xmit(struct sk_buff *skb, hf->channel = dev->channel; cf = (struct can_frame *)skb->data; hf->can_id = cf->can_id; - hf->len = cf->len; + hf->len = can_get_cc_dlc(dev->can.ctrlmode, cf->len, cf->len8_dlc); + memcpy(hf->data, cf->data, cf->len); usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, GSUSB_ENDPOINT_OUT), hf, @@ -856,11 +860,11 @@ static struct gs_can *gs_make_candev(unsigned int channel, dev->can.state = CAN_STATE_STOPPED; dev->can.clock.freq = bt_const->fclk_can; dev->can.bittiming_const = &dev->bt_const; dev->can.do_set_bittiming = gs_usb_set_bittiming; - dev->can.ctrlmode_supported = 0; + dev->can.ctrlmode_supported = CAN_CTRLMODE_CC_LEN8_DLC; if (bt_const->feature & GS_CAN_FEATURE_LISTEN_ONLY) dev->can.ctrlmode_supported |= CAN_CTRLMODE_LISTENONLY; if (bt_const->feature & GS_CAN_FEATURE_LOOP_BACK) diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c index ec34f87cc02c..5a8dffacc24e 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c @@ -733,10 +733,12 @@ static int pcan_usb_decode_data(struct pcan_usb_msg_context *mc, u8 status_len) cf->can_id = le16_to_cpu(tmp16) >> 5; } cf->len = can_cc_dlc2len(rec_len); + cf->len8_dlc = can_get_len8_dlc(mc->pdev->dev.can.ctrlmode, cf->len, + rec_len); /* Only first packet timestamp is a word */ if (pcan_usb_decode_ts(mc, !mc->rec_ts_idx)) goto decode_failed; @@ -836,11 +838,12 @@ static int pcan_usb_encode_msg(struct peak_usb_device *dev, struct sk_buff *skb, obuf[1] = 1; pc = obuf + PCAN_USB_MSG_HEADER_LEN; /* status/len byte */ - *pc = cf->len; + *pc = can_get_cc_dlc(dev->can.ctrlmode, cf->len, cf->len8_dlc); + if (cf->can_id & CAN_RTR_FLAG) *pc |= PCAN_USB_STATUSLEN_RTR; /* can id */ if (cf->can_id & CAN_EFF_FLAG) { @@ -990,11 +993,12 @@ static const struct can_bittiming_const pcan_usb_const = { const struct peak_usb_adapter pcan_usb = { .name = "PCAN-USB", .device_id = PCAN_USB_PRODUCT_ID, .ctrl_count = 1, .ctrlmode_supported = CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_BERR_REPORTING, + CAN_CTRLMODE_BERR_REPORTING | + CAN_CTRLMODE_CC_LEN8_DLC, .clock = { .freq = PCAN_USB_CRYSTAL_HZ / 2 , }, .bittiming_const = &pcan_usb_const, diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c index 761e78d8e647..8020071c9067 100644 --- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c +++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c @@ -492,16 +492,21 @@ static int pcan_usb_fd_decode_canmsg(struct pcan_usb_fd_if *usb_if, if (rx_msg_flags & PUCAN_MSG_ERROR_STATE_IND) cfd->flags |= CANFD_ESI; cfd->len = can_fd_dlc2len(pucan_msg_get_dlc(rm)); } else { + struct can_frame *cf; + /* CAN 2.0 frame case */ skb = alloc_can_skb(netdev, (struct can_frame **)&cfd); if (!skb) return -ENOMEM; cfd->len = can_cc_dlc2len(pucan_msg_get_dlc(rm)); + cf = (struct can_frame *)cfd; + cf->len8_dlc = can_get_len8_dlc(dev->can.ctrlmode, cf->len, + pucan_msg_get_dlc(rm)); } cfd->can_id = le32_to_cpu(rm->can_id); if (rx_msg_flags & PUCAN_MSG_EXT_ID) @@ -764,12 +769,14 @@ static int pcan_usb_fd_encode_msg(struct peak_usb_device *dev, tx_msg_flags |= PUCAN_MSG_BITRATE_SWITCH; if (cfd->flags & CANFD_ESI) tx_msg_flags |= PUCAN_MSG_ERROR_STATE_IND; } else { + struct can_frame *cf = (struct can_frame *)cfd; + /* CAND 2.0 frames */ - len = cfd->len; + len = can_get_cc_dlc(dev->can.ctrlmode, cf->len, cf->len8_dlc); if (cfd->can_id & CAN_RTR_FLAG) tx_msg_flags |= PUCAN_MSG_RTR; } @@ -1033,11 +1040,11 @@ static const struct can_bittiming_const pcan_usb_fd_data_const = { const struct peak_usb_adapter pcan_usb_fd = { .name = "PCAN-USB FD", .device_id = PCAN_USBFD_PRODUCT_ID, .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, - .ctrlmode_supported = CAN_CTRLMODE_FD | + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, }, .bittiming_const = &pcan_usb_fd_const, @@ -1105,11 +1112,11 @@ static const struct can_bittiming_const pcan_usb_chip_data_const = { const struct peak_usb_adapter pcan_usb_chip = { .name = "PCAN-Chip USB", .device_id = PCAN_USBCHIP_PRODUCT_ID, .ctrl_count = PCAN_USBFD_CHANNEL_COUNT, - .ctrlmode_supported = CAN_CTRLMODE_FD | + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, }, .bittiming_const = &pcan_usb_chip_const, @@ -1177,11 +1184,11 @@ static const struct can_bittiming_const pcan_usb_pro_fd_data_const = { const struct peak_usb_adapter pcan_usb_pro_fd = { .name = "PCAN-USB Pro FD", .device_id = PCAN_USBPROFD_PRODUCT_ID, .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, - .ctrlmode_supported = CAN_CTRLMODE_FD | + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, }, .bittiming_const = &pcan_usb_pro_fd_const, @@ -1249,11 +1256,11 @@ static const struct can_bittiming_const pcan_usb_x6_data_const = { const struct peak_usb_adapter pcan_usb_x6 = { .name = "PCAN-USB X6", .device_id = PCAN_USBX6_PRODUCT_ID, .ctrl_count = PCAN_USBPROFD_CHANNEL_COUNT, - .ctrlmode_supported = CAN_CTRLMODE_FD | + .ctrlmode_supported = CAN_CTRLMODE_FD | CAN_CTRLMODE_CC_LEN8_DLC | CAN_CTRLMODE_3_SAMPLES | CAN_CTRLMODE_LISTENONLY, .clock = { .freq = PCAN_UFD_CRYSTAL_HZ, }, .bittiming_const = &pcan_usb_x6_const, diff --git a/drivers/net/can/usb/usb_8dev.c b/drivers/net/can/usb/usb_8dev.c index 6517aaeb4bc0..57e689cb87c9 100644 --- a/drivers/net/can/usb/usb_8dev.c +++ b/drivers/net/can/usb/usb_8dev.c @@ -469,10 +469,12 @@ static void usb_8dev_rx_can_msg(struct usb_8dev_priv *priv, if (!skb) return; cf->can_id = be32_to_cpu(msg->id); cf->len = can_cc_dlc2len(msg->dlc & 0xF); + cf->len8_dlc = can_get_len8_dlc(priv->can.ctrlmode, cf->len, + msg->dlc & 0xF); if (msg->flags & USB_8DEV_EXTID) cf->can_id |= CAN_EFF_FLAG; if (msg->flags & USB_8DEV_RTR) @@ -635,11 +637,11 @@ static netdev_tx_t usb_8dev_start_xmit(struct sk_buff *skb, if (cf->can_id & CAN_EFF_FLAG) msg->flags |= USB_8DEV_EXTID; msg->id = cpu_to_be32(cf->can_id & CAN_ERR_MASK); - msg->dlc = cf->len; + msg->dlc = can_get_cc_dlc(priv->can.ctrlmode, cf->len, cf->len8_dlc); memcpy(msg->data, cf->data, cf->len); msg->end = USB_8DEV_DATA_END; for (i = 0; i < MAX_TX_URBS; i++) { if (priv->tx_contexts[i].echo_index == MAX_TX_URBS) { @@ -925,12 +927,13 @@ static int usb_8dev_probe(struct usb_interface *intf, priv->can.clock.freq = USB_8DEV_ABP_CLOCK; priv->can.bittiming_const = &usb_8dev_bittiming_const; priv->can.do_set_mode = usb_8dev_set_mode; priv->can.do_get_berr_counter = usb_8dev_get_berr_counter; priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | - CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_ONE_SHOT; + CAN_CTRLMODE_LISTENONLY | + CAN_CTRLMODE_ONE_SHOT | + CAN_CTRLMODE_CC_LEN8_DLC; netdev->netdev_ops = &usb_8dev_netdev_ops; netdev->flags |= IFF_ECHO; /* we support local echo */