All of lore.kernel.org
 help / color / mirror / Atom feed
* RE: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
@ 2022-01-31 14:25 Stéphane Grosjean
  2022-01-31 14:31 ` Marc Kleine-Budde
  0 siblings, 1 reply; 10+ messages in thread
From: Stéphane Grosjean @ 2022-01-31 14:25 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can Mailing List

Hi,

>> +     u32 devid;
>>
>> +             memcpy(data, (u8 *)&devid + eeprom->offset, eeprom->len);
>
> cast not needed.
>

We need to cast the u32 * into a u8 * because eeprom->offset is a count of bytes, isn't it?

Regards,

— Stéphane






            De: Marc Kleine-Budde
Envoyé: Samedi 29 janvier 2022 14:58
À: Stéphane Grosjean
Cc: linux-can Mailing List
Objet: Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number




On 28.01.2022 16:01:57, Stephane Grosjean wrote:

> This patch introduces 3 new functions implementing support for eeprom

> access of USB - CAN network interfaces managed by the driver, through the

> ethtool interface. All of them (except the PCAN-USB interface) interpret

> the 4 data bytes as a 32-bit value to be read/write in the non-volatile

> memory of the device. The PCAN-USB only manages a single byte value.

>

> Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>

> ---

>  drivers/net/can/usb/peak_usb/pcan_usb.c      |  9 +++

>  drivers/net/can/usb/peak_usb/pcan_usb_core.c | 69 ++++++++++++++++++++

>  drivers/net/can/usb/peak_usb/pcan_usb_core.h |  6 ++

>  drivers/net/can/usb/peak_usb/pcan_usb_fd.c   |  3 +

>  drivers/net/can/usb/peak_usb/pcan_usb_pro.c  |  3 +

>  5 files changed, 90 insertions(+)

>

> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c

> index b29daaab2e6e..60c9329701a5 100644

> --- a/drivers/net/can/usb/peak_usb/pcan_usb.c

> +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c

> @@ -981,8 +981,17 @@ static int pcan_usb_set_phys_id(struct net_device *netdev,

>        return err;

>  }

>

> +/* This device only handles 8-bit user device id. */

> +static int pcan_usb_get_eeprom_len(struct net_device *netdev)

> +{

> +     return sizeof(u8);

> +}

> +

>  static const struct ethtool_ops pcan_usb_ethtool_ops = {

>        .set_phys_id = pcan_usb_set_phys_id,

> +     .get_eeprom_len = pcan_usb_get_eeprom_len,

> +     .get_eeprom = peak_usb_get_eeprom,

> +     .set_eeprom = peak_usb_set_eeprom,

>  };

>

>  /*

> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c

> index aa8bcdcfa2fb..4e858d592e59 100644

> --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c

> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c

> @@ -782,6 +782,75 @@ static const struct net_device_ops peak_usb_netdev_ops = {

>        .ndo_change_mtu = can_change_mtu,

>  };

>

> +/* CAN-USB devices generally handle 32-bit user device id.

> + * In case one doesn't, then it have to overload this function.

> + */

> +int peak_usb_get_eeprom_len(struct net_device *netdev)

> +{

> +     return sizeof(u32);

> +}

> +

> +/* Every CAN-USB device exports the dev_get_user_devid() operation. It is used

> + * here to fill the data buffer with the user defined device number.

> + */

> +int peak_usb_get_eeprom(struct net_device *netdev,

> +                     struct ethtool_eeprom *eeprom, u8 *data)

> +{

> +     struct peak_usb_device *dev = netdev_priv(netdev);

> +     u32 devid;

> +     int err;

> +

> +     if (!eeprom->len)

> +             return -EINVAL;



There already is a check for len == 0.



> +     err = dev->adapter->dev_get_user_devid(dev, &devid);

> +     if (!err) {



Please return on error.



> +             memcpy(data, (u8 *)&devid + eeprom->offset, eeprom->len);



cast not needed.

> +

> +             /* update cached value */

> +             dev->device_number = devid;

> +     }

> +

> +     return err;

> +}

> +

> +/* Every CAN-USB device exports the dev_get_user_devid()/dev_set_user_devid()

> + * operations. They are used here to set the new user defined device number.

> + */

> +int peak_usb_set_eeprom(struct net_device *netdev,

> +                     struct ethtool_eeprom *eeprom, u8 *data)

> +{

> +     struct peak_usb_device *dev = netdev_priv(netdev);

> +     u32 devid;

> +     int err;

> +

> +     if (!eeprom->len)

> +             return -EINVAL;



There already is a check for len == 0.



> +

> +     /* first, read the current user defined device value number */

> +     err = dev->adapter->dev_get_user_devid(dev, &devid);

> +     if (err) {

> +             netdev_err(netdev, "Failed to init device id (err %d)\n", err);

> +             return err;

> +     }

> +

> +     /* do update the value with user given bytes */

> +     memcpy((u8 *)&devid + eeprom->offset, data, eeprom->len);



cast not needed.



regards,

Marc



--

Pengutronix e.K.                 | Marc Kleine-Budde           |

Embedded Linux                   | https://www.pengutronix.de  |

Vertretung West/Dortmund         | Phone: +49-231-2826-924     |

Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183
Geschaeftsfuehrung: Alexander Gach / Uwe Wilhelm
Unsere Datenschutzerklaerung mit wichtigen Hinweisen
zur Behandlung personenbezogener Daten finden Sie unter
www.peak-system.com/Datenschutz.483.0.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
  2022-01-31 14:25 [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number Stéphane Grosjean
@ 2022-01-31 14:31 ` Marc Kleine-Budde
  2022-02-11 10:57   ` Stéphane Grosjean
  0 siblings, 1 reply; 10+ messages in thread
From: Marc Kleine-Budde @ 2022-01-31 14:31 UTC (permalink / raw)
  To: Stéphane Grosjean; +Cc: linux-can Mailing List

[-- Attachment #1: Type: text/plain, Size: 667 bytes --]

On 31.01.2022 14:25:28, Stéphane Grosjean wrote:
> >> +     u32 devid;
> >>
> >> +             memcpy(data, (u8 *)&devid + eeprom->offset, eeprom->len);
> >
> > cast not needed.
> >
> 
> We need to cast the u32 * into a u8 * because eeprom->offset is a count of bytes, isn't it?

Doh! right.

What about endianness? I think it's better to use an array of bytes
everywhere.

Marc

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
@ 2022-02-11 10:57   ` Stéphane Grosjean
  2022-02-15  8:34     ` Stéphane Grosjean
  2022-02-15 15:10     ` Marc Kleine-Budde
  0 siblings, 2 replies; 10+ messages in thread
