LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-24-2009, 06:48 PM   #1
AustinMarton
Member
 
Registered: May 2007
Location: New Zealand
Distribution: Ubuntu
Posts: 88

Rep: Reputation: 16
Question 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.
 
Old 02-25-2009, 03:30 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,571

Rep: Reputation: 180Reputation: 180
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Linux Ethernet PHY Device Driver Hok Linux - Networking 0 10-08-2008 12:56 AM
C: convert char buffer received from socket to host endianess buffer kpachopoulos Programming 3 06-07-2007 05:06 PM
fseek on a socket descriptor to discard socket buffer? Thinking Programming 1 12-06-2005 09:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration