netcore.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Shared kernel receive pump for the network stack.
  2. *
  3. * Packet-level commands still take an exclusive raw lease through
  4. * netdev_acquire(). TCP clients no longer take that lease: every socket
  5. * syscall drains the active NIC through net_pump(), which dispatches each
  6. * frame to the TCP client table, the TCP listener, a pending DNS query, the
  7. * ARP cache and the netkexec watcher, and answers ARP/ICMP.
  8. *
  9. * net_pump() may only be called with the BKL held: it serializes every stack
  10. * user against the same NIC rings, the shared receive scratch and the
  11. * protocol state. It temporarily enables interrupts (the driver TX timeout
  12. * paths spin on get_ticks_ms()) and restores the caller's IF at the end.
  13. */
  14. #ifndef NETCORE_H
  15. #define NETCORE_H
  16. /* Drain at most `budget` frames and dispatch them. Returns the number of
  17. * frames consumed. No-op while a packet-level command owns the NIC. */
  18. int net_pump(unsigned int budget);
  19. /* Make several pump passes before a caller sleeps. A driver returns -1 both
  20. * for an empty ring and after an overflow reset, and one pass stops at the
  21. * first -1; repeated passes drain the ring and let the link recover. */
  22. static inline int net_pump_burst(unsigned int budget)
  23. {
  24. int n = 0, i;
  25. for (i = 0; i < 4; i++)
  26. n += net_pump(budget);
  27. return n;
  28. }
  29. /* Save/disable interrupts, then enable them. Paired with net_irq_exit().
  30. * Used around driver calls in the cooperative stack paths so a stuck TX
  31. * descriptor can still time out on the PIT. */
  32. unsigned int net_irq_enter(void);
  33. void net_irq_exit(unsigned int flags);
  34. /* Long-running stack operations (DNS/ARP waits, TCP connects) keep the
  35. * background netkexec watcher from polling the active NIC and stealing their
  36. * frames. The counter is protected by the BKL. */
  37. void net_stack_enter(void);
  38. void net_stack_leave(void);
  39. int net_stack_busy(void);
  40. /* Reaper: forget a dead process's stack-operation counts. */
  41. void net_stack_reap(unsigned int pid);
  42. #endif