LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Ethernet device driver hardware rx- am I doing the right thing with my socket buffer? (https://www.linuxquestions.org/questions/linux-kernel-70/ethernet-device-driver-hardware-rx-am-i-doing-the-right-thing-with-my-socket-buffer-707261/)

AustinMarton 02-24-2009 07:48 PM

Ethernet device driver hardware rx- am I doing the right thing with my socket buffer?
 
Hi there,

I am working on an Ethernet device driver for uClinux, currently I am not sure about the hardware receive function, this is what I do:

define a socket buffer:
Code:

struct sk_buff *skb;
perform some checks on the device specific header (from which I get the rxLen)

if all okay, allocate memory for the skb:
Code:

if (goodPacket && ((skb = dev_alloc_skb(rxLen+x)) != NULL)) { ...
align IP header to 16 bit boundary - not too sure about this but other drivers seem to do it:
Code:

skb_reserve(skb, 2);
get a pointer to the start of the skb data section:
Code:

rdptr = (uint8_t *) skb_put(skb, rxLen+x);
I then loop, reading one word from hardware (into rxWord), and then writing it to the skb:
Code:

        memcpy(rdptr, &rxWord, 16); /* copy 2 bytes to socket buffer */
        rdptr += 2;        /* increment pointer by 2 bytes */

Once I have reached the end of the frame, fill skb structure:
Code:

skb->dev = dev;
skb->protocol = eth_type_trans(skb, dev);
skb->ip_summed = CHECKSUM_UNNECESSARY; /* don't check it */
priv->stats.rx_packets++;
priv->stats.rx_bytes += rxLen;

And pass it to the upper layer
Code:

ret = netif_rx(skb);


Does this look correct?

I do not know what to put for the offset to add to rxLen ("x"). If I put zero I get
Code:

skb_over_panic: text:fb00005e len:240 put:240 head:00bd6000 data:00bd6012 tail:0xbd6102 end:0xbd6100 dev:eth0
BUG: failure at /home/caleb/nios2-linux/linux-2.6/net/core/skbuff.c:128/skb_over_panic()!
Kernel panic - not syncing: BUG!

, but when I add an offset, when I print out the skb data at the end to check, it has the sequence "...bb00 efbe adde 0000..." at the end of the buffer after the packet data I have written. Is there a way I can clear the socket buffer memory? should I memcpy zeros in initially? Do I need to pad to some boundary?

netif_rx is returning 0 which indicates success, but I don't see the packet count increase in ifconfig.

Mara 02-25-2009 04:30 PM

x=2. That's the same 2 you add to skb_reserve. Explanation: IP packet in the stack must be aligned. It doesn't match the 'raw' Ethernet packet you have. It means that you need to reserve 2 octets more and copy the data in such a way that the IP packet is formed as it should be.


All times are GMT -5. The time now is 11:45 PM.