public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [query] skb alignment in tx path of driver
@ 2009-07-23 16:55 Kalpesh Rathod
  2009-07-23 17:16 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Kalpesh Rathod @ 2009-07-23 16:55 UTC (permalink / raw)
  To: linux-net, linux-kernel

Hi,

I am writing n/w device driver for sdio wifi card. I am testing it on
embedded platform.
DMA controller on the platform is able to xfer data to sdio only if
source data buf address is 4 byte aligned.

The firmware on the card understands 802.3 frames with snap headers.
So, I convert it to the required format in my driver.
4 byte additional header is also attached to this frame and sent over sdio.
This all conversion effectively adds 12 byes to the frame received in
hard_xmit method.

Problem is, frame received in hard_xmit method is 2 byte aligned.
(skb->data is 2 byte aligned). As a result,
after addition of 12 bytes header, skb->data remains 2 byte aligned
instead of 4 byte aligned. And DMA controller refuses
to transfer it.

So, how can I request IP stack so that frame received in hard_xmit is
on 4 byte aligned boundry?

I believe setting NET_IP_ALIGN will only matter in rx path. is this correct?

Thanks in advance.

Regards,
Kalpesh

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

* Re: [query] skb alignment in tx path of driver
  2009-07-23 16:55 [query] skb alignment in tx path of driver Kalpesh Rathod
@ 2009-07-23 17:16 ` Eric Dumazet
  2009-07-23 17:23   ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2009-07-23 17:16 UTC (permalink / raw)
  To: Kalpesh Rathod; +Cc: linux-net, linux-kernel

Kalpesh Rathod a écrit :
> Hi,
> 
> I am writing n/w device driver for sdio wifi card. I am testing it on
> embedded platform.
> DMA controller on the platform is able to xfer data to sdio only if
> source data buf address is 4 byte aligned.
> 
> The firmware on the card understands 802.3 frames with snap headers.
> So, I convert it to the required format in my driver.
> 4 byte additional header is also attached to this frame and sent over sdio.
> This all conversion effectively adds 12 byes to the frame received in
> hard_xmit method.
> 
> Problem is, frame received in hard_xmit method is 2 byte aligned.
> (skb->data is 2 byte aligned). As a result,
> after addition of 12 bytes header, skb->data remains 2 byte aligned
> instead of 4 byte aligned. And DMA controller refuses
> to transfer it.
> 
> So, how can I request IP stack so that frame received in hard_xmit is
> on 4 byte aligned boundry?

You cannot.

Search for skb_copy_and_csum_dev() use in drivers.

drivers/net/via-rhine.c is a good example of a driver dealing with same
alignment requirement.

        if ((rp->quirks & rqRhineI) &&
            (((unsigned long)skb->data & 3) || skb_shinfo(skb)->nr_frags != 0 || skb->ip_summed == CHECKSUM_PARTIAL)) {
                /* Must use alignment buffer. */
                if (skb->len > PKT_BUF_SZ) {
                        /* packet too long, drop it */
                        dev_kfree_skb(skb);
                        rp->tx_skbuff[entry] = NULL;
                        dev->stats.tx_dropped++;
                        return NETDEV_TX_OK;
                }

                /* Padding is not copied and so must be redone. */
                skb_copy_and_csum_dev(skb, rp->tx_buf[entry]);
                if (skb->len < ETH_ZLEN)
                        memset(rp->tx_buf[entry] + skb->len, 0,
                               ETH_ZLEN - skb->len);
                rp->tx_skbuff_dma[entry] = 0;
                rp->tx_ring[entry].addr = cpu_to_le32(rp->tx_bufs_dma +
                                                      (rp->tx_buf[entry] -
                                                       rp->tx_bufs));
        } else {
                rp->tx_skbuff_dma[entry] =
                        pci_map_single(rp->pdev, skb->data, skb->len,
                                       PCI_DMA_TODEVICE);
                rp->tx_ring[entry].addr = cpu_to_le32(rp->tx_skbuff_dma[entry]);
        }



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

* Re: [query] skb alignment in tx path of driver
  2009-07-23 17:16 ` Eric Dumazet
@ 2009-07-23 17:23   ` Stephen Hemminger
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2009-07-23 17:23 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: Kalpesh Rathod, linux-net, linux-kernel

On Thu, 23 Jul 2009 19:16:49 +0200
Eric Dumazet <eric.dumazet@gmail.com> wrote:

> Kalpesh Rathod a écrit :
> > Hi,
> > 
> > I am writing n/w device driver for sdio wifi card. I am testing it on
> > embedded platform.
> > DMA controller on the platform is able to xfer data to sdio only if
> > source data buf address is 4 byte aligned.
> > 
> > The firmware on the card understands 802.3 frames with snap headers.
> > So, I convert it to the required format in my driver.
> > 4 byte additional header is also attached to this frame and sent over sdio.
> > This all conversion effectively adds 12 byes to the frame received in
> > hard_xmit method.
> > 
> > Problem is, frame received in hard_xmit method is 2 byte aligned.
> > (skb->data is 2 byte aligned). As a result,
> > after addition of 12 bytes header, skb->data remains 2 byte aligned
> > instead of 4 byte aligned. And DMA controller refuses
> > to transfer it.
> > 
> > So, how can I request IP stack so that frame received in hard_xmit is
> > on 4 byte aligned boundry?
> 
> You cannot.
> 
> Search for skb_copy_and_csum_dev() use in drivers.
> 
> drivers/net/via-rhine.c is a good example of a driver dealing with same
> alignment requirement.
> 
>         if ((rp->quirks & rqRhineI) &&
>             (((unsigned long)skb->data & 3) || skb_shinfo(skb)->nr_frags != 0 || skb->ip_summed == CHECKSUM_PARTIAL)) {
There are wrappers for two of those tests
	      (!IS_ALIGNED(skb->data, 4) || skb_has_frags(skb) || skb->ip_summed == CHECKSUM_PARTIAL)

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

end of thread, other threads:[~2009-07-23 17:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-23 16:55 [query] skb alignment in tx path of driver Kalpesh Rathod
2009-07-23 17:16 ` Eric Dumazet
2009-07-23 17:23   ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox