netdev.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  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. * netping, 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. #endif