Re: [PATCH] net: ezchip: adapt driver to little endian architecture

2016-02-26 Thread David Miller
From: Arnd Bergmann 
Date: Fri, 26 Feb 2016 21:10:31 +0100

> On Friday 26 February 2016 22:05:09 Lada Trimasova wrote:
>> for (i = 0; i < len; i++, reg++) {
>> u32 buf = nps_enet_reg_get(priv, 
>> NPS_ENET_REG_RX_BUF);
>> +   buf = be32_to_cpu(buf);
>> put_unaligned(buf, reg);
>> }
> 
> I think most of the changes can make use of the put_unaligned_be32()
> etc helpers that might also be more efficient.

Agreed.


Re: [PATCH] net: ezchip: adapt driver to little endian architecture

2016-02-26 Thread Arnd Bergmann
On Friday 26 February 2016 22:05:09 Lada Trimasova wrote:
> 
> @@ -75,6 +86,7 @@ struct nps_enet_rx_ctl {
>  * nr:  Length in bytes of Rx frame loaded by MAC to Rx buffer
>  */
> struct {
> +#ifdef CONFIG_CPU_BIG_ENDIAN
> u32
> __reserved_1:16,
> cr:1,
> @@ -82,6 +94,15 @@ struct nps_enet_rx_ctl {
> crc:1,
> __reserved_2:2,
> nr:11;
> +#else
> +   u32
> +   nr:11,
> +   __reserved_2:2,
> +   crc:1,
> +   er:1,
> +   cr:1,
> +   __reserved_1:16;
> +#endif
> };

A nicer way to do this would be to remove all the bitfields
and use named constants for accessing the fields insode of
a u32 or u64 variable.

The order of the bits in a bit field is implementation specific
and your method might not work on all architectures. Even if the
driver is only meant to run on a single CPU architecture, it's
always better to write portable code.

Arnd


Re: [PATCH] net: ezchip: adapt driver to little endian architecture

2016-02-26 Thread Arnd Bergmann
On Friday 26 February 2016 22:05:09 Lada Trimasova wrote:
> for (i = 0; i < len; i++, reg++) {
> u32 buf = nps_enet_reg_get(priv, NPS_ENET_REG_RX_BUF);
> +   buf = be32_to_cpu(buf);
> put_unaligned(buf, reg);
> }

I think most of the changes can make use of the put_unaligned_be32()
etc helpers that might also be more efficient.

Arnd