netdev.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. int (*set_speed)(unsigned int mbps); /* 0 = auto, 100 = force 100M; may be NULL */
  20. void (*set_mac)(const unsigned char mac[6]); /* runtime MAC override; may be NULL */
  21. /* Address applied when this driver becomes active. The direct ASIX
  22. * link uses its own subnet so it can coexist with the e1000e link to
  23. * the router. NULL leaves the current address alone. */
  24. const unsigned char *default_ip;
  25. const unsigned char *default_mask;
  26. /* Short RX summary for the boot log (a full register dump can
  27. * overflow the netlog ring before the WM starts); may be NULL. */
  28. void (*dump_brief)(void);
  29. /* Stop DMA before a kexec jump; may be NULL. */
  30. void (*stop)(void);
  31. };
  32. /* First registered driver that probes successfully (probe result is cached);
  33. * NULL when no NIC is present. */
  34. const struct netdev *netdev_active(void);
  35. /* Management NIC for netlog/netkexec. Prefers the ASIX dongle so the
  36. * direct debug link survives `netdev e1000e`; falls back to the active
  37. * driver. */
  38. const struct netdev *netdev_mgmt(void);
  39. /* Quiesce the active and management NIC DMA before a kexec jump. */
  40. void netdev_shutdown(void);
  41. /* Select a NIC by short driver name ("e1000e", "r8168", "ne2000", "asix").
  42. * Returns 0 on success; leaves the current driver active on failure. */
  43. int netdev_select(const char *name);
  44. void program_netdev_main(const char *arg);
  45. /* Busy gate for commands that poll the NIC for a while (netrecv, ping,
  46. * netloop, netkexec): the background kexec watcher must not steal
  47. * frames while one of them owns the receiver. */
  48. void netdev_acquire(void);
  49. void netdev_release(void);
  50. int netdev_in_use(void);
  51. /* Process that currently owns the NIC (0 = free), and a hard reset used by
  52. * the reaper so a killed process cannot leave the receiver owned. */
  53. unsigned int netdev_owner(void);
  54. void netdev_release_all(void);
  55. /* Fill the active NIC's MAC; -1 (and a zero MAC) when there is no NIC. */
  56. int netdev_get_mac(unsigned char mac[6]);
  57. /* One shared frame-receive scratch buffer (1518 bytes) for protocol code that
  58. * just needs somewhere for nd->rx() to land. Only valid while the caller
  59. * owns the NIC, and only until the next rx(). Shared so the DNS/TCP/ARP
  60. * paths don't each carry their own frame buffer in the kernel's BSS. */
  61. unsigned char *netdev_rx_scratch(void);
  62. #define NETDEV_FRAME_MAX 1518
  63. #endif