From: Stéphane Grosjean @ 2022-02-11 10:57 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can Mailing List

Hi Marc,

endianess is handled by lower level functions (see for ex pcan_usb_fd_get_user_devid()/pcan_usb_fd_set_user_devid() in PATCH 2/6).

This data is really a number and must be treated as such. The "ethtool -e" interface only displays a silly memory dump not very practical to read a number (especially a 32-bit one), requiring the use of hexdump such as:

ethtool -e can1 raw on | hexdump -v -e '1 "%u\n"'

to have a usable display. Unfortunately, these formats do not take endianess into account (AFAIK). Maybe you know another way?

Regards,


— Stéphane


            De: Marc Kleine-Budde
Envoyé: Lundi 31 janvier 2022 15:31
À: Stéphane Grosjean
Cc: linux-can Mailing List
Objet: Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number




On 31.01.2022 14:25:28, Stéphane Grosjean wrote:

> >> +     u32 devid;

> >>

> >> +             memcpy(data, (u8 *)&devid + eeprom->offset, eeprom->len);

> >

> > cast not needed.

> >

>

> We need to cast the u32 * into a u8 * because eeprom->offset is a count of bytes, isn't it?



Doh! right.



What about endianness? I think it's better to use an array of bytes

everywhere.



Marc



--

Pengutronix e.K.                 | Marc Kleine-Budde           |

Embedded Linux                   | https://www.pengutronix.de  |

Vertretung West/Dortmund         | Phone: +49-231-2826-924     |

Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183
Geschaeftsfuehrung: Alexander Gach / Uwe Wilhelm
Unsere Datenschutzerklaerung mit wichtigen Hinweisen
zur Behandlung personenbezogener Daten finden Sie unter
www.peak-system.com/Datenschutz.483.0.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
  2022-02-11 10:57   ` Stéphane Grosjean
@ 2022-02-15  8:34     ` Stéphane Grosjean
  2022-02-15 15:10     ` Marc Kleine-Budde
  1 sibling, 0 replies; 10+ messages in thread
From: Stéphane Grosjean @ 2022-02-15  8:34 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can Mailing List

Hi Marc,

Any news about this please?

Stephane

________________________________________
De : Stéphane Grosjean <s.grosjean@peak-system.com>
Envoyé : vendredi 11 février 2022 11:57
À : Marc Kleine-Budde
Cc : linux-can Mailing List
Objet : RE: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number

Hi Marc,

endianess is handled by lower level functions (see for ex pcan_usb_fd_get_user_devid()/pcan_usb_fd_set_user_devid() in PATCH 2/6).

This data is really a number and must be treated as such. The "ethtool -e" interface only displays a silly memory dump not very practical to read a number (especially a 32-bit one), requiring the use of hexdump such as:

ethtool -e can1 raw on | hexdump -v -e '1 "%u\n"'

to have a usable display. Unfortunately, these formats do not take endianess into account (AFAIK). Maybe you know another way?

Regards,


— Stéphane


            De: Marc Kleine-Budde
Envoyé: Lundi 31 janvier 2022 15:31
À: Stéphane Grosjean
Cc: linux-can Mailing List
Objet: Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number




On 31.01.2022 14:25:28, Stéphane Grosjean wrote:

> >> +     u32 devid;

> >>

> >> +             memcpy(data, (u8 *)&devid + eeprom->offset, eeprom->len);

> >

> > cast not needed.

> >

>

> We need to cast the u32 * into a u8 * because eeprom->offset is a count of bytes, isn't it?



Doh! right.



What about endianness? I think it's better to use an array of bytes

everywhere.



Marc



--

Pengutronix e.K.                 | Marc Kleine-Budde           |

Embedded Linux                   | https://www.pengutronix.de  |

Vertretung West/Dortmund         | Phone: +49-231-2826-924     |

Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183
Geschaeftsfuehrung: Alexander Gach / Uwe Wilhelm
Unsere Datenschutzerklaerung mit wichtigen Hinweisen
zur Behandlung personenbezogener Daten finden Sie unter
www.peak-system.com/Datenschutz.483.0.html

--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183
Geschaeftsfuehrung: Alexander Gach / Uwe Wilhelm
Unsere Datenschutzerklaerung mit wichtigen Hinweisen
zur Behandlung personenbezogener Daten finden Sie unter
www.peak-system.com/Datenschutz.483.0.html

--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183
Geschaeftsfuehrung: Alexander Gach / Uwe Wilhelm
Unsere Datenschutzerklaerung mit wichtigen Hinweisen
zur Behandlung personenbezogener Daten finden Sie unter
www.peak-system.com/Datenschutz.483.0.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
  2022-02-11 10:57   ` Stéphane Grosjean
  2022-02-15  8:34     ` Stéphane Grosjean
@ 2022-02-15 15:10     ` Marc Kleine-Budde
  2022-02-16  9:51       ` Marc Kleine-Budde
  1 sibling, 1 reply; 10+ messages in thread
From: Marc Kleine-Budde @ 2022-02-15 15:10 UTC (permalink / raw)
  To: Stéphane Grosjean; +Cc: linux-can Mailing List

[-- Attachment #1: Type: text/plain, Size: 2036 bytes --]

On 11.02.2022 10:57:34, Stéphane Grosjean wrote:
> endianess is handled by lower level functions (see for ex
> pcan_usb_fd_get_user_devid()/pcan_usb_fd_set_user_devid() in PATCH
> 2/6).
>
> This data is really a number and must be treated as such.

What's the use case for the data/number? What's the big picture?

> The "ethtool -e" interface only displays a silly memory dump not very
> practical to read a number (especially a 32-bit one), requiring the
> use of hexdump such as:
> 
> ethtool -e can1 raw on | hexdump -v -e '1 "%u\n"'

On a little endian system this gives:

| ➜ (pts/0) frogger@rpi4b4:~ (master) sudo ethtool -e can0
| Offset          Values
| ------          ------
| 0x0000:         11 22 33 44 

On a big endian we see:

| root@DistroKit:~ ethtool -e can0
| Offset		Values
| ------		------
| 0x0000:		44 33 22 11

However, if we pass it through hexdump it's always the same:

| root@DistroKit:~ ethtool -e can0 raw on|hexdump -v -e '1 "%u\n"'
| 1144201745
| ➜ (pts/0) frogger@rpi4b4:~ (master) sudo ethtool -e can0 raw on|hexdump -v -e '1 "%u\n"'
| 1144201745

Why does the hexdump give the same number? I think it interprets the
memory in native endianness.

> to have a usable display. Unfortunately, these formats do not take
> endianess into account (AFAIK). Maybe you know another way?

I think from the ethtool's point of view the "EEPROM" contents is a
stream of bytes.

With your patches the EEPROM contents is not the same on big and little
endian systems, rather the EEPROM contents is a 32 bit number in native
endianness. From my point of view I think it's more consistent to have
the EEPROM contain a u32 in little endian. But I'm really interested in
the use cases.

Marc

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
  2022-02-15 15:10     ` Marc Kleine-Budde
@ 2022-02-16  9:51       ` Marc Kleine-Budde
  0 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2022-02-16  9:51 UTC (permalink / raw)
  To: Stéphane Grosjean; +Cc: linux-can Mailing List

[-- Attachment #1: Type: text/plain, Size: 1078 bytes --]

On 15.02.2022 16:10:45, Marc Kleine-Budde wrote:
> On 11.02.2022 10:57:34, Stéphane Grosjean wrote:
> > endianess is handled by lower level functions (see for ex
> > pcan_usb_fd_get_user_devid()/pcan_usb_fd_set_user_devid() in PATCH
> > 2/6).
> >
> > This data is really a number and must be treated as such.
> 
> What's the use case for the data/number? What's the big picture?

| Jan 01 05:16:21 DistroKit kernel: peak_usb 1-1:1.0: PEAK-System PCAN-USB FD v1 fw v3.2.0 (1 channels)
| Jan 01 05:16:21 DistroKit kernel: peak_usb 1-1:1.0 can0: attached to PCAN-USB FD channel 0 (device 1144201745)
                                                                                                     ^^^^^^^^^^

But that is something different than the serial number, right?

regards,
Marc

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
  2022-02-21  9:29 Stéphane Grosjean
@ 2022-02-21 22:44 ` Vincent Mailhol
  0 siblings, 0 replies; 10+ messages in thread
From: Vincent Mailhol @ 2022-02-21 22:44 UTC (permalink / raw)
  To: Stéphane Grosjean; +Cc: Marc Kleine-Budde, linux-can Mailing List

On Tue. 22 Feb 2022 à 01:39, Stéphane Grosjean
<s.grosjean@peak-system.com> wrote:
>
> Hi Marc,
>
> >On 15.02.2022 16:10:45, Marc Kleine-Budde wrote:
> >> On 11.02.2022 10:57:34, Stéphane Grosjean wrote:
> >> > endianess is handled by lower level functions (see for ex
> >> > pcan_usb_fd_get_user_devid()/pcan_usb_fd_set_user_devid() in PATCH
> >> > 2/6).
> >> >
> >> > This data is really a number and must be treated as such.
> >>
> >> What's the use case for the data/number? What's the big picture?
>
> >| Jan 01 05:16:21 DistroKit kernel: peak_usb 1-1:1.0: PEAK-System PCAN-USB FD v1 fw v3.2.0 (1 channels)
> >| Jan 01 05:16:21 DistroKit kernel: peak_usb 1-1:1.0 can0: attached to PCAN-USB FD channel 0 (device 1144201745)
> >                                                                                                     ^^^^^^^^^^
>
> >But that is something different than the serial number, right?
>
> Yep! This is a number that can be used to uniquely identify the device, regardless of the USB port or the order in which it is connected. The purpose is to allow the user to name the network interface according to this number. This is for example what is done by the "historical" driver "pcan" which is freely downloadable from www.peak-system.com.

FYI, for the dual interfaces (PCAN-USB Pro), you might want to
populate net_device::dev_port as well.
c.f. https://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next.git/commit/?h=testing&id=e233640cd3034ae65924316a0d95ccacb86ae4bd


Yours sincerely,
Vincent Mailhol

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
@ 2022-02-21  9:29 Stéphane Grosjean
  2022-02-21 22:44 ` Vincent Mailhol
  0 siblings, 1 reply; 10+ messages in thread
From: Stéphane Grosjean @ 2022-02-21  9:29 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can Mailing List

Hi Marc,

>On 15.02.2022 16:10:45, Marc Kleine-Budde wrote:
>> On 11.02.2022 10:57:34, Stéphane Grosjean wrote:
>> > endianess is handled by lower level functions (see for ex
>> > pcan_usb_fd_get_user_devid()/pcan_usb_fd_set_user_devid() in PATCH
>> > 2/6).
>> >
>> > This data is really a number and must be treated as such.
>>
>> What's the use case for the data/number? What's the big picture?

>| Jan 01 05:16:21 DistroKit kernel: peak_usb 1-1:1.0: PEAK-System PCAN-USB FD v1 fw v3.2.0 (1 channels)
>| Jan 01 05:16:21 DistroKit kernel: peak_usb 1-1:1.0 can0: attached to PCAN-USB FD channel 0 (device 1144201745)
>                                                                                                     ^^^^^^^^^^

>But that is something different than the serial number, right?

Yep! This is a number that can be used to uniquely identify the device, regardless of the USB port or the order in which it is connected. The purpose is to allow the user to name the network interface according to this number. This is for example what is done by the "historical" driver "pcan" which is freely downloadable from www.peak-system.com.

>On a little endian system this gives:
>
>| ➜ (pts/0) frogger@rpi4b4:~ (master) sudo ethtool -e can0
>| Offset          Values
>| ------          ------
>| 0x0000:         11 22 33 44
>
>On a big endian we see:
>
>| root@DistroKit:~ ethtool -e can0
>| Offset                Values
>| ------                ------
>| 0x0000:               44 33 22 11

I admit that it is quite disturbing indeed to imagine that 0x11 is not necessarily in eeprom[0]... But:

>| root@DistroKit:~ ethtool -e can0 raw on|hexdump -v -e '1 "%u\n"'
>| 1144201745
>| ➜ (pts/0) frogger@rpi4b4:~ (master) sudo ethtool -e can0 raw on|hexdump -v -e '1 "%u\n"'
>| 1144201745

is the goal: can interface name will be the same in both systems.

In any case, thanks for the tests.

--- Stephane


            De: Marc Kleine-Budde
Envoyé: Mercredi 16 février 2022 10:51
À: Stéphane Grosjean
Cc: linux-can Mailing List
Objet: Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number




On 15.02.2022 16:10:45, Marc Kleine-Budde wrote:

> On 11.02.2022 10:57:34, Stéphane Grosjean wrote:

> > endianess is handled by lower level functions (see for ex

> > pcan_usb_fd_get_user_devid()/pcan_usb_fd_set_user_devid() in PATCH

> > 2/6).

> >

> > This data is really a number and must be treated as such.

>

> What's the use case for the data/number? What's the big picture?



| Jan 01 05:16:21 DistroKit kernel: peak_usb 1-1:1.0: PEAK-System PCAN-USB FD v1 fw v3.2.0 (1 channels)

| Jan 01 05:16:21 DistroKit kernel: peak_usb 1-1:1.0 can0: attached to PCAN-USB FD channel 0 (device 1144201745)

                                                                                                     ^^^^^^^^^^



But that is something different than the serial number, right?



regards,

Marc



--

Pengutronix e.K.                 | Marc Kleine-Budde           |

Embedded Linux                   | https://www.pengutronix.de  |

Vertretung West/Dortmund         | Phone: +49-231-2826-924     |

Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183
Geschaeftsfuehrung: Alexander Gach / Uwe Wilhelm
Unsere Datenschutzerklaerung mit wichtigen Hinweisen
zur Behandlung personenbezogener Daten finden Sie unter
www.peak-system.com/Datenschutz.483.0.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
  2022-01-28 15:01 ` [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number Stephane Grosjean
@ 2022-01-29 13:58   ` Marc Kleine-Budde
  0 siblings, 0 replies; 10+ messages in thread
From: Marc Kleine-Budde @ 2022-01-29 13:58 UTC (permalink / raw)
  To: Stephane Grosjean; +Cc: linux-can Mailing List

[-- Attachment #1: Type: text/plain, Size: 4124 bytes --]

On 28.01.2022 16:01:57, Stephane Grosjean wrote:
> This patch introduces 3 new functions implementing support for eeprom
> access of USB - CAN network interfaces managed by the driver, through the
> ethtool interface. All of them (except the PCAN-USB interface) interpret
> the 4 data bytes as a 32-bit value to be read/write in the non-volatile
> memory of the device. The PCAN-USB only manages a single byte value.
> 
> Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
> ---
>  drivers/net/can/usb/peak_usb/pcan_usb.c      |  9 +++
>  drivers/net/can/usb/peak_usb/pcan_usb_core.c | 69 ++++++++++++++++++++
>  drivers/net/can/usb/peak_usb/pcan_usb_core.h |  6 ++
>  drivers/net/can/usb/peak_usb/pcan_usb_fd.c   |  3 +
>  drivers/net/can/usb/peak_usb/pcan_usb_pro.c  |  3 +
>  5 files changed, 90 insertions(+)
> 
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
> index b29daaab2e6e..60c9329701a5 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
> @@ -981,8 +981,17 @@ static int pcan_usb_set_phys_id(struct net_device *netdev,
>  	return err;
>  }
>  
> +/* This device only handles 8-bit user device id. */
> +static int pcan_usb_get_eeprom_len(struct net_device *netdev)
> +{
> +	return sizeof(u8);
> +}
> +
>  static const struct ethtool_ops pcan_usb_ethtool_ops = {
>  	.set_phys_id = pcan_usb_set_phys_id,
> +	.get_eeprom_len	= pcan_usb_get_eeprom_len,
> +	.get_eeprom = peak_usb_get_eeprom,
> +	.set_eeprom = peak_usb_set_eeprom,
>  };
>  
>  /*
> diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> index aa8bcdcfa2fb..4e858d592e59 100644
> --- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> +++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
> @@ -782,6 +782,75 @@ static const struct net_device_ops peak_usb_netdev_ops = {
>  	.ndo_change_mtu = can_change_mtu,
>  };
>  
> +/* CAN-USB devices generally handle 32-bit user device id.
> + * In case one doesn't, then it have to overload this function.
> + */
> +int peak_usb_get_eeprom_len(struct net_device *netdev)
> +{
> +	return sizeof(u32);
> +}
> +
> +/* Every CAN-USB device exports the dev_get_user_devid() operation. It is used
> + * here to fill the data buffer with the user defined device number.
> + */
> +int peak_usb_get_eeprom(struct net_device *netdev,
> +			struct ethtool_eeprom *eeprom, u8 *data)
> +{
> +	struct peak_usb_device *dev = netdev_priv(netdev);
> +	u32 devid;
> +	int err;
> +
> +	if (!eeprom->len)
> +		return -EINVAL;

There already is a check for len == 0.

> +	err = dev->adapter->dev_get_user_devid(dev, &devid);
> +	if (!err) {

Please return on error.

> +		memcpy(data, (u8 *)&devid + eeprom->offset, eeprom->len);

cast not needed.
> +
> +		/* update cached value */
> +		dev->device_number = devid;
> +	}
> +
> +	return err;
> +}
> +
> +/* Every CAN-USB device exports the dev_get_user_devid()/dev_set_user_devid()
> + * operations. They are used here to set the new user defined device number.
> + */
> +int peak_usb_set_eeprom(struct net_device *netdev,
> +			struct ethtool_eeprom *eeprom, u8 *data)
> +{
> +	struct peak_usb_device *dev = netdev_priv(netdev);
> +	u32 devid;
> +	int err;
> +
> +	if (!eeprom->len)
> +		return -EINVAL;

There already is a check for len == 0.

> +
> +	/* first, read the current user defined device value number */
> +	err = dev->adapter->dev_get_user_devid(dev, &devid);
> +	if (err) {
> +		netdev_err(netdev, "Failed to init device id (err %d)\n", err);
> +		return err;
> +	}
> +
> +	/* do update the value with user given bytes */
> +	memcpy((u8 *)&devid + eeprom->offset, data, eeprom->len);

cast not needed.

regards,
Marc

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number
  2022-01-28 15:01 [PATCH 0/6] can: peak_usb: add ethtool interface to flashed value Stephane Grosjean
@ 2022-01-28 15:01 ` Stephane Grosjean
  2022-01-29 13:58   ` Marc Kleine-Budde
  0 siblings, 1 reply; 10+ messages in thread
From: Stephane Grosjean @ 2022-01-28 15:01 UTC (permalink / raw)
  To: linux-can Mailing List; +Cc: Stephane Grosjean

This patch introduces 3 new functions implementing support for eeprom
access of USB - CAN network interfaces managed by the driver, through the
ethtool interface. All of them (except the PCAN-USB interface) interpret
the 4 data bytes as a 32-bit value to be read/write in the non-volatile
memory of the device. The PCAN-USB only manages a single byte value.

Signed-off-by: Stephane Grosjean <s.grosjean@peak-system.com>
---
 drivers/net/can/usb/peak_usb/pcan_usb.c      |  9 +++
 drivers/net/can/usb/peak_usb/pcan_usb_core.c | 69 ++++++++++++++++++++
 drivers/net/can/usb/peak_usb/pcan_usb_core.h |  6 ++
 drivers/net/can/usb/peak_usb/pcan_usb_fd.c   |  3 +
 drivers/net/can/usb/peak_usb/pcan_usb_pro.c  |  3 +
 5 files changed, 90 insertions(+)

diff --git a/drivers/net/can/usb/peak_usb/pcan_usb.c b/drivers/net/can/usb/peak_usb/pcan_usb.c
index b29daaab2e6e..60c9329701a5 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb.c
@@ -981,8 +981,17 @@ static int pcan_usb_set_phys_id(struct net_device *netdev,
 	return err;
 }
 
+/* This device only handles 8-bit user device id. */
+static int pcan_usb_get_eeprom_len(struct net_device *netdev)
+{
+	return sizeof(u8);
+}
+
 static const struct ethtool_ops pcan_usb_ethtool_ops = {
 	.set_phys_id = pcan_usb_set_phys_id,
+	.get_eeprom_len	= pcan_usb_get_eeprom_len,
+	.get_eeprom = peak_usb_get_eeprom,
+	.set_eeprom = peak_usb_set_eeprom,
 };
 
 /*
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.c b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
index aa8bcdcfa2fb..4e858d592e59 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.c
@@ -782,6 +782,75 @@ static const struct net_device_ops peak_usb_netdev_ops = {
 	.ndo_change_mtu = can_change_mtu,
 };
 
+/* CAN-USB devices generally handle 32-bit user device id.
+ * In case one doesn't, then it have to overload this function.
+ */
+int peak_usb_get_eeprom_len(struct net_device *netdev)
+{
+	return sizeof(u32);
+}
+
+/* Every CAN-USB device exports the dev_get_user_devid() operation. It is used
+ * here to fill the data buffer with the user defined device number.
+ */
+int peak_usb_get_eeprom(struct net_device *netdev,
+			struct ethtool_eeprom *eeprom, u8 *data)
+{
+	struct peak_usb_device *dev = netdev_priv(netdev);
+	u32 devid;
+	int err;
+
+	if (!eeprom->len)
+		return -EINVAL;
+
+	err = dev->adapter->dev_get_user_devid(dev, &devid);
+	if (!err) {
+		memcpy(data, (u8 *)&devid + eeprom->offset, eeprom->len);
+
+		/* update cached value */
+		dev->device_number = devid;
+	}
+
+	return err;
+}
+
+/* Every CAN-USB device exports the dev_get_user_devid()/dev_set_user_devid()
+ * operations. They are used here to set the new user defined device number.
+ */
+int peak_usb_set_eeprom(struct net_device *netdev,
+			struct ethtool_eeprom *eeprom, u8 *data)
+{
+	struct peak_usb_device *dev = netdev_priv(netdev);
+	u32 devid;
+	int err;
+
+	if (!eeprom->len)
+		return -EINVAL;
+
+	/* first, read the current user defined device value number */
+	err = dev->adapter->dev_get_user_devid(dev, &devid);
+	if (err) {
+		netdev_err(netdev, "Failed to init device id (err %d)\n", err);
+		return err;
+	}
+
+	/* do update the value with user given bytes */
+	memcpy((u8 *)&devid + eeprom->offset, data, eeprom->len);
+
+	/* flash the new value now */
+	err = dev->adapter->dev_set_user_devid(dev, devid);
+	if (err) {
+		netdev_err(netdev, "Failed to write new device id (err %d)\n",
+			   err);
+		return err;
+	}
+
+	/* update cached value with the new one */
+	dev->device_number = devid;
+
+	return 0;
+}
+
 /*
  * create one device which is attached to CAN controller #ctrl_idx of the
  * usb adapter.
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_core.h b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
index 7fdc779986f0..4f4394733208 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_core.h
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_core.h
@@ -147,4 +147,10 @@ int peak_usb_netif_rx_64(struct sk_buff *skb, u32 ts_low, u32 ts_high);
 void peak_usb_async_complete(struct urb *urb);
 void peak_usb_restart_complete(struct peak_usb_device *dev);
 
+/* common 32-bit devid ethtool management */
+int peak_usb_get_eeprom_len(struct net_device *netdev);
+int peak_usb_get_eeprom(struct net_device *netdev,
+			struct ethtool_eeprom *eeprom, u8 *data);
+int peak_usb_set_eeprom(struct net_device *netdev,
+			struct ethtool_eeprom *eeprom, u8 *data);
 #endif
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 7440d5b145b5..cec09c7ffce2 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_fd.c
@@ -1072,6 +1072,9 @@ static int pcan_usb_fd_set_phys_id(struct net_device *netdev,
 
 static const struct ethtool_ops pcan_usb_fd_ethtool_ops = {
 	.set_phys_id = pcan_usb_fd_set_phys_id,
+	.get_eeprom_len	= peak_usb_get_eeprom_len,
+	.get_eeprom = peak_usb_get_eeprom,
+	.set_eeprom = peak_usb_set_eeprom,
 };
 
 /* describes the PCAN-USB FD adapter */
diff --git a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
index e98b08746e04..35177a3d1eba 100644
--- a/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
+++ b/drivers/net/can/usb/peak_usb/pcan_usb_pro.c
@@ -1036,6 +1036,9 @@ static int pcan_usb_pro_set_phys_id(struct net_device *netdev,
 
 static const struct ethtool_ops pcan_usb_pro_ethtool_ops = {
 	.set_phys_id = pcan_usb_pro_set_phys_id,
+	.get_eeprom_len	= peak_usb_get_eeprom_len,
+	.get_eeprom = peak_usb_get_eeprom,
+	.set_eeprom = peak_usb_set_eeprom,
 };
 
 /*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-02-21 22:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-31 14:25 [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number Stéphane Grosjean
2022-01-31 14:31 ` Marc Kleine-Budde
2022-02-11 10:57   ` Stéphane Grosjean
2022-02-15  8:34     ` Stéphane Grosjean
2022-02-15 15:10     ` Marc Kleine-Budde
2022-02-16  9:51       ` Marc Kleine-Budde
  -- strict thread matches above, loose matches on Subject: below --
2022-02-21  9:29 Stéphane Grosjean
2022-02-21 22:44 ` Vincent Mailhol
2022-01-28 15:01 [PATCH 0/6] can: peak_usb: add ethtool interface to flashed value Stephane Grosjean
2022-01-28 15:01 ` [PATCH 6/6] can: peak_usb: add ethtool interface to user defined flashed device number Stephane Grosjean
2022-01-29 13:58   ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.