* [PATCH can-next/b4 1/2] dummyxl: update config possibilities and rename dummyxl_priv @ 2025-07-06 13:35 Oliver Hartkopp 2025-07-06 13:35 ` [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values Oliver Hartkopp 0 siblings, 1 reply; 5+ messages in thread From: Oliver Hartkopp @ 2025-07-06 13:35 UTC (permalink / raw) To: linux-can; +Cc: Oliver Hartkopp Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> --- drivers/net/can/dummyxl.c | 55 +++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/drivers/net/can/dummyxl.c b/drivers/net/can/dummyxl.c index ac1b579b4c1f..c61f27b93e9f 100644 --- a/drivers/net/can/dummyxl.c +++ b/drivers/net/can/dummyxl.c @@ -10,16 +10,17 @@ #include <linux/units.h> #include <linux/can.h> #include <linux/can/dev.h> #include <linux/can/skb.h> -struct dummyxl { +struct dummyxl_priv { struct can_priv can; struct net_device *dev; }; -static struct dummyxl *dummyxl; +/* pointer to our single dummy device (for removal) */ +static struct net_device *dummyxl_dev = NULL; static const struct can_bittiming_const dummyxl_bittiming_const = { .name = "dummyxl nominal", .tseg1_min = 2, .tseg1_max = 256, @@ -71,11 +72,12 @@ static const struct can_tdc_const dummyxl_xl_tdc_const = { .tdco_max = 127, .tdcf_min = 0, .tdcf_max = 127 }; -static void dummyxl_print_bittiming(struct net_device *dev, struct can_bittiming *bt) +static void dummyxl_print_bittiming(struct net_device *dev, + struct can_bittiming *bt) { netdev_info(dev, "\tbitrate: %u\n", bt->bitrate); netdev_info(dev, "\tsample_point: %u\n", bt->sample_point); netdev_info(dev, "\ttq: %u\n", bt->tq); netdev_info(dev, "\tprop_seg: %u\n", bt->prop_seg); @@ -90,15 +92,14 @@ static void dummyxl_print_tdc(struct net_device *dev, struct can_tdc *tdc) netdev_info(dev, "\t\ttdcv: %u\n", tdc->tdcv); netdev_info(dev, "\t\ttdco: %u\n", tdc->tdco); netdev_info(dev, "\t\ttdcf: %u\n", tdc->tdcf); } -static int dummyxl_netdev_open(struct net_device *dev) +static void dummyxl_print_config(struct net_device *dev) { - struct dummyxl *priv = netdev_priv(dev); + struct dummyxl_priv *priv = netdev_priv(dev); struct can_priv *can_priv = &priv->can; - int ret; netdev_info(dev, "CAN control mode/supported : %08X/%08X\n", can_priv->ctrlmode, can_priv->ctrlmode_supported); netdev_info(dev, "CAN CC nominal bittiming:\n"); dummyxl_print_bittiming(dev, &can_priv->bittiming); @@ -129,10 +130,17 @@ static int dummyxl_netdev_open(struct net_device *dev) } } else { netdev_info(dev, "CAN XL is off\n"); } netdev_info(dev, "\n"); +} + +static int dummyxl_netdev_open(struct net_device *dev) +{ + int ret; + + dummyxl_print_config(dev); ret = open_candev(dev); if (ret) return ret; netif_start_queue(dev); @@ -174,50 +182,57 @@ static const struct net_device_ops dummyxl_netdev_ops = { }; static int __init dummyxl_init(void) { struct net_device *dev; - struct dummyxl *priv; + struct dummyxl_priv *priv; int ret; - dev = alloc_candev(sizeof(struct dummyxl), 0); + dev = alloc_candev(sizeof(struct dummyxl_priv), 0); if (!dev) return -ENOMEM; dev->netdev_ops = &dummyxl_netdev_ops; priv = netdev_priv(dev); priv->can.bittiming_const = &dummyxl_bittiming_const; - priv->can.bitrate_max = 8 * MEGA /* BPS */; - priv->can.clock.freq = 80 * MEGA /* Hz */; + priv->can.bitrate_max = 20 * MEGA /* BPS */; + priv->can.clock.freq = 160 * MEGA /* Hz */; priv->can.fd.data_bittiming_const = &dummyxl_fd_databittiming_const; priv->can.fd.tdc_const = &dummyxl_fd_tdc_const; priv->can.xl.data_bittiming_const = &dummyxl_xl_databittiming_const; priv->can.xl.tdc_const = &dummyxl_xl_tdc_const; - priv->can.ctrlmode_supported = CAN_CTRLMODE_LISTENONLY | - CAN_CTRLMODE_FD | CAN_CTRLMODE_TDC_AUTO | - CAN_CTRLMODE_XL | CAN_CTRLMODE_XL_TDC_AUTO; + priv->can.ctrlmode_supported = + CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_CC_LEN8_DLC | + CAN_CTRLMODE_FD | + CAN_CTRLMODE_TDC_AUTO | CAN_CTRLMODE_TDC_MANUAL | + CAN_CTRLMODE_XL | + CAN_CTRLMODE_XL_TDC_AUTO | CAN_CTRLMODE_XL_TDC_MANUAL | + CAN_CTRLMODE_XL_RRS | CAN_CTRLMODE_XL_TRX | + CAN_CTRLMODE_XL_ERR_SIGNAL; priv->dev = dev; - ret = register_candev(priv->dev); + ret = register_candev(dev); if (ret) { - free_candev(priv->dev); + free_candev(dev); return ret; } - dummyxl = priv; + dummyxl_dev = dev; netdev_info(dev, "dummyxl OK\n"); return 0; } static void __exit dummyxl_exit(void) { - struct net_device *dev = dummyxl->dev; + struct net_device *dev = dummyxl_dev; - netdev_info(dev, "dummyxl bye bye\n"); - unregister_candev(dev); - free_candev(dev); + if (dev) { + netdev_info(dev, "dummyxl bye bye\n"); + unregister_candev(dev); + free_candev(dev); + } } module_init(dummyxl_init); module_exit(dummyxl_exit); -- 2.47.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values 2025-07-06 13:35 [PATCH can-next/b4 1/2] dummyxl: update config possibilities and rename dummyxl_priv Oliver Hartkopp @ 2025-07-06 13:35 ` Oliver Hartkopp 2025-07-13 17:25 ` Vincent Mailhol 0 siblings, 1 reply; 5+ messages in thread From: Oliver Hartkopp @ 2025-07-06 13:35 UTC (permalink / raw) To: linux-can; +Cc: Oliver Hartkopp Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> --- drivers/net/can/dummyxl.c | 92 +++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 9 deletions(-) diff --git a/drivers/net/can/dummyxl.c b/drivers/net/can/dummyxl.c index c61f27b93e9f..5178fb7c10c4 100644 --- a/drivers/net/can/dummyxl.c +++ b/drivers/net/can/dummyxl.c @@ -76,11 +76,11 @@ static const struct can_tdc_const dummyxl_xl_tdc_const = { static void dummyxl_print_bittiming(struct net_device *dev, struct can_bittiming *bt) { netdev_info(dev, "\tbitrate: %u\n", bt->bitrate); - netdev_info(dev, "\tsample_point: %u\n", bt->sample_point); + netdev_info(dev, "\tsample_point: 0.%u\n", bt->sample_point); netdev_info(dev, "\ttq: %u\n", bt->tq); netdev_info(dev, "\tprop_seg: %u\n", bt->prop_seg); netdev_info(dev, "\tphase_seg1: %u\n", bt->phase_seg1); netdev_info(dev, "\tphase_seg2: %u\n", bt->phase_seg2); netdev_info(dev, "\tsjw: %u\n", bt->sjw); @@ -92,48 +92,122 @@ static void dummyxl_print_tdc(struct net_device *dev, struct can_tdc *tdc) netdev_info(dev, "\t\ttdcv: %u\n", tdc->tdcv); netdev_info(dev, "\t\ttdco: %u\n", tdc->tdco); netdev_info(dev, "\t\ttdcf: %u\n", tdc->tdcf); } -static void dummyxl_print_config(struct net_device *dev) +static void dummyxl_print_ctrlmode(struct net_device *dev) { struct dummyxl_priv *priv = netdev_priv(dev); struct can_priv *can_priv = &priv->can; + char opts[300] = { 0 }; netdev_info(dev, "CAN control mode/supported : %08X/%08X\n", can_priv->ctrlmode, can_priv->ctrlmode_supported); + + if (can_priv->ctrlmode & CAN_CTRLMODE_LOOPBACK) + strcat(opts, " loopback"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_LISTENONLY) + strcat(opts, " listen-only"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_3_SAMPLES) + strcat(opts, " triple-sampling"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_ONE_SHOT) + strcat(opts, " one-shot"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_BERR_REPORTING) + strcat(opts, " berr-reporting"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_FD) + strcat(opts, " fd"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_PRESUME_ACK) + strcat(opts, " presume-ack"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_FD_NON_ISO) + strcat(opts, " fd-non-iso"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) + strcat(opts, " cc-len8-dlc"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_TDC_AUTO) + strcat(opts, " tdc-mode-auto"); + else if (can_priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL) + strcat(opts, " tdc-mode-manual"); + else + strcat(opts, " tdc-mode-off"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_XL) + strcat(opts, " xl"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TDC_AUTO) + strcat(opts, " xltdc-mode-auto"); + else if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TDC_MANUAL) + strcat(opts, " xltdc-mode-manual"); + else + strcat(opts, " xltdc-mode-off"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_RRS) + strcat(opts, " xlrrs"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TRX) + strcat(opts, " xltrx"); + + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_ERR_SIGNAL) + strcat(opts, " xlerrsig"); + + netdev_info(dev, "Enabled modes:%s\n", opts); + netdev_info(dev, " \n"); +} + +static void dummyxl_print_config(struct net_device *dev) +{ + struct dummyxl_priv *priv = netdev_priv(dev); + struct can_priv *can_priv = &priv->can; + + netdev_info(dev, " \n"); + dummyxl_print_ctrlmode(dev); + + netdev_info(dev, "CAN clock: %9u Hz\n", priv->can.clock.freq); + netdev_info(dev, "CAN max bitrate: %9u BPS\n", priv->can.bitrate_max); + netdev_info(dev, " \n"); + netdev_info(dev, "CAN CC nominal bittiming:\n"); dummyxl_print_bittiming(dev, &can_priv->bittiming); - netdev_info(dev, "\n"); + netdev_info(dev, " \n"); if (can_priv->ctrlmode & CAN_CTRLMODE_FD) { netdev_info(dev, "CAN FD databittiming:\n"); dummyxl_print_bittiming(dev, &can_priv->fd.data_bittiming); if (can_fd_tdc_is_enabled(can_priv)) { netdev_info(dev, "\tCAN FD TDC:\n"); dummyxl_print_tdc(dev, &can_priv->fd.tdc); } else { netdev_info(dev, "\tCAN FD TDC is off\n"); } - } else { - netdev_info(dev, "CAN FD is off\n"); + netdev_info(dev, " \n"); } - netdev_info(dev, "\n"); if (can_priv->ctrlmode & CAN_CTRLMODE_XL) { netdev_info(dev, "CAN XL databittiming:\n"); dummyxl_print_bittiming(dev, &can_priv->xl.data_bittiming); if (can_xl_tdc_is_enabled(can_priv)) { netdev_info(dev, "\tCAN XL TDC:\n"); dummyxl_print_tdc(dev, &can_priv->xl.tdc); } else { netdev_info(dev, "\tCAN XL TDC is off\n"); } - } else { - netdev_info(dev, "CAN XL is off\n"); + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TRX) { + struct can_pwm *pwm = &can_priv->pwm; + netdev_info(dev, "\tCAN XL PWM:\n"); + netdev_info(dev, "\t\tpwmo: %u\n", pwm->pwm_offset); + netdev_info(dev, "\t\tpwml: %u\n", pwm->pwm_phase_long); + netdev_info(dev, "\t\tpwms: %u\n", pwm->pwm_phase_short); + } + netdev_info(dev, " \n"); } - netdev_info(dev, "\n"); } static int dummyxl_netdev_open(struct net_device *dev) { int ret; -- 2.47.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values 2025-07-06 13:35 ` [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values Oliver Hartkopp @ 2025-07-13 17:25 ` Vincent Mailhol 2025-07-15 10:06 ` Marc Kleine-Budde 0 siblings, 1 reply; 5+ messages in thread From: Vincent Mailhol @ 2025-07-13 17:25 UTC (permalink / raw) To: Oliver Hartkopp; +Cc: linux-can On Sun. 6 juil. 2025 at 22:36, Oliver Hartkopp <socketcan@hartkopp.net> wrote: > Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> (...) > -static void dummyxl_print_config(struct net_device *dev) > +static void dummyxl_print_ctrlmode(struct net_device *dev) > { > struct dummyxl_priv *priv = netdev_priv(dev); > struct can_priv *can_priv = &priv->can; > + char opts[300] = { 0 }; > > netdev_info(dev, "CAN control mode/supported : %08X/%08X\n", > can_priv->ctrlmode, can_priv->ctrlmode_supported); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_LOOPBACK) > + strcat(opts, " loopback"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_LISTENONLY) > + strcat(opts, " listen-only"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_3_SAMPLES) > + strcat(opts, " triple-sampling"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_ONE_SHOT) > + strcat(opts, " one-shot"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_BERR_REPORTING) > + strcat(opts, " berr-reporting"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_FD) > + strcat(opts, " fd"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_PRESUME_ACK) > + strcat(opts, " presume-ack"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_FD_NON_ISO) > + strcat(opts, " fd-non-iso"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) > + strcat(opts, " cc-len8-dlc"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_TDC_AUTO) > + strcat(opts, " tdc-mode-auto"); > + else if (can_priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL) > + strcat(opts, " tdc-mode-manual"); > + else > + strcat(opts, " tdc-mode-off"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL) > + strcat(opts, " xl"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TDC_AUTO) > + strcat(opts, " xltdc-mode-auto"); > + else if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TDC_MANUAL) > + strcat(opts, " xltdc-mode-manual"); > + else > + strcat(opts, " xltdc-mode-off"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_RRS) > + strcat(opts, " xlrrs"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TRX) > + strcat(opts, " xltrx"); > + > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_ERR_SIGNAL) > + strcat(opts, " xlerrsig"); I am not a big fan of having a fixed length buffer and then doing several strcat() on it. I rewrote it as below: static void dummyxl_print_ctrlmode(struct net_device *dev) { static const char *names[] = { [ilog2(CAN_CTRLMODE_LOOPBACK)] = "loopback", [ilog2(CAN_CTRLMODE_LISTENONLY)] = "listen-only", [ilog2(CAN_CTRLMODE_3_SAMPLES)] = "triple-sampling", [ilog2(CAN_CTRLMODE_ONE_SHOT)] = "one-shot", [ilog2(CAN_CTRLMODE_BERR_REPORTING)] = "berr-reporting", [ilog2(CAN_CTRLMODE_FD)] = "fd", [ilog2(CAN_CTRLMODE_PRESUME_ACK)] = "presume-ack", [ilog2(CAN_CTRLMODE_FD_NON_ISO)] = "fd-non-iso", [ilog2(CAN_CTRLMODE_CC_LEN8_DLC)] = "cc-len8-dlc", [ilog2(CAN_CTRLMODE_TDC_AUTO)] = "fd-tdc-auto", [ilog2(CAN_CTRLMODE_TDC_MANUAL)] = "fd-tdc-manual", [ilog2(CAN_CTRLMODE_XL)] = "xl", [ilog2(CAN_CTRLMODE_XL_TDC_AUTO)] = "xl-tdc-auto", [ilog2(CAN_CTRLMODE_XL_TDC_MANUAL)] = "xl-tdc-manual", [ilog2(CAN_CTRLMODE_XL_RRS)] = "xl-rrs", [ilog2(CAN_CTRLMODE_XL_TRX)] = "xl-trx", [ilog2(CAN_CTRLMODE_XL_ERR_SIGNAL)] = "xl-err-signal", [ilog2(CAN_CTRLMODE_XL_PWM)] = "pmw", }; struct dummyxl *priv = netdev_priv(dev); unsigned long ctrlmode = priv->can.ctrlmode; netdev_info(dev, "Control modes: 0x%08lx\n", ctrlmode); if (ctrlmode) { u32 idx; netdev_info(dev, "\tlist:"); for_each_set_bit(idx, &ctrlmode, ARRAY_SIZE(names)) netdev_info(dev, "\t\t%s\n", names[idx]); if (ctrlmode >= BIT(ARRAY_SIZE(names))) netdev_info(dev, "\tunknown: 0x%08lx\n", ctrlmode & ~(BIT(ARRAY_SIZE(names)) - 1)); } } It is a bit more concise and more scalable (if you forgot to update the table, you still get the hexadecimal value listed under "unknown"). > + netdev_info(dev, "Enabled modes:%s\n", opts); > + netdev_info(dev, " \n"); > +} I am moving forward with the PWM. Contrary to the last month which was extra busy, I finally managed to liberate some time. I still need some debugging here and there, I will keep you posted :) Yours sincerely, Vincent Mailhol ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values 2025-07-13 17:25 ` Vincent Mailhol @ 2025-07-15 10:06 ` Marc Kleine-Budde 2025-07-15 10:58 ` Vincent Mailhol 0 siblings, 1 reply; 5+ messages in thread From: Marc Kleine-Budde @ 2025-07-15 10:06 UTC (permalink / raw) To: Vincent Mailhol; +Cc: Oliver Hartkopp, linux-can [-- Attachment #1: Type: text/plain, Size: 4660 bytes --] On 14.07.2025 02:25:01, Vincent Mailhol wrote: > On Sun. 6 juil. 2025 at 22:36, Oliver Hartkopp <socketcan@hartkopp.net> wrote: > > Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> > > (...) > > > -static void dummyxl_print_config(struct net_device *dev) > > +static void dummyxl_print_ctrlmode(struct net_device *dev) > > { > > struct dummyxl_priv *priv = netdev_priv(dev); > > struct can_priv *can_priv = &priv->can; > > + char opts[300] = { 0 }; > > > > netdev_info(dev, "CAN control mode/supported : %08X/%08X\n", > > can_priv->ctrlmode, can_priv->ctrlmode_supported); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_LOOPBACK) > > + strcat(opts, " loopback"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_LISTENONLY) > > + strcat(opts, " listen-only"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_3_SAMPLES) > > + strcat(opts, " triple-sampling"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_ONE_SHOT) > > + strcat(opts, " one-shot"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_BERR_REPORTING) > > + strcat(opts, " berr-reporting"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_FD) > > + strcat(opts, " fd"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_PRESUME_ACK) > > + strcat(opts, " presume-ack"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_FD_NON_ISO) > > + strcat(opts, " fd-non-iso"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_CC_LEN8_DLC) > > + strcat(opts, " cc-len8-dlc"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_TDC_AUTO) > > + strcat(opts, " tdc-mode-auto"); > > + else if (can_priv->ctrlmode & CAN_CTRLMODE_TDC_MANUAL) > > + strcat(opts, " tdc-mode-manual"); > > + else > > + strcat(opts, " tdc-mode-off"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL) > > + strcat(opts, " xl"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TDC_AUTO) > > + strcat(opts, " xltdc-mode-auto"); > > + else if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TDC_MANUAL) > > + strcat(opts, " xltdc-mode-manual"); > > + else > > + strcat(opts, " xltdc-mode-off"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_RRS) > > + strcat(opts, " xlrrs"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_TRX) > > + strcat(opts, " xltrx"); > > + > > + if (can_priv->ctrlmode & CAN_CTRLMODE_XL_ERR_SIGNAL) > > + strcat(opts, " xlerrsig"); > > I am not a big fan of having a fixed length buffer and then doing > several strcat() on it. +1 > I rewrote it as below: > > static void dummyxl_print_ctrlmode(struct net_device *dev) > { > static const char *names[] = { > [ilog2(CAN_CTRLMODE_LOOPBACK)] = "loopback", > [ilog2(CAN_CTRLMODE_LISTENONLY)] = "listen-only", > [ilog2(CAN_CTRLMODE_3_SAMPLES)] = "triple-sampling", > [ilog2(CAN_CTRLMODE_ONE_SHOT)] = "one-shot", > [ilog2(CAN_CTRLMODE_BERR_REPORTING)] = "berr-reporting", > [ilog2(CAN_CTRLMODE_FD)] = "fd", > [ilog2(CAN_CTRLMODE_PRESUME_ACK)] = "presume-ack", > [ilog2(CAN_CTRLMODE_FD_NON_ISO)] = "fd-non-iso", > [ilog2(CAN_CTRLMODE_CC_LEN8_DLC)] = "cc-len8-dlc", > [ilog2(CAN_CTRLMODE_TDC_AUTO)] = "fd-tdc-auto", > [ilog2(CAN_CTRLMODE_TDC_MANUAL)] = "fd-tdc-manual", > [ilog2(CAN_CTRLMODE_XL)] = "xl", > [ilog2(CAN_CTRLMODE_XL_TDC_AUTO)] = "xl-tdc-auto", > [ilog2(CAN_CTRLMODE_XL_TDC_MANUAL)] = "xl-tdc-manual", > [ilog2(CAN_CTRLMODE_XL_RRS)] = "xl-rrs", > [ilog2(CAN_CTRLMODE_XL_TRX)] = "xl-trx", > [ilog2(CAN_CTRLMODE_XL_ERR_SIGNAL)] = "xl-err-signal", > [ilog2(CAN_CTRLMODE_XL_PWM)] = "pmw", > }; Is the compiler clever enough, or do you have to use const_ilog2()? regards, Marc -- Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung Nürnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 | [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values 2025-07-15 10:06 ` Marc Kleine-Budde @ 2025-07-15 10:58 ` Vincent Mailhol 0 siblings, 0 replies; 5+ messages in thread From: Vincent Mailhol @ 2025-07-15 10:58 UTC (permalink / raw) To: Marc Kleine-Budde; +Cc: Oliver Hartkopp, linux-can On 15/07/2025 at 19:06, Marc Kleine-Budde wrote: > On 14.07.2025 02:25:01, Vincent Mailhol wrote: >> On Sun. 6 juil. 2025 at 22:36, Oliver Hartkopp <socketcan@hartkopp.net> wrote: (...) >> I rewrote it as below: >> >> static void dummyxl_print_ctrlmode(struct net_device *dev) >> { >> static const char *names[] = { >> [ilog2(CAN_CTRLMODE_LOOPBACK)] = "loopback", >> [ilog2(CAN_CTRLMODE_LISTENONLY)] = "listen-only", >> [ilog2(CAN_CTRLMODE_3_SAMPLES)] = "triple-sampling", >> [ilog2(CAN_CTRLMODE_ONE_SHOT)] = "one-shot", >> [ilog2(CAN_CTRLMODE_BERR_REPORTING)] = "berr-reporting", >> [ilog2(CAN_CTRLMODE_FD)] = "fd", >> [ilog2(CAN_CTRLMODE_PRESUME_ACK)] = "presume-ack", >> [ilog2(CAN_CTRLMODE_FD_NON_ISO)] = "fd-non-iso", >> [ilog2(CAN_CTRLMODE_CC_LEN8_DLC)] = "cc-len8-dlc", >> [ilog2(CAN_CTRLMODE_TDC_AUTO)] = "fd-tdc-auto", >> [ilog2(CAN_CTRLMODE_TDC_MANUAL)] = "fd-tdc-manual", >> [ilog2(CAN_CTRLMODE_XL)] = "xl", >> [ilog2(CAN_CTRLMODE_XL_TDC_AUTO)] = "xl-tdc-auto", >> [ilog2(CAN_CTRLMODE_XL_TDC_MANUAL)] = "xl-tdc-manual", >> [ilog2(CAN_CTRLMODE_XL_RRS)] = "xl-rrs", >> [ilog2(CAN_CTRLMODE_XL_TRX)] = "xl-trx", >> [ilog2(CAN_CTRLMODE_XL_ERR_SIGNAL)] = "xl-err-signal", >> [ilog2(CAN_CTRLMODE_XL_PWM)] = "pmw", >> }; > > Is the compiler clever enough, or do you have to use const_ilog2()? Yes, the code above compiles and runs without issue. ilog2() expands into const_ilog2() if its argument is an integer constant expression (which is the case here). Also, note that the [ilog2(CAN_CTRLMODE_XXXXX)] thing is optional. Doing: static const char *names[] = { "loopback", "listen-only", "triple-sampling", "one-shot", "berr-reporting", "fd", "presume-ack", "fd-non-iso", "cc-len8-dlc", "fd-tdc-auto", "fd-tdc-manual", "xl", "xl-tdc-auto", "xl-tdc-manual", "xl-rrs", "xl-trx", "xl-err-signal", "pmw", }; also works. But the above is more prone to silly mistakes. The ilog2() trick prevents any index mismatch. Yours sincerely, Vincent Mailhol ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-07-15 10:59 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-07-06 13:35 [PATCH can-next/b4 1/2] dummyxl: update config possibilities and rename dummyxl_priv Oliver Hartkopp 2025-07-06 13:35 ` [PATCH can-next/b4 2/2] dummyxl: print ctrlmode and PWM values Oliver Hartkopp 2025-07-13 17:25 ` Vincent Mailhol 2025-07-15 10:06 ` Marc Kleine-Budde 2025-07-15 10:58 ` Vincent Mailhol
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox