public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Claudiu Manoil <claudiu.manoil@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 7/9] net: tsec: Use portable types and accessors for BDs
Date: Tue, 1 Oct 2013 14:38:20 +0300	[thread overview]
Message-ID: <524AB42C.7060404@freescale.com> (raw)
In-Reply-To: <1380583367.24959.551.camel@snotra.buserror.net>



On 10/1/2013 2:22 AM, Scott Wood wrote:
> On Mon, 2013-09-30 at 12:44 +0300, Claudiu Manoil wrote:
>> +static RTXBD rtx __aligned(8);
>> +#define RXBD(i) rtx.rxbd[i]
>> +#define TXBD(i) rtx.txbd[i]
>> +#define GET_BD_STAT(T, i) be16_to_cpu((__force __be16)T##BD(i).status)
>> +#define SET_BD_STAT(T, i, v) T##BD(i).status = (__force __u16)cpu_to_be16(v)
>> +#define GET_BD_BLEN(T, i) be16_to_cpu((__force __be16)T##BD(i).length)
>> +#define SET_BD_BLEN(T, i, v) T##BD(i).length = (__force __u16)cpu_to_be16(v)
>> +#define GET_BD_BPTR(T, i) be32_to_cpu((__force __be32)T##BD(i).bufptr)
>> +#define SET_BD_BPTR(T, i, v) T##BD(i).bufptr = (__force __u32)cpu_to_be32(v)
>
> Why the forcing?  Can't you declare the data with __be16/__be32?

The __force annotation is obviously needed to suppress the sparse
warnings due to BD data declaration type not being __bexx, but the
generic uintxx_t, as you noticed as well.
Now, why I didn't use __bexx instead?  The main reason would be
maintainability: the DMA descriptors may not be in big endian format
exclusively.  The eTSEC hw may actually have an option to interpret
the DMA descriptors in little endian format.  If we decide to use
that option for future platforms, then the __bexx type wouldn't be
correct anymore.
Besides, I noticed that most drivers prefer to use the generic type
uintxx_t for buffer descriptors, instead of the annotated __bexx/__lexx
types.

>
>>   #else
>>   #error "rtx must be 64-bit aligned"
>>   #endif
>> @@ -275,10 +283,11 @@ void redundant_init(struct eth_device *dev)
>>   	clrbits_be32(&regs->dmactrl, DMACTRL_GRS | DMACTRL_GTS);
>>
>>   	do {
>> +		uint16_t status;
>>   		tsec_send(dev, (void *)pkt, sizeof(pkt));
>>
>>   		/* Wait for buffer to be received */
>> -		for (t = 0; rtx.rxbd[rx_idx].status & RXBD_EMPTY; t++) {
>> +		for (t = 0; GET_BD_STAT(RX, rx_idx) & RXBD_EMPTY; t++) {
>
> What's wrong with:
>
> for (t = 0; in_be16(&rtx.rxbd[rx_idx].status) & RXBD_EMPTY; t++) {
>
> Or if you don't want to use I/O accessors on the DMA descriptors (Is
> synchronization ensured some other way?  We had problems with this in
> the Linux driver before...):
>

Synchronization here is is insured by declaring the RTXBD structure
type as "volatile" (see RTXBD declaration, a couple of lines above).
The existing code has been working this way for quite a while on the
mpc85xx platforms, so I thought it would be better not to change this
approach.  Using i/o accessors for the Buffer Descriptors would be a
significant change, and I don't see how to argue such a change: why
would the I/O accessors be better than the current approach - i.e.
declaring the DMA descriptors as volatile?  Is there something wrong
with about volatile usage in this case? (afaik, this is a case were
the volatile declaration is permitted)

Also, there doesn't seem to be other net drivers using I/O accessors
for the BD rings.

> for (t = 0; be16_to_cpup(&rtx.rxbd[rx_idx].status) & RXBD_EMPTY; t++) {
>

I opted for using macros instead due to code maintainability, and to
avoid overly long lines (80) and to better control these changes.
For instance, if etsec were to access it's BDs in little endian format
in the future, then it would be enough to update the implementation
of the macro accessors without touching the whole code.

> -Scott
>

Thanks for reviewing this.

Regards,
Claudiu

  reply	other threads:[~2013-10-01 11:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-30  9:44 [U-Boot] [PATCH 0/9] net: tsec: Driver portability fixes and cleanup Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 1/9] net: Fix mcast function pointer prototype Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 2/9] net: tsec: Fix and cleanup tsec_mcast_addr() Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 3/9] net: tsec: Fix priv pointer in tsec_mcast_addr() Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 4/9] net: tsec: Cleanup tsec regs init and fix __iomem warns Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 5/9] net: fsl_mdio: Fix warnings for __iomem pointers Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 6/9] net: tsec: Fix CamelCase issues around BD code Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 7/9] net: tsec: Use portable types and accessors for BDs Claudiu Manoil
2013-09-30 23:22   ` Scott Wood
2013-10-01 11:38     ` Claudiu Manoil [this message]
2013-10-01 18:50       ` Scott Wood
2013-10-02 14:16         ` Claudiu Manoil
2013-10-02 22:15           ` Scott Wood
2013-10-03 11:48             ` [U-Boot] [PATCH 7/9][v2] " Claudiu Manoil
2013-10-03 18:37               ` Scott Wood
2013-10-04  8:27                 ` Claudiu Manoil
2013-10-04 15:50                   ` Scott Wood
2013-10-04 16:13                     ` [U-Boot] [PATCH 7/9][v3] " Claudiu Manoil
2013-10-04 16:25                     ` [U-Boot] [PATCH 7/9][v2] " Claudiu Manoil
2013-10-05 14:31                       ` Timur Tabi
2013-10-05 14:49                         ` Timur Tabi
2013-10-07  9:53                           ` Claudiu Manoil
2013-10-07 10:16                         ` Claudiu Manoil
2013-10-07 12:05                           ` Timur Tabi
2013-10-07 16:42                           ` Scott Wood
2013-10-03 13:36             ` [U-Boot] [PATCH 7/9] " Claudiu Manoil
2013-10-04  3:12   ` Timur Tabi
2013-10-04  8:35     ` Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 8/9] net: tsec: Use portable regs type (uint->u32) Claudiu Manoil
2013-09-30  9:44 ` [U-Boot] [PATCH 9/9] net: tsec: Fix mac addr setup portability, cleanup Claudiu Manoil

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=524AB42C.7060404@freescale.com \
    --to=claudiu.manoil@freescale.com \
    --cc=u-boot@lists.denx.de \
    /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