Skip to contentSkip to conversation

questions about network device drivers

DISCUSSION Abraham vd Merwe 4 participants 7 messages Jul 30, 2002 – Jul 31, 2002

lore
Share & tools
lore
#0 lore raw

Hi!

hard_start_xmit() method
========================

when should this function return 0 and when should it return 1 and in which cases should it do netif_stop_queue() and/or free the dev_kfree_skb() ?

I'd really appreciate it if someone could clear this up. Almost all the source/docs I've looked at seems to contradict each other ):

also, since hard_start_xmit() is protected by xmit_lock, why are some drivers (e.g. cs89x0.c) guarding against concurrent calls to hard_start_xmit (see the spinlock in cs89x0.c:net_send_packet)?

is there any way to control alignment of sk_buff's that gets passed to this function? e.g. if I want the buffer to be aligned on 16-bit boundary and/or be padded to a 16-bit boundary - is there any way to tell the kernel to pass the driver buffers with those characterestics?

get_stats() method
==================

when errors occur that have details error fields in the net_device_stats structure, am I supposed to increment both the total error count and the detailed error count or both? also, what about dropped packets?

e.g.

1. i drop a frame because there's no memory left to allocate a sk_buff when I receive a packet. Do I increment rx_dropped, rx_errors, or both?

2. there's a crc error. do I increment rx_crc_errors and rx_errors or just rx_crc_errors?

also, I noticed that many drivers keep a private copy of the net_device_stats structure and just return a pointer to that structure in the get_stats method. what prevents the other driver methods from racing with the functions that gets passed this structure?

tx_timeout() method
=================

