linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Oliver Hartkopp <socketcan@hartkopp.net>, linux-can@vger.kernel.org
Subject: Re: [PATCH v4 4/5] can: bcm: add support for CAN FD frames
Date: Fri, 17 Jun 2016 12:23:50 +0200	[thread overview]
Message-ID: <d37c690e-d872-cf25-b22c-7a6def80069f@pengutronix.de> (raw)
In-Reply-To: <1465068411-24301-5-git-send-email-socketcan@hartkopp.net>


[-- Attachment #1.1: Type: text/plain, Size: 3869 bytes --]

On 06/04/2016 09:26 PM, Oliver Hartkopp wrote:
> The programming API of the CAN_BCM depends on struct can_frame which is
> given as array directly behind the bcm_msg_head structure. To follow this
> schema for the CAN FD frames a new flag 'CAN_FD_FRAME' in the bcm_msg_head
> flags indicates that the concatenated CAN frame structures behind the
> bcm_msg_head are defined as struct canfd_frame.
> 
> This patch adds the support to handle CAN and CAN FD frames on a per BCM-op
> base. Main changes:
> 
> - generally use struct canfd_frames instead if struct can_frames
> - use canfd_frame.flags instead of can_frame.can_dlc for private BCM flags
> - make all CAN frame sizes depending on the new CAN_FD_FRAME flags
> - separate between CAN and CAN FD when sending/receiving frames
> 
> Due to the dependence of the CAN_FD_FRAME flag the former binary interface
> for classic CAN frames remains stable.
> 
> Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
> ---
>  include/uapi/linux/can/bcm.h |   1 +
>  net/can/bcm.c                | 223 ++++++++++++++++++++++++++-----------------
>  2 files changed, 134 insertions(+), 90 deletions(-)
> 
> diff --git a/include/uapi/linux/can/bcm.h b/include/uapi/linux/can/bcm.h
> index 7a291dc..cefb304 100644
> --- a/include/uapi/linux/can/bcm.h
> +++ b/include/uapi/linux/can/bcm.h
> @@ -99,5 +99,6 @@ enum {
>  #define RX_ANNOUNCE_RESUME  0x0100
>  #define TX_RESET_MULTI_IDX  0x0200
>  #define RX_RTR_FRAME        0x0400
> +#define CAN_FD_FRAME        0x0800
>  
>  #endif /* !_UAPI_CAN_BCM_H */
> diff --git a/net/can/bcm.c b/net/can/bcm.c
> index f3bf387..31571b6 100644
> --- a/net/can/bcm.c
> +++ b/net/can/bcm.c
> @@ -1,7 +1,7 @@
>  /*
>   * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
>   *
> - * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
> + * Copyright (c) 2002-2016 Volkswagen Group Electronic Research
>   * All rights reserved.
>   *
>   * Redistribution and use in source and binary forms, with or without
> @@ -67,27 +67,27 @@
>   */
>  #define MAX_NFRAMES 256
>  
> -/* use of last_frames[index].can_dlc */
> +/* use of last_frames[index].flags */
>  #define RX_RECV    0x40 /* received data for this element */
>  #define RX_THR     0x80 /* element not been sent due to throttle feature */
> -#define BCM_CAN_DLC_MASK 0x0F /* clean private flags in can_dlc by masking */
> +#define BCM_CAN_FLAGS_MASK 0x3F /* to clean private flags after usage */
>  
>  /* get best masking value for can_rx_register() for a given single can_id */
>  #define REGMASK(id) ((id & CAN_EFF_FLAG) ? \
>  		     (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \
>  		     (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG))
>  
> -#define CAN_BCM_VERSION CAN_VERSION
> +#define CAN_BCM_VERSION "20160531"
>  
>  MODULE_DESCRIPTION("PF_CAN broadcast manager protocol");
>  MODULE_LICENSE("Dual BSD/GPL");
>  MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
>  MODULE_ALIAS("can-proto-2");
>  
> -/* easy access to CAN frame payload */
> -static inline u64 GET_U64(const struct can_frame *cp)
> +/* easy access to the first 64 bit of can(fd)_frame payload */
> +static inline u64 GET_U64(const struct canfd_frame *cp, int offset)
>  {
> -	return *(u64 *)cp->data;
> +	return *(u64 *)(cp->data + offset);

Can you ensure that offset is always a multiple of 8? Unaligned pointer
access will be quite slow on some platforms. Can you please make this
function lower-case (as it's a function not a macro).

>  }
>  

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

  reply	other threads:[~2016-06-17 10:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-04 19:26 [PATCH v4 0/5] Add support for CAN FD to broadcast manager (CAN_BCM) Oliver Hartkopp
2016-06-04 19:26 ` [PATCH v4 1/5] can: bcm: fix indention and other minor style issues Oliver Hartkopp
2016-06-04 19:26 ` [PATCH v4 2/5] can: bcm: use CAN frame instead of can_frame in comments Oliver Hartkopp
2016-06-04 19:26 ` [PATCH v4 3/5] can: bcm: unify bcm_msg_head handling and prepare function parameters Oliver Hartkopp
2016-06-04 19:26 ` [PATCH v4 4/5] can: bcm: add support for CAN FD frames Oliver Hartkopp
2016-06-17 10:23   ` Marc Kleine-Budde [this message]
2016-06-17 10:37     ` Oliver Hartkopp
2016-06-17 10:41       ` Marc Kleine-Budde
2016-06-04 19:26 ` [PATCH v4 5/5] can: bcm: add documentation for CAN FD support Oliver Hartkopp

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=d37c690e-d872-cf25-b22c-7a6def80069f@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    /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;
as well as URLs for NNTP newsgroup(s).