netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vincent MAILHOL <mailhol.vincent@wanadoo.fr>
To: Frank Jungclaus <frank.jungclaus@esd.eu>
Cc: linux-can@vger.kernel.org,
	"Marc Kleine-Budde" <mkl@pengutronix.de>,
	"Wolfgang Grandegger" <wg@grandegger.com>,
	"Stefan Mätje" <stefan.maetje@esd.eu>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/6] can: esd_usb: Replace initializer macros used for struct can_bittiming_const
Date: Sun, 21 May 2023 18:16:17 +0900	[thread overview]
Message-ID: <CAMZ6RqL-2qB=kLPd84rWHd3=xPcspSNXvNYpR9Fyx+4-Ft16gQ@mail.gmail.com> (raw)
In-Reply-To: <20230519195600.420644-3-frank.jungclaus@esd.eu>

Thanks for the patch.

On Sat. 20 May 2023 at 04:57, Frank Jungclaus <frank.jungclaus@esd.eu> wrote:
> Replace the macros used to initialize the members of struct
> can_bittiming_const with direct values. Then also use those struct
> members to do the calculations in esd_usb2_set_bittiming().
>
> Link: https://lore.kernel.org/all/CAMZ6RqLaDNy-fZ2G0+QMhUEckkXLL+ZyELVSDFmqpd++aBzZQg@mail.gmail.com/
> Suggested-by: Vincent MAILHOL <mailhol.vincent@wanadoo.fr>
> Signed-off-by: Frank Jungclaus <frank.jungclaus@esd.eu>
> ---
>  drivers/net/can/usb/esd_usb.c | 33 +++++++++++++--------------------
>  1 file changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/net/can/usb/esd_usb.c b/drivers/net/can/usb/esd_usb.c
> index 32354cfdf151..2eecf352ec47 100644
> --- a/drivers/net/can/usb/esd_usb.c
> +++ b/drivers/net/can/usb/esd_usb.c
> @@ -60,18 +60,10 @@ MODULE_LICENSE("GPL v2");
>  #define ESD_USB_NO_BAUDRATE    GENMASK(30, 0) /* bit rate unconfigured */
>
>  /* bit timing CAN-USB/2 */
> -#define ESD_USB2_TSEG1_MIN     1
> -#define ESD_USB2_TSEG1_MAX     16
>  #define ESD_USB2_TSEG1_SHIFT   16
> -#define ESD_USB2_TSEG2_MIN     1
> -#define ESD_USB2_TSEG2_MAX     8
>  #define ESD_USB2_TSEG2_SHIFT   20
> -#define ESD_USB2_SJW_MAX       4
>  #define ESD_USB2_SJW_SHIFT     14
>  #define ESD_USBM_SJW_SHIFT     24
> -#define ESD_USB2_BRP_MIN       1
> -#define ESD_USB2_BRP_MAX       1024
> -#define ESD_USB2_BRP_INC       1
>  #define ESD_USB2_3_SAMPLES     BIT(23)
>
>  /* esd IDADD message */
> @@ -909,19 +901,20 @@ static const struct ethtool_ops esd_usb_ethtool_ops = {
>
>  static const struct can_bittiming_const esd_usb2_bittiming_const = {
>         .name = "esd_usb2",
> -       .tseg1_min = ESD_USB2_TSEG1_MIN,
> -       .tseg1_max = ESD_USB2_TSEG1_MAX,
> -       .tseg2_min = ESD_USB2_TSEG2_MIN,
> -       .tseg2_max = ESD_USB2_TSEG2_MAX,
> -       .sjw_max = ESD_USB2_SJW_MAX,
> -       .brp_min = ESD_USB2_BRP_MIN,
> -       .brp_max = ESD_USB2_BRP_MAX,
> -       .brp_inc = ESD_USB2_BRP_INC,
> +       .tseg1_min = 1,
> +       .tseg1_max = 16,
> +       .tseg2_min = 1,
> +       .tseg2_max = 8,
> +       .sjw_max = 4,
> +       .brp_min = 1,
> +       .brp_max = 1024,
> +       .brp_inc = 1,
>  };
>
>  static int esd_usb2_set_bittiming(struct net_device *netdev)
>  {
>         struct esd_usb_net_priv *priv = netdev_priv(netdev);
> +       const struct can_bittiming_const *btc = priv->can.bittiming_const;

I initially suggested doing:

          const struct can_bittiming_const *btc = priv->can.bittiming_const;

But now that I think again about it, doing:

          const struct can_bittiming_const *btc = &esd_usb2_bittiming_const;

is slightly better as it will allow the compiler to fold the integer
constant expressions such as btc->brp_max - 1. The compiler is not
smart enough to figure out what values are held in
priv->can.bittiming_const at compile time.

Sorry for not figuring this the first time.

>         struct can_bittiming *bt = &priv->can.bittiming;
>         union esd_usb_msg *msg;
>         int err;
> @@ -932,7 +925,7 @@ static int esd_usb2_set_bittiming(struct net_device *netdev)
>         if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
>                 canbtr |= ESD_USB_LOM;
>
> -       canbtr |= (bt->brp - 1) & (ESD_USB2_BRP_MAX - 1);
> +       canbtr |= (bt->brp - 1) & (btc->brp_max - 1);
>
>         if (le16_to_cpu(priv->usb->udev->descriptor.idProduct) ==
>             USB_CANUSBM_PRODUCT_ID)
> @@ -940,12 +933,12 @@ static int esd_usb2_set_bittiming(struct net_device *netdev)
>         else
>                 sjw_shift = ESD_USB2_SJW_SHIFT;
>
> -       canbtr |= ((bt->sjw - 1) & (ESD_USB2_SJW_MAX - 1))
> +       canbtr |= ((bt->sjw - 1) & (btc->sjw_max - 1))
>                 << sjw_shift;
>         canbtr |= ((bt->prop_seg + bt->phase_seg1 - 1)
> -                  & (ESD_USB2_TSEG1_MAX - 1))
> +                  & (btc->tseg1_max - 1))
>                 << ESD_USB2_TSEG1_SHIFT;
> -       canbtr |= ((bt->phase_seg2 - 1) & (ESD_USB2_TSEG2_MAX - 1))
> +       canbtr |= ((bt->phase_seg2 - 1) & (btc->tseg2_max - 1))
>                 << ESD_USB2_TSEG2_SHIFT;
>         if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
>                 canbtr |= ESD_USB2_3_SAMPLES;
> --
> 2.25.1
>

  reply	other threads:[~2023-05-21  9:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 19:55 [PATCH v2 0/6] can: esd_usb: More preparation before supporting esd CAN-USB/3 Frank Jungclaus
2023-05-19 19:55 ` [PATCH v2 1/6] can: esd_usb: Make use of existing kernel macros Frank Jungclaus
2023-05-21  9:16   ` Vincent MAILHOL
2023-05-22  8:13     ` Marc Kleine-Budde
2023-05-19 19:55 ` [PATCH v2 2/6] can: esd_usb: Replace initializer macros used for struct can_bittiming_const Frank Jungclaus
2023-05-21  9:16   ` Vincent MAILHOL [this message]
2023-05-22  8:19     ` Marc Kleine-Budde
2023-05-19 19:55 ` [PATCH v2 3/6] can: esd_usb: Use consistent prefixes for macros Frank Jungclaus
2023-05-19 19:55 ` [PATCH v2 4/6] can: esd_usb: Prefix all structures with the device name Frank Jungclaus
2023-05-19 19:55 ` [PATCH v2 5/6] can: esd_usb: Replace hardcoded message length given to USB commands Frank Jungclaus
2023-05-19 19:56 ` [PATCH v2 6/6] can: esd_usb: Don't bother the user with nonessential log message Frank Jungclaus
2023-05-21  9:20 ` [PATCH v2 0/6] can: esd_usb: More preparation before supporting esd CAN-USB/3 Vincent MAILHOL

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='CAMZ6RqL-2qB=kLPd84rWHd3=xPcspSNXvNYpR9Fyx+4-Ft16gQ@mail.gmail.com' \
    --to=mailhol.vincent@wanadoo.fr \
    --cc=frank.jungclaus@esd.eu \
    --cc=linux-can@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=stefan.maetje@esd.eu \
    --cc=wg@grandegger.com \
    /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).