netdev.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Network device interface: one struct per NIC driver, shared by the network
  2. * stack (net.c) and the net* shell commands (netcmd.c).
  3. *
  4. * Drivers are registered in the table in netdev.c (first match wins); add new
  5. * ones there. Everything here is polled, matching the rest of the kernel. */
  6. #ifndef NETDEV_H
  7. #define NETDEV_H
  8. struct netdev {
  9. const char *name; /* short driver name, e.g. "ne2000" */
  10. const char *chip; /* detected chip, e.g. "RTL8029AS" */
  11. int (*init)(void); /* probe + bring up: 0 = ready, -1 = not present */
  12. void (*get_mac)(unsigned char mac[6]);
  13. int (*rx)(unsigned char *buf, unsigned int maxlen); /* len, or -1 */
  14. int (*tx)(const unsigned char *buf, unsigned int len); /* 0, or -1 */
  15. void (*print_info)(void); /* status lines (MAC, link, ...) */
  16. void (*dump_regs)(void); /* register dump; may be NULL */
  17. int (*set_loopback)(int on); /* PHY loopback for self-test; may be NULL */
  18. void (*reset)(void); /* full NIC re-init (recover from a stall); may be NULL */
  19. };
  20. /* First registered driver that probes successfully (probe result is cached);
  21. * NULL when no NIC is present. */
  22. const struct netdev *netdev_active(void);
  23. /* Busy gate for commands that poll the NIC for a while (netrecv, ping,
  24. * netloop, netkexec): the background kexec watcher must not steal
  25. * frames while one of them owns the receiver. */
  26. void netdev_acquire(void);
  27. void netdev_release(void);
  28. int netdev_in_use(void);
  29. /* Fill the active NIC's MAC; -1 (and a zero MAC) when there is no NIC. */
  30. int netdev_get_mac(unsigned char mac[6]);
  31. /* One shared frame-receive scratch buffer (1518 bytes) for protocol code that
  32. * just needs somewhere for nd->rx() to land. Only valid while the caller
  33. * owns the NIC, and only until the next rx(). Shared so the DNS/TCP/ARP
  34. * paths don't each carry their own frame buffer in the kernel's BSS. */
  35. unsigned char *netdev_rx_scratch(void);
  36. #define NETDEV_FRAME_MAX 1518
  37. #endif