there is no way to return an error in the tx_timeout method. what should I do when an error occurs in that function (e.g. I'm unable to reset the controller)? panic? that seems a bit excessive...

general
=======

What is the difference between netif_wake_queue() and netif_start_queue()?

Signature · 17 lines
Regards
 Abraham

Humor in the Court:
Q.  And who is this person you are speaking of?
A.  My ex-widow said it.

__________________________________________________________
 Abraham vd Merwe - 2d3D, Inc.

 Device Driver Development, Outsourcing, Embedded Systems

  Cell: +27 82 565 4451         Snailmail:
   Tel: +27 21 761 7549            Block C, Aintree Park
   Fax: +27 21 761 7648            Doncaster Road
 Email: [email protected]         Kenilworth, 7700
  Http: http://www.2d3d.com        South Africa
#1 lore raw
Quoted 5 lines · Abraham vd Merwe

hard_start_xmit() method
========================

when should this function return 0 and when should it return 1 and in which cases should it do netif_stop_queue() and/or free the dev_kfree_skb() ?

0 - OK
1 - I am busy, give me it later.

If you return 1 be sure to netif_stop_queue. The netif_wake_queue will continue transmission

Quoted 4 lines

is there any way to control alignment of sk_buff's that gets passed to this function? e.g. if I want the buffer to be aligned on 16-bit boundary and/or be padded to a 16-bit boundary - is there any way to tell the kernel to pass the driver buffers with those characterestics?

There is not. You can expect just about every packet to be 16bit aligned

Quoted 3 lines

when errors occur that have details error fields in the net_device_stats structure, am I supposed to increment both the total error count and the detailed error count or both? also, what about dropped packets?

total and specific error.

dropped - not sure. Its not a precise science since cards vary themselves how their hardware accounts such things

Quoted 6 lines

tx_timeout() method
=================

there is no way to return an error in the tx_timeout method. what should I do when an error occurs in that function (e.g. I'm unable to reset the controller)? panic? that seems a bit excessive...

Try again ? If that fails I guess you initiate the self destruct sequence for just that driver.

Quoted 1 line
#2 lore raw

Hi Alan!

Quoted 11 lines
Quoted 5 lines

hard_start_xmit() method
========================

when should this function return 0 and when should it return 1 and in which cases should it do netif_stop_queue() and/or free the dev_kfree_skb() ?

0 - OK
1 - I am busy, give me it later.

If you return 1 be sure to netif_stop_queue. The netif_wake_queue will continue transmission

In both cases, should I free the sk_buff structure or only if I return 0? Also, if I understand you correctly, I should _only_ call netif_stop_queue() if the function fails to transmit the packet?

What about cases where the packet will always fail, e.g. the frame length is bigger than what the device supports. I take it in those cases I should return 0, but should I call netif_stop_queue() as well?

Signature · 15 lines
Regards
 Abraham

Here there be tygers.

__________________________________________________________
 Abraham vd Merwe - 2d3D, Inc.

 Device Driver Development, Outsourcing, Embedded Systems

  Cell: +27 82 565 4451         Snailmail:
   Tel: +27 21 761 7549            Block C, Aintree Park
   Fax: +27 21 761 7648            Doncaster Road
 Email: [email protected]         Kenilworth, 7700
  Http: http://www.2d3d.com        South Africa
#3 lore raw
Quoted 16 lines · Abraham vd Merwe

Hi Alan!

Quoted 11 lines
Quoted 5 lines

hard_start_xmit() method
========================

when should this function return 0 and when should it return 1 and in which cases should it do netif_stop_queue() and/or free the dev_kfree_skb() ?

0 - OK
1 - I am busy, give me it later.

If you return 1 be sure to netif_stop_queue. The netif_wake_queue will continue transmission

Quoted 7 lines

In both cases, should I free the sk_buff structure or only if I return 0? Also, if I understand you correctly, I should _only_ call netif_stop_queue() if the function fails to transmit the packet?

What about cases where the packet will always fail, e.g. the frame length is bigger than what the device supports. I take it in those cases I should return 0, but should I call netif_stop_queue() as well?

free it if you are returning zero. But of course, after the card has handled the packet.

If you set your MTU correctly, you shouldn't get frames larger than proper length.

netif_stop_queue and netif_start_queue and netif_wake_queue are your queue management tools. _only_ enable the queue when there is room for more packets.

Jeff

#4 lore raw
In reply to Alan Cox
Quoted 9 lines · Alan Cox
Quoted 5 lines · Abraham vd Merwe

hard_start_xmit() method
========================

when should this function return 0 and when should it return 1 and in which cases should it do netif_stop_queue() and/or free the dev_kfree_skb() ?

Quoted 5 lines

0 - OK
1 - I am busy, give me it later.

If you return 1 be sure to netif_stop_queue. The netif_wake_queue will continue transmission

I was recently corrected in this... for modern drivers it's really a bug (see drivers/net/tg3.c::tg3_start_xmit). The queue should be managed such that it is awake only when there is room for more packets.

For example, one code path (not the default one) in dev_queue_xmit will just drop the skb, not requeue it for later.

Quoted 10 lines
Quoted 6 lines

tx_timeout() method
=================

there is no way to return an error in the tx_timeout method. what should I do when an error occurs in that function (e.g. I'm unable to reset the controller)? panic? that seems a bit excessive...

Try again ? If that fails I guess you initiate the self destruct sequence for just that driver.

The typical method is to reset the NIC hardware, and either requeue waiting packets or drop all the packets you have waiting on the floor. tx_timeout is a generic catch-all that normally happens when the NIC is wedged.

Jeff

#5 lore raw
Quoted 1 line · Jeff Garzik

(lots of useful information)

Any chance of updating Documentation/networking/driver.txt to include this useful information (even if its just appending the email from Alan and yourself?) I was looking for this information recently as well.

Signature · 2 lines
Russell King ([email protected])                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html
#6 lore raw

Hi Russell!

Quoted 5 lines
Quoted 1 line

(lots of useful information)

Any chance of updating Documentation/networking/driver.txt to include this useful information (even if its just appending the email from Alan and yourself?) I was looking for this information recently as well.

I'm putting together a few notes on this and other network driver related things. Will post a patch soon...

Signature · 17 lines
Regards
 Abraham

Unprovided with original learning, unformed in the habits of thinking,
unskilled in the arts of composition, I resolved to write a book.
		-- Edward Gibbon

__________________________________________________________
 Abraham vd Merwe - 2d3D, Inc.

 Device Driver Development, Outsourcing, Embedded Systems

  Cell: +27 82 565 4451         Snailmail:
   Tel: +27 21 761 7549            Block C, Aintree Park
   Fax: +27 21 761 7648            Doncaster Road
 Email: [email protected]         Kenilworth, 7700
  Http: http://www.2d3d.com        South Africa