driver.txt 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. Document about softnet driver issues
  2. Transmit path guidelines:
  3. 1) The hard_start_xmit method must never return '1' under any
  4. normal circumstances. It is considered a hard error unless
  5. there is no way your device can tell ahead of time when it's
  6. transmit function will become busy.
  7. Instead it must maintain the queue properly. For example,
  8. for a driver implementing scatter-gather this means:
  9. static int drv_hard_start_xmit(struct sk_buff *skb,
  10. struct net_device *dev)
  11. {
  12. struct drv *dp = dev->priv;
  13. lock_tx(dp);
  14. ...
  15. /* This is a hard error log it. */
  16. if (TX_BUFFS_AVAIL(dp) <= (skb_shinfo(skb)->nr_frags + 1)) {
  17. netif_stop_queue(dev);
  18. unlock_tx(dp);
  19. printk(KERN_ERR PFX "%s: BUG! Tx Ring full when queue awake!\n",
  20. dev->name);
  21. return 1;
  22. }
  23. ... queue packet to card ...
  24. ... update tx consumer index ...
  25. if (TX_BUFFS_AVAIL(dp) <= (MAX_SKB_FRAGS + 1))
  26. netif_stop_queue(dev);
  27. ...
  28. unlock_tx(dp);
  29. ...
  30. }
  31. And then at the end of your TX reclamation event handling:
  32. if (netif_queue_stopped(dp->dev) &&
  33. TX_BUFFS_AVAIL(dp) > (MAX_SKB_FRAGS + 1))
  34. netif_wake_queue(dp->dev);
  35. For a non-scatter-gather supporting card, the three tests simply become:
  36. /* This is a hard error log it. */
  37. if (TX_BUFFS_AVAIL(dp) <= 0)
  38. and:
  39. if (TX_BUFFS_AVAIL(dp) == 0)
  40. and:
  41. if (netif_queue_stopped(dp->dev) &&
  42. TX_BUFFS_AVAIL(dp) > 0)
  43. netif_wake_queue(dp->dev);
  44. 2) Do not forget to update netdev->trans_start to jiffies after
  45. each new tx packet is given to the hardware.
  46. 3) Do not forget that once you return 0 from your hard_start_xmit
  47. method, it is your driver's responsibility to free up the SKB
  48. and in some finite amount of time.
  49. For example, this means that it is not allowed for your TX
  50. mitigation scheme to let TX packets "hang out" in the TX
  51. ring unreclaimed forever if no new TX packets are sent.
  52. This error can deadlock sockets waiting for send buffer room
  53. to be freed up.
  54. If you return 1 from the hard_start_xmit method, you must not keep
  55. any reference to that SKB and you must not attempt to free it up.
  56. Probing guidelines:
  57. 1) Any hardware layer address you obtain for your device should
  58. be verified. For example, for ethernet check it with
  59. linux/etherdevice.h:is_valid_ether_addr()
  60. Close/stop guidelines:
  61. 1) After the dev->stop routine has been called, the hardware must
  62. not receive or transmit any data. All in flight packets must
  63. be aborted. If necessary, poll or wait for completion of
  64. any reset commands.
  65. 2) The dev->stop routine will be called by unregister_netdevice
  66. if device is still UP.